/** * Returns a single element from the query result. The QueryResult is * automatically closed by this method. * * @since 2.7.0 * @return a single query result element. * @throws QueryEvaluationException */ public static Statement singleResult(GraphQueryResult result) throws QueryEvaluationException { Statement singleResult = null; if (result.hasNext()) { singleResult = result.next(); } result.close(); return singleResult; }
rdfHandler.startRDF(); for (Map.Entry<String, String> entry : gqr.getNamespaces().entrySet()) { String prefix = entry.getKey(); String namespace = entry.getValue(); while (gqr.hasNext()) { Statement st = gqr.next(); rdfHandler.handleStatement(st); gqr.close();
@Override public void remove() throws QueryEvaluationException { queryResult.remove(); }
/** * Utility method to turn a {@link GraphQueryResult} into a {@link Graph}. * * @param result * The {@link GraphQueryResult}. * * @return The {@link Graph}. * * @throws Exception */ static public Graph asGraph(final GraphQueryResult result) throws Exception { final Graph g = new LinkedHashModel(); while (result.hasNext()) { g.add(result.next()); } return g; }
@Override public void close() throws QueryEvaluationException { queryResult.close(); } }
@Override public boolean hasNext() throws QueryEvaluationException { return queryResult.hasNext(); }
@Override public Statement next() throws QueryEvaluationException { return result.next(); } }
@Override public Map<String, String> getNamespaces() throws QueryEvaluationException { return unfiltered.getNamespaces(); } }
@Override public void close() { try { graphResult.close(); } catch (QueryEvaluationException e1) { throw new RepositoryException(e1); } }
@Override public boolean hasNext() { try { return graphResult.hasNext(); } catch (QueryEvaluationException e) { throw new RepositoryException(e); } }
@Override public Statement next() throws RepositoryException { try { return src.next(); } catch (Exception ex) { throw new RepositoryException(ex); } }
@Override public Map<String, String> getNamespaces() throws QueryEvaluationException { return result.getNamespaces(); }
/** * Counts the #of results in a SPARQL result set. * * @param result * The connection from which to read the results. * * @return The #of results. * * @throws Exception * If anything goes wrong. */ static protected long countResults(final GraphQueryResult result) throws Exception { try { long count = 0; while (result.hasNext()) { result.next(); count++; } return count; } finally { result.close(); } }
@Override public void close() throws RepositoryException { try { src.close(); } catch (Exception ex) { throw new RepositoryException(ex); } }
@Override public boolean hasNext() throws QueryEvaluationException { final boolean hasNext = result.hasNext(); if (!hasNext) { close(); } return hasNext; }
@Override public STMT next() { try { return convert(graphResult.next(), true); } catch (QueryEvaluationException e) { throw new RepositoryException(e); } }
@Override public void remove() throws QueryEvaluationException { result.remove(); }
public GraphQueryResult evaluate() throws QueryEvaluationException { GraphQueryResult result = delegate.evaluate(); CloseableIteration<Statement, QueryEvaluationException> iter; iter = new AStatementIterator<QueryEvaluationException>(result, node, "subject", "object"); return new GraphQueryResultImpl(result.getNamespaces(), iter); }