Refine search
private Statement first(RepositoryConnection conn, URI pred, Value obj) throws RepositoryException { RepositoryResult<Statement> stmts; stmts = conn.getStatements(null, pred, obj, true); try { if (stmts.hasNext()) return stmts.next(); return null; } finally { stmts.close(); } }
private RepositoryResult<Statement> detach(RepositoryResult<Statement> stmts) throws RepositoryException { try { Iterator<Statement> iter = stmts.asList().iterator(); CloseableIteration<Statement, RepositoryException> itern; itern = new CloseableIteratorIteration<Statement, RepositoryException>( iter); return new RepositoryResult<Statement>(itern); } finally { stmts.close(); } }
public static void printRepository(SailRepository nr) throws RepositoryException{ RepositoryResult<Statement> rr = nr.getConnection().getStatements((Resource)null, null, null, false, (Resource)null); List<Statement> rl = rr.asList(); for(Statement s : rl){ System.out.println( s.getSubject().toString()+" ----( "+ s.getPredicate().toString()+" )---> "+ s.getObject().toString()); } } }
@Override public boolean contains(Object o) { if (o instanceof Statement) { Statement st = (Statement) o; try { try (RepositoryResult result = rc.getStatements( st.getSubject(), st.getPredicate(), st.getObject(), INFER, st.getContext())) { return result.hasNext(); } } catch (Exception e) { throw new RepositoryGraphRuntimeException(e); } } else { return false; } }
@Test public void testGetStatementsMalformedTypedLiteral() throws Exception { Literal invalidIntegerLiteral = vf.createLiteral("the number four", XMLSchema.INTEGER); try { URI pred = vf.createURI(URN_PRED); testCon.add(bob, pred, invalidIntegerLiteral); RepositoryResult<Statement> statements = testCon.getStatements(bob, pred, null, true); assertNotNull(statements); assertTrue(statements.hasNext()); Statement st = statements.next(); assertTrue(st.getObject() instanceof Literal); assertTrue(st.getObject().equals(invalidIntegerLiteral)); } catch (RepositoryException e) { // shouldn't happen fail(e.getMessage()); } }
protected Collection<Value> listSubjectsInternal(final RepositoryConnection connection, org.openrdf.model.URI property, Value object, boolean includeInferred, Resource... contexts) throws RepositoryException { final ValueFactory valueFactory = connection.getValueFactory(); Set<Value> result = new HashSet<>(); RepositoryResult<Statement> qResult = connection.getStatements(null, merge(property, valueFactory), merge(object, valueFactory), includeInferred, contexts); try { while(qResult.hasNext()) { result.add(qResult.next().getSubject()); } } finally { qResult.close(); } return result; }
.getStatements(null, null, null, true); for (org.openrdf.model.Statement stmt : statements.asList()) { stmts.add(stmt); valueFactory.createStatement(stmt.getSubject(), stmt .getPredicate(), stmt.getObject(), openrdfContextURI); statements = repositoryModel.connection.getStatements(null, null, null, false, context); for (org.openrdf.model.Statement stmt : statements.asList()) { this.connection.add(valueFactory.createStatement(stmt .getSubject(), stmt.getPredicate(), stmt .getObject(), openrdfContextURI), openrdfContextURI); if (statements != null) { try { statements.close(); } catch (RepositoryException e) { throw new ModelRuntimeException(e);
@Override public OWLAxiom next() throws RepositoryException { Statement stmt = stmts.next(); org.openrdf.model.URI axiomResource = (org.openrdf.model.URI) stmt.getSubject(); RepositoryConnection connection = repository.getConnection(); try { return anonymousHandler.removeSurrogates(parseAxiom(connection, axiomResource)); } catch (RepositoryException re) { throw re; } catch (Exception e) { throw new RepositoryException(e); } finally { connection.close(); } }
@Override public JSONArray loadHistory(String filename) throws Exception { File file = new File(filename); // String encoding = EncodingDetector.detect(file); // String contents = EncodingDetector.getString(file, encoding); SailRepository myRepository = new SailRepository(new MemoryStore()); myRepository.initialize(); SailRepositoryConnection con = myRepository.getConnection(); con.add(file, "", RDFFormat.TURTLE); RepositoryResult<Statement> result = con.getStatements(null, new URIImpl("http://isi.edu/integration/karma/dev#hasWorksheetHistory"), null, false); if(result.hasNext()) { Statement stmt = result.next(); String history = stmt.getObject().stringValue(); return new JSONArray(history); } return new JSONArray(); }
public void testGraphSerialization() throws Exception { testCon.add(bob, name, nameBob); testCon.add(alice, name, nameAlice); Graph graph; RepositoryResult<Statement> statements = testCon.getStatements(null, null, null, true); try { graph = new GraphImpl(vf, statements.asList()); } finally { statements.close(); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(graph); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); Graph deserializedGraph = (Graph)in.readObject(); in.close(); assertFalse(deserializedGraph.isEmpty()); for (Statement st : deserializedGraph) { assertTrue(graph.contains(st)); assertTrue(testCon.hasStatement(st, true)); } }
private static int statementsCount(RepositoryConnection conn, Resource ctx) { int counter = 0; try { RepositoryResult<Statement> statements = conn.getStatements(null, null, null, true, ctx); while (statements.hasNext()) { counter++; statements.next(); } } catch (RepositoryException e) { LOG.error(e.getMessage()); } return counter; }
public void testGetContextIDs() throws Exception { assertEquals(0, testCon.getContextIDs().asList().size()); // load data testCon.setAutoCommit(false); testCon.add(bob, name, nameBob, context1); assertEquals(Arrays.asList(context1), testCon.getContextIDs().asList()); testCon.remove(bob, name, nameBob, context1); assertEquals(0, testCon.getContextIDs().asList().size()); testCon.setAutoCommit(true); assertEquals(0, testCon.getContextIDs().asList().size()); testCon.add(bob, name, nameBob, context2); assertEquals(Arrays.asList(context2), testCon.getContextIDs().asList()); }
private static void copyNamespacesToModel(RepositoryConnection conn, Model m) throws RepositoryException { RepositoryResult<Namespace> ns = conn.getNamespaces(); while (ns.hasNext()) { m.setNamespace(ns.next()); } }
RepositoryConnection con = repo.getConnection(); try { model.put("asSubject", con.getStatements(resource, null, null, true).asList()); model.put("asPredicate", con.getStatements(null, (URI)resource, null, true).asList()); model.put("asObject", con.getStatements(null, null, resource, true).asList());
@Override public Atom next() { try { return statementToAtom(this.it.next()); } catch (RepositoryException e) { // TODO manage this Exception LOGGER.error("Error on SailStore iterator."); return null; } }
public boolean hasNext() { try { return result.hasNext(); } catch (RepositoryException e) { throw new RepositoryGraphRuntimeException(e); } }
@Override public void close() { try { this.it.close(); } catch (RepositoryException e) { LOGGER.error("Error when closing SailStore iterator."); } }