@Override public void close() throws QueryEvaluationException { queryResult.close(); } }
@Override public void close() throws RepositoryException { try { src.close(); } catch (Exception ex) { throw new RepositoryException(ex); } }
@Override public void close() { try { graphResult.close(); } catch (QueryEvaluationException e1) { throw new RepositoryException(e1); } }
@Override public void run() { try { log.warn("Get namespace list..."); m_mgr.getRepositoryDescriptions().close(); log.warn("Get namespace list done"); } catch (final Exception e) { log.error("Failed to get namespace list:", e); testSucceeding.set(false); } if (testSucceeding.get()) executor.schedule(this, 1, TimeUnit.SECONDS); } });
/** * Utility method for closing all GraphQueryResults and TupleQueryResults * occurring as values in the specified Map. */ public static void closeResults(Map<?, ?> results) { for (Object key : results.keySet()) { Object value = results.get(key); try { if (value instanceof GraphQueryResult) { ((GraphQueryResult)value).close(); } else if (value instanceof TupleQueryResult) { ((TupleQueryResult)value).close(); } } catch (QueryEvaluationException e) { Logger logger = LoggerFactory.getLogger(BlockingQueryEvaluator.class); logger.warn("Unable to close query result", e); } } } }
@Override public void close() throws QueryEvaluationException { try { result.close(); } finally { try { connection.close(); } catch (RepositoryException e) { throw new QueryEvaluationException("Exception closing connection.", 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(); } }
@Override public void run() { try { log.warn("Get namespace list..."); m_mgr.getRepositoryDescriptions().close(); log.warn("Get namespace list done"); } catch (final Exception e) { log.error("Failed to get namespace list:", e); testSucceeding.set(false); } if (testSucceeding.get()) executor.schedule(this, 1, TimeUnit.SECONDS); } });
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; }
/** * @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(); } }
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(); } }
/** * @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(); } }