/** * 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 Statement singleResult(GraphQueryResult result) throws QueryEvaluationException { Statement singleResult = null; try { if (result.hasNext()) { singleResult = result.next(); } } finally { result.close(); } return singleResult; }
@Override public Map<String, String> getNamespaces() throws QueryEvaluationException { return unfiltered.getNamespaces(); } }
@Override public void remove() throws QueryEvaluationException { result.remove(); }
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 writeGraphQueryResult(GraphQueryResult queryResult) throws ExportException { try { writer.startRDF(); for (Map.Entry<String, String> me : queryResult.getNamespaces().entrySet()) { writer.handleNamespace(me.getKey(), me.getValue()); } while (queryResult.hasNext()) { writer.handleStatement(queryResult.next()); tick(); } writer.endRDF(); } catch (QueryEvaluationException | RDFHandlerException e) { throw new ExportException(e); } }
@Override public void close() { try { result.close(); } catch (QueryEvaluationException e) { throw new RuntimeException(e); } }
@Override public Statement next() throws QueryEvaluationException { return result.next(); } }
@Override public boolean hasNext() { try { return result.hasNext(); } catch (QueryEvaluationException e) { throw new RuntimeException(e); } }
@Override public Iterator<Quad> execConstructQuads() { try (GraphQueryResult result = getConstructResult()) { List<Quad> quadArrayList = new ArrayList<>(); while (result.hasNext()) { quadArrayList.add(AGNodeFactory.asQuad(result.next())); } //Getting Iterator from List return quadArrayList.iterator(); } catch (QueryEvaluationException e) { throw new QueryException(e); } }
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 Model execConstruct(Model m) { GraphQueryResult result = getConstructResult(); if (m == null) { m = ModelFactory.createDefaultModel(); } try { m.setNsPrefixes(result.getNamespaces()); while (result.hasNext()) { m.add(model.asStatement(AGNodeFactory.asTriple(result.next()))); } } catch (QueryEvaluationException e) { throw new QueryException(e); } return m; }
@Override public void handleClose() throws QueryEvaluationException { try { super.handleClose(); } finally { queryResult.close(); } } }
@Override public Triple next() { Triple tr; try { current = result.next(); tr = AGNodeFactory.asTriple(current); } catch (QueryEvaluationException e) { throw new RuntimeException(e); } return tr; }
@Override public boolean hasNext() throws QueryEvaluationException { final boolean hasNext = result.hasNext(); if (!hasNext) { close(); } return hasNext; }
/** * 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 Statement singleResult(GraphQueryResult result) throws QueryEvaluationException { Statement singleResult = null; try { if (result.hasNext()) { singleResult = result.next(); } } finally { result.close(); } return singleResult; }
@Override public Iterator<Triple> execConstructTriples() { try (GraphQueryResult result = getConstructResult()) { List<Triple> tripleArrayList = new ArrayList<>(); while (result.hasNext()) { tripleArrayList.add(AGNodeFactory.asTriple(result.next())); } //Getting Iterator from List return tripleArrayList.iterator(); } catch (QueryEvaluationException e) { throw new QueryException(e); } }
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 close() throws QueryEvaluationException { try { result.close(); } finally { try { connection.close(); } catch (RepositoryException e) { throw new QueryEvaluationException("Exception closing connection.", e); } } }
@Override public List<Value> next() throws QueryEvaluationException { if (isClosed()) { throw new NoSuchElementException("The iteration has been closed."); } try { 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()); } } catch (NoSuchElementException e) { close(); throw e; } }