use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class RemoteRepositoryManager method addRepositoryConfig.
@Override
public void addRepositoryConfig(RepositoryConfig config) throws RepositoryException, RepositoryConfigException {
try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
String baseURI = Protocol.getRepositoryLocation(serverURL, config.getID());
Resource ctx = SimpleValueFactory.getInstance().createIRI(baseURI + "#" + config.getID());
httpClient.setUsernameAndPassword(username, password);
httpClient.setRepository(Protocol.getRepositoryLocation(serverURL, SystemRepository.ID));
Model model = new LinkedHashModel();
config.export(model, ctx);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Rio.write(model, baos, httpClient.getPreferredRDFFormat());
removeRepository(config.getID());
try (InputStream contents = new ByteArrayInputStream(baos.toByteArray())) {
httpClient.upload(contents, baseURI, httpClient.getPreferredRDFFormat(), false, true, ctx);
}
} catch (IOException | QueryEvaluationException | UnauthorizedException ue) {
throw new RepositoryException(ue);
}
}
use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class HTTPRepositoryConnection method addModel.
private void addModel(Model m) throws RepositoryException {
// TODO we should dynamically pick a format from the available writers
// perhaps?
RDFFormat format = RDFFormat.BINARY;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Rio.write(m, out, format);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
client.addData(in, null, format);
} catch (RDFHandlerException e) {
throw new RepositoryException("error while writing statement", e);
} catch (RDFParseException e) {
throw new RepositoryException(e);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
use of org.eclipse.rdf4j.repository.RepositoryException 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.RepositoryException 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;
}
}
use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class HTTPRepositoryConnection method commit.
public void commit() throws RepositoryException {
if (this.getRepository().useCompatibleMode()) {
synchronized (txn) {
if (txn.size() > 0) {
try {
client.sendTransaction(txn);
txn.clear();
} catch (IOException e) {
throw new RepositoryException(e);
}
}
active = false;
}
return;
}
flushTransactionState(Action.COMMIT);
try {
client.commitTransaction();
active = false;
} catch (RDF4JException e) {
throw new RepositoryException(e);
} catch (IllegalStateException e) {
throw new RepositoryException(e);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
Aggregations