use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.
the class RepositoryConfigUtil method getRepositoryConfig.
@Deprecated
public static RepositoryConfig getRepositoryConfig(Repository repository, String repositoryID) throws RepositoryConfigException, RepositoryException {
RepositoryConnection con = repository.getConnection();
try {
Statement idStatement = getIDStatement(con, repositoryID);
if (idStatement == null) {
// No such config
return null;
}
Resource repositoryNode = idStatement.getSubject();
Resource context = idStatement.getContext();
if (context == null) {
throw new RepositoryException("No configuration context for repository " + repositoryID);
}
Model contextGraph = QueryResults.asModel(con.getStatements(null, null, null, true, context));
return RepositoryConfig.create(contextGraph, repositoryNode);
} finally {
con.close();
}
}
use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.
the class RepositoryUtil method equals.
/**
* Compares the models in the default contexts of the two supplied repositories and returns true if they
* are equal. Models are equal if they contain the same set of statements. bNodes IDs are not relevant for
* model equality, they are mapped from one model to the other by using the attached properties. Note that
* the method pulls the entire default context of both repositories into main memory. Use with caution.
*/
public static boolean equals(Repository rep1, Repository rep2) throws RepositoryException {
// Fetch statements from rep1 and rep2
Set<Statement> model1, model2;
RepositoryConnection con1 = rep1.getConnection();
try {
model1 = Iterations.asSet(con1.getStatements(null, null, null, true));
} finally {
con1.close();
}
RepositoryConnection con2 = rep2.getConnection();
try {
model2 = Iterations.asSet(con2.getStatements(null, null, null, true));
} finally {
con2.close();
}
return Models.isomorphic(model1, model2);
}
use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.
the class Connections method consumeRDFCollection.
/**
* Retrieve all {@link Statement}s that together form the RDF Collection starting with the supplied start
* resource and send them to the supplied {@link Consumer}.
*
* @param conn
* the {@link RepositoryConnection} to use for statement retrieval.
* @param head
* the start resource of the RDF Collection. May not be {@code null}.
* @param collectionConsumer
* a {@link Consumer} function to which all retrieved statements will be reported. May not be
* {@code null}.
* @param contexts
* the context(s) from which to read the RDF Collection. This argument is an optional vararg and
* can be left out.
* @throws RepositoryException
* if an error occurred while reading the collection statements, for example if a cycle is
* detected in the RDF collection, or some other anomaly which makes it non-wellformed.
* @see RDFCollections
* @see <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Schema 1.1 section on Collection
* vocabulary</a>.
*/
public static void consumeRDFCollection(RepositoryConnection conn, Resource head, Consumer<Statement> collectionConsumer, Resource... contexts) throws RepositoryException {
GetStatementOptional statementSupplier = (s, p, o, c) -> getStatement(conn, s, p, o, c);
Function<String, Supplier<RepositoryException>> exceptionSupplier = Repositories::repositoryException;
RDFCollections.extract(statementSupplier, head, collectionConsumer, exceptionSupplier, contexts);
}
use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.
the class LocalRepositoryManagerTest method testRestartManagerWithoutTransaction.
@Test
public void testRestartManagerWithoutTransaction() throws Exception {
Repository rep = manager.getRepository(TEST_REPO);
assertNotNull("Expected repository to exist.", rep);
assertTrue("Expected repository to be initialized.", rep.isInitialized());
RepositoryConnection conn = rep.getConnection();
try {
conn.add(conn.getValueFactory().createIRI("urn:sesame:test:subject"), RDF.TYPE, OWL.ONTOLOGY);
assertEquals(1, conn.size());
} finally {
conn.close();
rep.shutDown();
manager.shutDown();
}
manager = new LocalRepositoryManager(datadir);
manager.initialize();
Repository rep2 = manager.getRepository(TEST_REPO);
assertNotNull("Expected repository to exist.", rep2);
assertTrue("Expected repository to be initialized.", rep2.isInitialized());
RepositoryConnection conn2 = rep2.getConnection();
try {
assertEquals(1, conn2.size());
} finally {
conn2.close();
rep2.shutDown();
manager.shutDown();
}
}
Aggregations