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; } |