/** * Returns a single element from the query result. The QueryResult is automatically closed by this method. * * @return a single query result element. * @throws QueryEvaluationException */ public static BindingSet singleResult(TupleQueryResult result) throws QueryEvaluationException { BindingSet singleResult = null; try { if (result.hasNext()) { singleResult = result.next(); } } finally { result.close(); } return singleResult; }
@Override public void evaluate(TupleQueryResultHandler handler) throws QueryEvaluationException, TupleQueryResultHandlerException { TupleQueryResult result = evaluate(); handler.startQueryResult(result.getBindingNames()); while (result.hasNext()) { handler.handleSolution(result.next()); } handler.endQueryResult(); }
@Override public void remove() throws QueryEvaluationException { result.remove(); } }
/** * Reports a tuple query result to a {@link TupleQueryResultHandler}. <br> * The {@link TupleQueryResult#close()} method will always be called before this method returns. <br> * If there is an exception generated by the TupleQueryResult, {@link QueryResultHandler#endQueryResult()} * will not be called. * * @param tqr * The query result to report. * @param handler * The handler to report the query result to. * @throws TupleQueryResultHandlerException * If such an exception is thrown by the used query result writer. */ public static void report(TupleQueryResult tqr, QueryResultHandler handler) throws TupleQueryResultHandlerException, QueryEvaluationException { try { handler.startQueryResult(tqr.getBindingNames()); while (tqr.hasNext()) { BindingSet bindingSet = tqr.next(); handler.handleSolution(bindingSet); } } finally { tqr.close(); } handler.endQueryResult(); }
@Override public BindingSet next() throws QueryEvaluationException { return result.next(); }
public void testBaseURIInParam() throws Exception { testCon.add(vf.createIRI("http://example.org/s1"), vf.createIRI("urn:test:p1"), vf.createIRI("urn:test:o1")); TupleQueryResult rs = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * { <s1> ?p ?o }", "http://example.org").evaluate(); try { assertTrue(rs.hasNext()); } finally { rs.close(); } }
@Override public boolean hasNext() { boolean res; try { res = result.hasNext(); } catch (QueryEvaluationException e) { throw new RuntimeException(e); } return res; }
public void close() { aTupleQueryResult.close(); } };
public MutableTupleQueryResult(TupleQueryResult tqr) throws QueryEvaluationException { this(tqr.getBindingNames(), tqr); }
/** * Reports a tuple query result to a {@link TupleQueryResultHandler}. <br> * The {@link TupleQueryResult#close()} method will always be called before this method returns. <br> * If there is an exception generated by the TupleQueryResult, {@link QueryResultHandler#endQueryResult()} * will not be called. * * @param tqr * The query result to report. * @param handler * The handler to report the query result to. * @throws TupleQueryResultHandlerException * If such an exception is thrown by the used query result writer. */ public static void report(TupleQueryResult tqr, QueryResultHandler handler) throws TupleQueryResultHandlerException, QueryEvaluationException { try { handler.startQueryResult(tqr.getBindingNames()); while (tqr.hasNext()) { BindingSet bindingSet = tqr.next(); handler.handleSolution(bindingSet); } } finally { tqr.close(); } handler.endQueryResult(); }
@Override public AGQuerySolution next() { BindingSet bs; try { bs = result.next(); } catch (QueryEvaluationException e) { throw new RuntimeException(e); } return new AGQuerySolution(bs, model); }
public void testBaseURIInParamWithTrailingSlash() throws Exception { testCon.add(vf.createIRI("http://example.org/s1"), vf.createIRI("urn:test:p1"), vf.createIRI("urn:test:o1")); TupleQueryResult rs = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * { <s1> ?p ?o }", "http://example.org/").evaluate(); try { assertTrue(rs.hasNext()); } finally { rs.close(); } }
@Override public boolean hasNext() { try { return result.hasNext(); } catch (QueryEvaluationException e) { throw new RuntimeException(e); } }
@Override public void close() { try { result.close(); } catch (QueryEvaluationException e) { throw new RuntimeException(e); } }
TupleQueryResultIteration(TupleQueryResult queryResult) throws QueryEvaluationException { this.queryResult = queryResult; this.bindingNames = queryResult.getBindingNames(); }
/** * Returns a single element from the query result. The QueryResult is automatically closed by this method. * * @return a single query result element. * @throws QueryEvaluationException */ public static BindingSet singleResult(TupleQueryResult result) throws QueryEvaluationException { BindingSet singleResult = null; try { if (result.hasNext()) { singleResult = result.next(); } } finally { result.close(); } return singleResult; }
private List<String> getRdfTypes(String instanceId) throws QueryEvaluationException, RepositoryException, MalformedQueryException { List<String> rdfTypes = new ArrayList<>(); TupleQueryResult result =getQueryResult(QueryBuilder.getRdfType(instanceId)); while (result.hasNext()) { BindingSet bindingSet = result.next(); Value typeOf = bindingSet.getValue("typeOf"); rdfTypes.add(typeOf.stringValue()); } return rdfTypes; }
@Override public void evaluate(TupleQueryResultHandler handler) throws QueryEvaluationException, TupleQueryResultHandlerException { TupleQueryResult result = evaluate(); handler.startQueryResult(result.getBindingNames()); while (result.hasNext()) { handler.handleSolution(result.next()); } handler.endQueryResult(); }