Search in sources :

Example 21 with Repository

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

the class RepositoryManager method removeRepositoryConfig.

/**
 * Removes the configuration for the specified repository from the manager's system repository if such a
 * configuration is present. Returns <tt>true</tt> if the system repository actually contained the
 * specified repository configuration.
 *
 * @param repositoryID
 *        The ID of the repository whose configuration needs to be removed.
 * @throws RepositoryException
 *         If the manager failed to update it's system repository.
 * @throws RepositoryConfigException
 *         If the manager doesn't know how to remove a configuration due to inconsistent configuration
 *         data in the system repository. For example, this happens when there are multiple existing
 *         configurations with the concerning ID.
 * @deprecated since 2.6.7. Use {@link #removeRepository(String repositoryID)} instead.
 */
@Deprecated
public boolean removeRepositoryConfig(String repositoryID) throws RepositoryException, RepositoryConfigException {
    logger.debug("Removing repository configuration for {}.", repositoryID);
    boolean isRemoved = hasRepositoryConfig(repositoryID);
    synchronized (initializedRepositories) {
        // update SYSTEM repository if there is one for 2.2 compatibility
        Repository systemRepository = getSystemRepository();
        if (systemRepository != null) {
            RepositoryConfigUtil.removeRepositoryConfigs(systemRepository, repositoryID);
        }
        if (isRemoved) {
            logger.debug("Shutdown repository {} after removal of configuration.", repositoryID);
            Repository repository = initializedRepositories.remove(repositoryID);
            if (repository != null && repository.isInitialized()) {
                repository.shutDown();
            }
            try {
                cleanUpRepository(repositoryID);
            } catch (IOException e) {
                throw new RepositoryException("Unable to clean up resources for removed repository " + repositoryID, e);
            }
        }
    }
    return isRemoved;
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 22 with Repository

use of org.eclipse.rdf4j.repository.Repository 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)

Example 23 with Repository

use of org.eclipse.rdf4j.repository.Repository 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);
}
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 24 with Repository

use of org.eclipse.rdf4j.repository.Repository 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)

Example 25 with Repository

use of org.eclipse.rdf4j.repository.Repository 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();
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Repository(org.eclipse.rdf4j.repository.Repository) NotifyingRepositoryConnectionWrapper(org.eclipse.rdf4j.repository.event.base.NotifyingRepositoryConnectionWrapper) QueryLanguage(org.eclipse.rdf4j.query.QueryLanguage) AbstractUpdate(org.eclipse.rdf4j.query.impl.AbstractUpdate) Update(org.eclipse.rdf4j.query.Update) RepositoryConnectionListenerAdapter(org.eclipse.rdf4j.repository.event.base.RepositoryConnectionListenerAdapter) Test(org.junit.Test)

Aggregations

Repository (org.eclipse.rdf4j.repository.Repository)27 Test (org.junit.Test)19 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)18 IRI (org.eclipse.rdf4j.model.IRI)5 QueryLanguage (org.eclipse.rdf4j.query.QueryLanguage)5 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)4 Dataset (org.eclipse.rdf4j.query.Dataset)3 IOException (java.io.IOException)2 Resource (org.eclipse.rdf4j.model.Resource)2 Value (org.eclipse.rdf4j.model.Value)2 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 DelegatingRepository (org.eclipse.rdf4j.repository.DelegatingRepository)2 InterceptingRepositoryConnectionWrapper (org.eclipse.rdf4j.repository.event.base.InterceptingRepositoryConnectionWrapper)2 NotifyingRepositoryConnectionWrapper (org.eclipse.rdf4j.repository.event.base.NotifyingRepositoryConnectionWrapper)2 RepositoryConnectionInterceptorAdapter (org.eclipse.rdf4j.repository.event.base.RepositoryConnectionInterceptorAdapter)2 RepositoryConnectionListenerAdapter (org.eclipse.rdf4j.repository.event.base.RepositoryConnectionListenerAdapter)2 HashMap (java.util.HashMap)1