Search in sources :

Example 16 with RepositoryConnection

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

the class ContextAwareConnectionTest method testReadContexts.

@Test
public void testReadContexts() throws Exception {
    RepositoryConnection stub = new RepositoryConnectionStub();
    Repository repo = stub.getRepository();
    ContextAwareConnection a = new ContextAwareConnection(repo, stub);
    ContextAwareConnection b = new ContextAwareConnection(repo, a);
    b.setReadContexts(context);
    assertEquals(context, b.getReadContexts()[0]);
    assertEquals(context, a.getReadContexts()[0]);
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Repository(org.eclipse.rdf4j.repository.Repository) Test(org.junit.Test)

Example 17 with RepositoryConnection

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

the class ContextAwareConnectionTest method testRemoveContexts.

@Test
public void testRemoveContexts() throws Exception {
    RepositoryConnection stub = new RepositoryConnectionStub();
    Repository repo = stub.getRepository();
    ContextAwareConnection a = new ContextAwareConnection(repo, stub);
    ContextAwareConnection b = new ContextAwareConnection(repo, a);
    b.setRemoveContexts(context);
    assertEquals(context, b.getRemoveContexts()[0]);
    assertEquals(context, a.getRemoveContexts()[0]);
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Repository(org.eclipse.rdf4j.repository.Repository) Test(org.junit.Test)

Example 18 with RepositoryConnection

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

the class ContextAwareConnectionTest method testArchiveContexts.

@Test
public void testArchiveContexts() throws Exception {
    RepositoryConnection stub = new RepositoryConnectionStub();
    Repository repo = stub.getRepository();
    ContextAwareConnection a = new ContextAwareConnection(repo, stub);
    ContextAwareConnection b = new ContextAwareConnection(repo, a);
    b.setArchiveContexts(context);
    assertEquals(context, b.getArchiveContexts()[0]);
    assertEquals(context, a.getArchiveContexts()[0]);
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Repository(org.eclipse.rdf4j.repository.Repository) Test(org.junit.Test)

Example 19 with RepositoryConnection

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

the class ContextAwareConnectionTest method testGraphQuery.

@Test
public void testGraphQuery() throws Exception {
    RepositoryConnection stub = new RepositoryConnectionStub() {

        @Override
        public GraphQuery prepareGraphQuery(QueryLanguage ql, String query, String baseURI) throws MalformedQueryException, RepositoryException {
            assertEquals(SPARQL, ql);
            assertEquals(queryString, query);
            return new GraphQueryStub() {

                @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.prepareGraphQuery(SPARQL, queryString, null);
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) IRI(org.eclipse.rdf4j.model.IRI) Repository(org.eclipse.rdf4j.repository.Repository) Dataset(org.eclipse.rdf4j.query.Dataset) QueryLanguage(org.eclipse.rdf4j.query.QueryLanguage) Test(org.junit.Test)

Example 20 with RepositoryConnection

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

the class InterceptingRepositoryWrapper method getConnection.

@Override
public InterceptingRepositoryConnection getConnection() throws RepositoryException {
    RepositoryConnection conn = getDelegate().getConnection();
    if (activated) {
        boolean denied = false;
        for (RepositoryInterceptor interceptor : interceptors) {
            denied = interceptor.getConnection(getDelegate(), conn);
            if (denied) {
                break;
            }
        }
        if (denied) {
            conn = null;
        }
    }
    if (conn == null)
        return null;
    InterceptingRepositoryConnection iconn = new InterceptingRepositoryConnectionWrapper(this, conn);
    for (RepositoryConnectionInterceptor conInterceptor : conInterceptors) {
        iconn.addRepositoryConnectionInterceptor(conInterceptor);
    }
    return iconn;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) InterceptingRepositoryConnection(org.eclipse.rdf4j.repository.event.InterceptingRepositoryConnection) InterceptingRepositoryConnection(org.eclipse.rdf4j.repository.event.InterceptingRepositoryConnection) RepositoryConnectionInterceptor(org.eclipse.rdf4j.repository.event.RepositoryConnectionInterceptor) RepositoryInterceptor(org.eclipse.rdf4j.repository.event.RepositoryInterceptor)

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