use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.
the class ContextAwareConnectionTest method testQuery.
@Test
public void testQuery() throws Exception {
RepositoryConnection stub = new RepositoryConnectionStub() {
@Override
public Query prepareQuery(QueryLanguage ql, String query, String baseURI) throws MalformedQueryException, RepositoryException {
assertEquals(SPARQL, ql);
assertEquals(queryString, query);
return new QueryStub() {
@Override
public void setDataset(Dataset dataset) {
Set<IRI> contexts = Collections.singleton(context);
assertEquals(contexts, dataset.getDefaultGraphs());
super.setDataset(dataset);
}
};
}
};
Repository repo = stub.getRepository();
ContextAwareConnection con = new ContextAwareConnection(repo, stub);
con.setReadContexts(context);
con.setQueryLanguage(SERQL);
con.prepareQuery(SPARQL, queryString, null);
}
use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.
the class InterceptorTest method testRemove.
@Test
public void testRemove() throws Exception {
ValueFactory vf = SimpleValueFactory.getInstance();
final IRI uri = vf.createIRI("http://example.com/");
final RepositoryConnection stub = new RepositoryConnectionStub() {
protected void removeWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException {
fail();
}
};
Repository repo = stub.getRepository();
InterceptingRepositoryConnection con = new InterceptingRepositoryConnectionWrapper(repo, stub);
con.addRepositoryConnectionInterceptor(new RepositoryConnectionInterceptorAdapter() {
public boolean remove(RepositoryConnection conn, Resource subject, IRI predicate, Value object, Resource... contexts) {
assertEquals(stub, conn);
assertEquals(uri, subject);
assertEquals(uri, predicate);
assertEquals(uri, object);
assertEquals(0, contexts.length);
return true;
}
});
con.remove(con.getValueFactory().createStatement(uri, uri, uri));
}
use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.
the class NotifyingTest method testUpdate.
@Test
public void testUpdate() throws Exception {
final Update updateStub = new UpdateStub();
final RepositoryConnection stub = new RepositoryConnectionStub() {
public Update prepareUpdate(QueryLanguage ql, String query, String baseURI) throws MalformedQueryException, RepositoryException {
return updateStub;
}
};
Repository repo = stub.getRepository();
NotifyingRepositoryConnection con = new NotifyingRepositoryConnectionWrapper(repo, stub);
con.addRepositoryConnectionListener(new RepositoryConnectionListenerAdapter() {
public void execute(RepositoryConnection conn, QueryLanguage ql, String update, String baseURI, Update operation) {
assertEquals(stub, conn);
assertEquals(SPARQL, ql);
assertEquals("DELETE DATA { <> <> <> }", update);
assertEquals("http://example.com/", baseURI);
assertEquals(updateStub, operation);
}
});
Update update = con.prepareUpdate(SPARQL, "DELETE DATA { <> <> <> }", "http://example.com/");
update.execute();
}
use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.
the class RepositoryConfigUtil method getRepositoryIDs.
@Deprecated
public static Set<String> getRepositoryIDs(Repository repository) throws RepositoryException {
RepositoryConnection con = repository.getConnection();
try {
Set<String> idSet = new LinkedHashSet<String>();
RepositoryResult<Statement> idStatementIter = con.getStatements(null, REPOSITORYID, null, true);
try {
while (idStatementIter.hasNext()) {
Statement idStatement = idStatementIter.next();
if (idStatement.getObject() instanceof Literal) {
Literal idLiteral = (Literal) idStatement.getObject();
idSet.add(idLiteral.getLabel());
}
}
} finally {
idStatementIter.close();
}
return idSet;
} finally {
con.close();
}
}
use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.
the class RepositoryConfigUtil method removeRepositoryConfigs.
/**
* Removes one or more Repository configurations from a Repository. Nothing happens when this Repository
* does not contain configurations for these Repository IDs.
*
* @param repository
* The Repository to remove the configurations from.
* @param repositoryIDs
* The IDs of the Repositories whose configurations need to be removed.
* @throws RepositoryException
* Whenever access to the Repository's RepositoryConnection causes a RepositoryException.
* @throws RepositoryConfigException
*/
@Deprecated
public static boolean removeRepositoryConfigs(Repository repository, String... repositoryIDs) throws RepositoryException, RepositoryConfigException {
boolean changed = false;
RepositoryConnection con = repository.getConnection();
try {
con.begin();
for (String id : repositoryIDs) {
Resource context = getContext(con, id);
if (context != null) {
con.clear(context);
con.remove(context, RDF.TYPE, REPOSITORY_CONTEXT);
changed = true;
}
}
con.commit();
} finally {
con.close();
}
return changed;
}
Aggregations