@Override public Statement next() throws QueryEvaluationException { return result.next(); } }
@Override public Statement next() throws RepositoryException { try { return src.next(); } catch (Exception ex) { throw new RepositoryException(ex); } }
@Override public STMT next() { try { return convert(graphResult.next(), true); } catch (QueryEvaluationException e) { throw new RepositoryException(e); } }
/** * 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; }
/** * 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(); } }
/** * 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; }
private static boolean namespaceExists(final String namespace, final RemoteRepositoryManager repo) throws Exception{ final GraphQueryResult res = repo.getRepositoryDescriptions(); try{ while(res.hasNext()){ final Statement stmt = res.next(); if (stmt.getPredicate().toString().equals(SD.KB_NAMESPACE.stringValue())) { if(namespace.equals(stmt.getObject().stringValue())){ log.info(String.format("Namespace %s already exists", namespace)); return true; } } } } finally { res.close(); } return false; }
private static boolean namespaceExists(final String namespace, final RemoteRepositoryManager repo) throws Exception{ final GraphQueryResult res = repo.getRepositoryDescriptions(); try{ while(res.hasNext()){ final Statement stmt = res.next(); if (stmt.getPredicate().toString().equals(SD.KB_NAMESPACE.stringValue())) { if(namespace.equals(stmt.getObject().stringValue())){ log.info(String.format("Namespace %s already exists", namespace)); return true; } } } } finally { res.close(); } return false; }
@Override public List<Value> next() throws QueryEvaluationException { Statement stmt = queryResult.next(); Resource ctx = stmt.getContext(); if(ctx != null) { return Arrays.asList(stmt.getSubject(), stmt.getPredicate(), stmt.getObject(), ctx); } else { return Arrays.asList(stmt.getSubject(), stmt.getPredicate(), stmt.getObject()); } }
/** * @deprecated by {@link #asGraph(IPreparedGraphQuery)} which can ensure that * the {@link GraphQueryResult} is closed. */ static protected Graph asGraph(final GraphQueryResult result) throws Exception { try { final Graph g = new LinkedHashModel(); while (result.hasNext()) { g.add(result.next()); } return g; } finally { result.close(); } }
@Override public void evaluate(RDFHandler handler) throws QueryEvaluationException, RDFHandlerException { GraphQueryResult result = evaluate(); handler.startRDF(); while (result.hasNext()) handler.handleStatement(result.next()); handler.endRDF(); } }
public Statement asStatement() throws OpenRDFException { GraphQueryResult result = asGraphQueryResult(); try { if (result.hasNext()) { Statement stmt = result.next(); if (result.hasNext()) throw new MultipleResultException(); return stmt; } return null; } finally { result.close(); } }
public Statement asStatement() throws OpenRDFException { GraphQueryResult result = asGraphQueryResult(); try { if (result.hasNext()) { Statement stmt = result.next(); if (result.hasNext()) throw new MultipleResultException(); return stmt; } return null; } finally { result.close(); } }
private static boolean namespaceExists(final RemoteRepositoryManager repo, final String namespace) throws Exception { final GraphQueryResult res = repo.getRepositoryDescriptions(); try { while (res.hasNext()) { final Statement stmt = res.next(); if (stmt.getPredicate() .toString() .equals(SD.KB_NAMESPACE.stringValue())) { if (namespace.equals(stmt.getObject().stringValue())) { return true; } } } } finally { res.close(); } return false; }
@Override public void evaluate(RDFHandler handler) throws QueryEvaluationException, RDFHandlerException { GraphQueryResult gqr = evaluate(); try { handler.startRDF(); while (gqr.hasNext()) { handler.handleStatement(gqr.next()); } handler.endRDF();; } finally { gqr.close(); } } }
/** * Preferred version executes the {@link IPreparedGraphQuery} and ensures * that the {@link GraphQueryResult} is closed. * * @param preparedQuery * The prepared query. * * @return The resulting graph. * * @throws Exception */ static protected Graph asGraph(final IPreparedGraphQuery preparedQuery) throws Exception { final GraphQueryResult result = preparedQuery.evaluate(); try { final Graph g = new LinkedHashModel(); while (result.hasNext()) { g.add(result.next()); } return g; } finally { result.close(); } }
/** * 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(); } }
/** * @deprecated by {@link #asGraph(IPreparedGraphQuery)} which can ensure that * the {@link GraphQueryResult} is closed. */ static protected Graph asGraph(final GraphQueryResult result) throws Exception { try { final Graph g = new LinkedHashModel(); while (result.hasNext()) { g.add(result.next()); } return g; } finally { result.close(); } }
@Override public void exportStatements(final Resource s, final URI p, final Value o, final boolean includeInferred, final RDFHandler handler, final Resource... c) throws RepositoryException, RDFHandlerException { try { final RemoteRepository remote = repo.getRemoteRepository(); final GraphQueryResult src = remote.getStatements(s, p, o, includeInferred, c); try { handler.startRDF(); while (src.hasNext()) { handler.handleStatement(src.next()); } handler.endRDF(); } finally { src.close(); } } catch (Exception ex) { throw new RepositoryException(ex); } }
/** * Preferred version executes the {@link IPreparedGraphQuery} and ensures * that the {@link GraphQueryResult} is closed. * * @param preparedQuery * The prepared query. * * @return The resulting graph. * * @throws Exception */ static protected Graph asGraph(final IPreparedGraphQuery preparedQuery) throws Exception { final GraphQueryResult result = preparedQuery.evaluate(); try { final Graph g = new LinkedHashModel(); while (result.hasNext()) { g.add(result.next()); } return g; } finally { result.close(); } }