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);
}
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();
}
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;
}
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);
}
}
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;
}
}
Aggregations