But the funny thing is that in both cases (with and without UNION) the code is 
the same. I know I close the transaction, but I don’t understand why in one 
case it works and in the other no.

I would like to ask another thing:  In a @requestscope is the reading 
transaction automatically close when finished the REST processing or is it 
mandatory to call dataset.end()?

I don't knw why example code is unreadable. I have perfectly seen the code.

Thanks a lot
Jorge

Sent from jlanza_lumia820

From: Andy Seaborne
Sent: martes, 28 de febrero de 2017 0:12
To: [email protected]
Subject: Re: SPARQL with UNION returning TDBTransactionException

Unreadable.

-------------------------

Probably you are passing the result stream out of the transaction.

Reading a ResultSet requires reading the dataset and must be inside a 
transaction when the calls to hasNext/next are happening.

     Andy

On 27/02/17 18:18, George News wrote:
> |public SparqlResult executeSparql(String sparql) throws
> SparqlExecutionException { String queryString = sparql; Query query =
> QueryFactory.create(queryString); dataset.begin(ReadWrite.READ); try {
> QueryExecution qExec = QueryExecutionFactory.create(query, getModel());
> // System.out.println(qExec.getQuery().serialize()); //
> System.out.println(qExec.getQuery().toString()); SparqlResult result; if
> (query.isSelectType()) { result = new SparqlResult(qExec.execSelect(),
> qExec); } else if (query.isDescribeType()) { result = new
> SparqlResult(qExec.execDescribe(), qExec); } else if (query.isAskType())
> { result = new SparqlResult(qExec.execAsk(), qExec); } else if
> (query.isConstructType()) { result = new
> SparqlResult(qExec.execConstruct(), qExec); } else { throw new
> SparqlExecutionException("Unsupported query type: " +
> query.getQueryType()); } return result; } finally { dataset.end(); }
> private Map<String, Integer> getSummaryStatistics() { String queryString
> = "THE_ONE"; Map<String, Integer> statistics = new HashMap<>();
> GlobalTripleStore gts = new GlobalTripleStore(); try (SparqlResult
> result = gts.executeSparql(queryString)) { ResultSet resultSet =
> (ResultSet) result.getResult(); while (resultSet.hasNext()) {
> QuerySolution sol = resultSet.next(); int devices =
> sol.get("count_devices").asLiteral().getInt(); int observations
> =sol.get("count_o").asLiteral().getInt(); statistics.put("devices",
> resources); statistics.put("o", observations); } } catch
> (SparqlExecutionException e) { // TODO Auto-generated catch block
> e.printStackTrace(); } return statistics; } |

Reply via email to