@Override public CloseableIterator<STMT> findStatements(ID subject, UID predicate, NODE object, UID context, boolean includeInferred) { return connections[0].findStatements(subject, predicate, object, context, includeInferred); }
@Nullable private STMT find( @Nullable ID subject, @Nullable UID predicate, @Nullable NODE object) { CloseableIterator<STMT> stmts = connection.findStatements(subject, predicate, object, null, false); try { return stmts.hasNext() ? stmts.next() : null; } finally { stmts.close(); } } }
private List<STMT> findStatements(@Nullable ID subject, @Nullable UID predicate, @Nullable NODE object, @Nullable UID context, boolean includeInferred) { if (logger.isDebugEnabled()) { logger.debug("findStatements " + subject + " " + predicate + " " + object + " " + context); } // rdf type inference if (RDF.type.equals(predicate) && subject == null && object != null && connection.getInferenceOptions().subClassOf()) { Collection<UID> types = ontology.getSubtypes(object.asURI()); if (types.size() > 1) { RDFQuery query = new RDFQueryImpl(connection); CloseableIterator<STMT> stmts = query.where( Blocks.SPOC, QNODE.o.in(types)) .set(QNODE.p, predicate) .construct(Blocks.SPOC); return IteratorAdapter.asList(stmts); } } return IteratorAdapter.asList(connection.findStatements(subject, predicate, object, context, includeInferred)); }
@Override public Long doInConnection(RDFConnection connection) throws IOException { long count = 0l; CloseableIterator<STMT> stmts = connection.findStatements(subject, predicate, object, context, includeInferred); try { while (stmts.hasNext()) { count++; stmts.next(); } return count; } finally { stmts.close(); } }
@Override public Iterator<Bindings> iterator() { Bindings parent = bindings.getParent(); ID s = (ID) expr.getSubject().accept(QueryRDFVisitor.this, parent); UID p = (UID) expr.getPredicate().accept(QueryRDFVisitor.this, parent); NODE o = (NODE) expr.getObject().accept(QueryRDFVisitor.this, parent); UID c = null; if (expr.getContext() != null) { c = (UID) expr.getContext().accept(QueryRDFVisitor.this, parent); } else if (_context != null) { c = (UID) _context.accept(QueryRDFVisitor.this, parent); } bindings.clear(); return Iterators.transform(connection.findStatements(s, p, o, c, false), transformer); }
@Override public void export(Format format, Map<String, String> ns2prefix, UID context, OutputStream out) { RDFWriter writer = WriterUtils.createWriter(format, out, ns2prefix); RDFConnection conn = openConnection(); try { CloseableIterator<STMT> stmts = conn.findStatements(null, null, null, context, false); try { writer.begin(); while (stmts.hasNext()) { writer.handle(stmts.next()); } writer.end(); } finally { stmts.close(); } } finally { conn.close(); } }