Search in sources :

Example 21 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection 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 22 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.

the class NotifyingRepositoryWrapper method getConnection.

@Override
public NotifyingRepositoryConnection getConnection() throws RepositoryException {
    RepositoryConnection con = getDelegate().getConnection();
    NotifyingRepositoryConnection ncon = new NotifyingRepositoryConnectionWrapper(this, con, getDefaultReportDeltas());
    if (activated) {
        for (RepositoryListener listener : listeners) {
            listener.getConnection(this, ncon);
        }
    }
    for (RepositoryConnectionListener l : conListeners) {
        ncon.addRepositoryConnectionListener(l);
    }
    return ncon;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) NotifyingRepositoryConnection(org.eclipse.rdf4j.repository.event.NotifyingRepositoryConnection) RepositoryListener(org.eclipse.rdf4j.repository.event.RepositoryListener) RepositoryConnectionListener(org.eclipse.rdf4j.repository.event.RepositoryConnectionListener) NotifyingRepositoryConnection(org.eclipse.rdf4j.repository.event.NotifyingRepositoryConnection)

Example 23 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.

the class SystemRepository method initialize.

@Override
public void initialize() throws RepositoryException {
    super.initialize();
    RepositoryConnection con = getConnection();
    try {
        if (con.isEmpty()) {
            logger.debug("Initializing empty {} repository", ID);
            con.begin();
            con.setNamespace("rdf", RDF.NAMESPACE);
            con.setNamespace("sys", RepositoryConfigSchema.NAMESPACE);
            con.commit();
            RepositoryConfig repConfig = new RepositoryConfig(ID, TITLE, new SystemRepositoryConfig());
            RepositoryConfigUtil.updateRepositoryConfigs(con, repConfig);
        }
    } catch (RepositoryConfigException e) {
        throw new RepositoryException(e.getMessage(), e);
    } finally {
        con.close();
    }
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException)

Example 24 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.

the class NotifyingTest 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 {
        }
    };
    Repository repo = stub.getRepository();
    NotifyingRepositoryConnection con = new NotifyingRepositoryConnectionWrapper(repo, stub);
    con.addRepositoryConnectionListener(new RepositoryConnectionListenerAdapter() {

        public void 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);
        }
    });
    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) NotifyingRepositoryConnectionWrapper(org.eclipse.rdf4j.repository.event.base.NotifyingRepositoryConnectionWrapper) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory) RepositoryConnectionListenerAdapter(org.eclipse.rdf4j.repository.event.base.RepositoryConnectionListenerAdapter) Test(org.junit.Test)

Example 25 with RepositoryConnection

use of org.eclipse.rdf4j.repository.RepositoryConnection in project rdf4j by eclipse.

the class ContextAwareConnectionTest method testIncludeInferred.

@Test
public void testIncludeInferred() throws Exception {
    RepositoryConnection stub = new RepositoryConnectionStub();
    Repository repo = stub.getRepository();
    ContextAwareConnection a = new ContextAwareConnection(repo, stub);
    ContextAwareConnection b = new ContextAwareConnection(repo, a);
    b.setIncludeInferred(true);
    assertTrue(b.isIncludeInferred());
    assertTrue(a.isIncludeInferred());
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Repository(org.eclipse.rdf4j.repository.Repository) Test(org.junit.Test)

Aggregations

RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)34 Test (org.junit.Test)21 Repository (org.eclipse.rdf4j.repository.Repository)18 IRI (org.eclipse.rdf4j.model.IRI)6 Resource (org.eclipse.rdf4j.model.Resource)6 Statement (org.eclipse.rdf4j.model.Statement)6 Model (org.eclipse.rdf4j.model.Model)5 QueryLanguage (org.eclipse.rdf4j.query.QueryLanguage)5 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)4 RepositoryConfig (org.eclipse.rdf4j.repository.config.RepositoryConfig)4 Value (org.eclipse.rdf4j.model.Value)3 TreeModel (org.eclipse.rdf4j.model.impl.TreeModel)3 Dataset (org.eclipse.rdf4j.query.Dataset)3 ProxyRepositoryConfig (org.eclipse.rdf4j.repository.sail.config.ProxyRepositoryConfig)3 SailRepositoryConfig (org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig)3 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)2 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)2 Update (org.eclipse.rdf4j.query.Update)2 AbstractUpdate (org.eclipse.rdf4j.query.impl.AbstractUpdate)2 InterceptingRepositoryConnectionWrapper (org.eclipse.rdf4j.repository.event.base.InterceptingRepositoryConnectionWrapper)2