Search in sources :

Example 16 with Repository

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

the class LocalRepositoryManager method createRepository.

@Override
protected Repository createRepository(String id) throws RepositoryConfigException, RepositoryException {
    Repository repository = null;
    RepositoryConfig repConfig = getRepositoryConfig(id);
    if (repConfig != null) {
        repConfig.validate();
        repository = createRepositoryStack(repConfig.getRepositoryImplConfig());
        repository.setDataDir(getRepositoryDir(id));
        repository.initialize();
    }
    return repository;
}
Also used : RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) Repository(org.eclipse.rdf4j.repository.Repository) DelegatingRepository(org.eclipse.rdf4j.repository.DelegatingRepository)

Example 17 with Repository

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

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

the class RepositoryManager method removeRepository.

/**
 * Removes the specified repository by deleting its configuration from the manager's system repository if
 * such a configuration is present, and removing any persistent data associated with the repository.
 * Returns <tt>true</tt> if the system repository actually contained the specified repository
 * configuration. <strong>NB this operation can not be undone!</strong>
 *
 * @param repositoryID
 *        The ID of the repository that needs to be removed.
 * @throws RepositoryException
 *         If the manager failed to update its system repository.
 * @throws RepositoryConfigException
 *         If the manager doesn't know how to remove a repository due to inconsistent configuration data
 *         in the system repository. For example, this happens when there are multiple existing
 *         configurations with the concerning ID.
 */
public boolean removeRepository(String repositoryID) throws RepositoryException, RepositoryConfigException {
    logger.debug("Removing repository {}.", 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 19 with Repository

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

the class RepositoryManager method getRepository.

/**
 * Gets the repository that is known by the specified ID from this manager.
 *
 * @param identity
 *        A repository ID.
 * @return An initialized Repository object, or <tt>null</tt> if no repository was known for the specified
 *         ID.
 * @throws RepositoryConfigException
 *         If no repository could be created due to invalid or incomplete configuration data.
 */
@Override
public Repository getRepository(String identity) throws RepositoryConfigException, RepositoryException {
    synchronized (initializedRepositories) {
        updateInitializedRepositories();
        Repository result = initializedRepositories.get(identity);
        if (result != null && !result.isInitialized()) {
            // repository exists but has been shut down. throw away the old
            // object so we can re-read from the config.
            initializedRepositories.remove(identity);
            result = null;
        }
        if (result == null && SystemRepository.ID.equals(identity)) {
            result = getSystemRepository();
        }
        if (result == null) {
            // First call (or old object thrown away), create and initialize the
            // repository.
            result = createRepository(identity);
            if (result != null) {
                initializedRepositories.put(identity, result);
            }
        }
        return result;
    }
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository)

Example 20 with Repository

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

the class RepositoryManager method getSystemRepository.

/**
 * Gets the SYSTEM repository.
 */
@Deprecated
public Repository getSystemRepository() {
    if (!isInitialized()) {
        throw new IllegalStateException("Repository Manager is not initialized");
    }
    synchronized (initializedRepositories) {
        Repository systemRepository = initializedRepositories.get(SystemRepository.ID);
        if (systemRepository != null && systemRepository.isInitialized()) {
            return systemRepository;
        }
        systemRepository = createSystemRepository();
        if (systemRepository != null) {
            initializedRepositories.put(SystemRepository.ID, systemRepository);
        }
        return systemRepository;
    }
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository)

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