Search in sources :

Example 11 with Repository

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

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

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

the class LocalRepositoryManager method createRepositoryStack.

/**
 * Creates the stack of Repository objects for the repository represented by the specified
 * {@link org.eclipse.rdf4j.repository.config.RepositoryImplConfig}. Uses a
 * {@link org.eclipse.rdf4j.repository.config.RepositoryFactory} to create the repository and initialize
 * it.
 *
 * @param config
 *        The node representing the to-be-created repository in the configuration.
 * @return The created repository, or <tt>null</tt> if no such repository exists.
 * @throws RepositoryConfigException
 *         If no repository could be created due to invalid or incomplete configuration data.
 */
private Repository createRepositoryStack(RepositoryImplConfig config) throws RepositoryConfigException {
    RepositoryFactory factory = RepositoryRegistry.getInstance().get(config.getType()).orElseThrow(() -> new RepositoryConfigException("Unsupported repository type: " + config.getType()));
    Repository repository = factory.getRepository(config);
    if (repository instanceof RepositoryResolverClient) {
        ((RepositoryResolverClient) repository).setRepositoryResolver(this);
    }
    if (repository instanceof FederatedServiceResolverClient) {
        ((FederatedServiceResolverClient) repository).setFederatedServiceResolver(getFederatedServiceResolver());
    }
    if (repository instanceof SessionManagerDependent) {
        ((SessionManagerDependent) repository).setHttpClientSessionManager(client);
    } else if (repository instanceof HttpClientDependent) {
        ((HttpClientDependent) repository).setHttpClient(getHttpClient());
    }
    if (config instanceof DelegatingRepositoryImplConfig) {
        RepositoryImplConfig delegateConfig = ((DelegatingRepositoryImplConfig) config).getDelegate();
        Repository delegate = createRepositoryStack(delegateConfig);
        try {
            ((DelegatingRepository) repository).setDelegate(delegate);
        } catch (ClassCastException e) {
            throw new RepositoryConfigException("Delegate specified for repository that is not a DelegatingRepository: " + delegate.getClass(), e);
        }
    }
    return repository;
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) DelegatingRepository(org.eclipse.rdf4j.repository.DelegatingRepository) RepositoryImplConfig(org.eclipse.rdf4j.repository.config.RepositoryImplConfig) DelegatingRepositoryImplConfig(org.eclipse.rdf4j.repository.config.DelegatingRepositoryImplConfig) DelegatingRepositoryImplConfig(org.eclipse.rdf4j.repository.config.DelegatingRepositoryImplConfig) RepositoryFactory(org.eclipse.rdf4j.repository.config.RepositoryFactory) FederatedServiceResolverClient(org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedServiceResolverClient) SessionManagerDependent(org.eclipse.rdf4j.http.client.SessionManagerDependent) DelegatingRepository(org.eclipse.rdf4j.repository.DelegatingRepository) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException) RepositoryResolverClient(org.eclipse.rdf4j.repository.RepositoryResolverClient) HttpClientDependent(org.eclipse.rdf4j.http.client.HttpClientDependent)

Example 14 with Repository

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

the class RepositoryManager method refresh.

/**
 * Shuts down all initialized user repositories.
 *
 * @see #shutDown()
 */
public void refresh() {
    logger.debug("Refreshing repository information in manager...");
    // FIXME: uninitialized, removed repositories won't be cleaned up.
    try {
        synchronized (initializedRepositories) {
            Iterator<Map.Entry<String, Repository>> iter = initializedRepositories.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry<String, Repository> entry = iter.next();
                String repositoryID = entry.getKey();
                Repository repository = entry.getValue();
                if (!SystemRepository.ID.equals(repositoryID)) {
                    // remove from initialized repositories
                    iter.remove();
                    // refresh single repository
                    refreshRepository(repositoryID, repository);
                }
            }
        }
    } catch (RepositoryException re) {
        logger.error("Failed to refresh repositories", re);
    }
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with Repository

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

the class RepositoryManager method shutDown.

/**
 * Shuts down all initialized repositories, including the SYSTEM repository.
 *
 * @see #refresh()
 */
public void shutDown() {
    synchronized (initializedRepositories) {
        updateInitializedRepositories();
        for (Repository repository : initializedRepositories.values()) {
            try {
                if (repository.isInitialized()) {
                    repository.shutDown();
                }
            } catch (RepositoryException e) {
                logger.error("Repository shut down failed", e);
            }
        }
        initializedRepositories.clear();
        initialized = false;
    }
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

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