On 28/02/17 15:05, George News wrote:


On 28/02/2017 10:51, Andy Seaborne wrote:
What people on the list receive is:

https://lists.apache.org/api/source.lua/8d17e5299cbbe585e7d45ff8ce156021162a9e16fe77818d8f7cff6c@%3Cusers.jena.apache.org%3E


Ok. So the list is text based ;) Fine for next time.

Looks like HTML to text conversion.

On 27/02/17 23:58, George News wrote:
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.

Probably you close the transaction before the resultset is all
consumed.

Some work is done on execSelect so internally, the use of the
dataset can finish early.

UNION has two branches calculated separately.

I was supposing that. At the end I have included the dataset in my own
ResultSetClosable class, so this way I can call dataset.end() on
ResultSet close. It seems that it works this way, it is not the more
elegant one, but it works.

In this sense, one option for including in Jena could be to enable the
option to create a QueryExecution with transaction included, in order to
avoid some issues like that.

That's what ResultSetFormatter.toList or ResultSetFactory.copyResults do.

        Andy


It depends on the real query.

Andy


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