Search in sources :

Example 1 with RepositoryConnectionInterceptorAdapter

use of org.eclipse.rdf4j.repository.event.base.RepositoryConnectionInterceptorAdapter in project rdf4j by eclipse.

the class InterceptorTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final Update updateStub = new UpdateStub() {

        public void execute() throws UpdateExecutionException {
            fail();
        }
    };
    final RepositoryConnection stub = new RepositoryConnectionStub() {

        public Update prepareUpdate(QueryLanguage ql, String query, String baseURI) throws MalformedQueryException, RepositoryException {
            return updateStub;
        }
    };
    Repository repo = stub.getRepository();
    InterceptingRepositoryConnection con = new InterceptingRepositoryConnectionWrapper(repo, stub);
    con.addRepositoryConnectionInterceptor(new RepositoryConnectionInterceptorAdapter() {

        public boolean 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);
            return true;
        }
    });
    Update update = con.prepareUpdate(SPARQL, "DELETE DATA { <> <> <> }", "http://example.com/");
    update.execute();
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Repository(org.eclipse.rdf4j.repository.Repository) QueryLanguage(org.eclipse.rdf4j.query.QueryLanguage) RepositoryConnectionInterceptorAdapter(org.eclipse.rdf4j.repository.event.base.RepositoryConnectionInterceptorAdapter) AbstractUpdate(org.eclipse.rdf4j.query.impl.AbstractUpdate) Update(org.eclipse.rdf4j.query.Update) InterceptingRepositoryConnectionWrapper(org.eclipse.rdf4j.repository.event.base.InterceptingRepositoryConnectionWrapper) Test(org.junit.Test)

Example 2 with RepositoryConnectionInterceptorAdapter

use of org.eclipse.rdf4j.repository.event.base.RepositoryConnectionInterceptorAdapter 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));
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) IRI(org.eclipse.rdf4j.model.IRI) Repository(org.eclipse.rdf4j.repository.Repository) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value) RepositoryConnectionInterceptorAdapter(org.eclipse.rdf4j.repository.event.base.RepositoryConnectionInterceptorAdapter) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory) InterceptingRepositoryConnectionWrapper(org.eclipse.rdf4j.repository.event.base.InterceptingRepositoryConnectionWrapper) Test(org.junit.Test)

Aggregations

Repository (org.eclipse.rdf4j.repository.Repository)2 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)2 InterceptingRepositoryConnectionWrapper (org.eclipse.rdf4j.repository.event.base.InterceptingRepositoryConnectionWrapper)2 RepositoryConnectionInterceptorAdapter (org.eclipse.rdf4j.repository.event.base.RepositoryConnectionInterceptorAdapter)2 Test (org.junit.Test)2 IRI (org.eclipse.rdf4j.model.IRI)1 Resource (org.eclipse.rdf4j.model.Resource)1 Value (org.eclipse.rdf4j.model.Value)1 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)1 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)1 QueryLanguage (org.eclipse.rdf4j.query.QueryLanguage)1 Update (org.eclipse.rdf4j.query.Update)1 AbstractUpdate (org.eclipse.rdf4j.query.impl.AbstractUpdate)1