Search in sources :

Example 31 with RepositoryException

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Resource(org.eclipse.rdf4j.model.Resource) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) UnauthorizedException(org.eclipse.rdf4j.http.protocol.UnauthorizedException) RDF4JProtocolSession(org.eclipse.rdf4j.http.client.RDF4JProtocolSession) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Example 32 with RepositoryException

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);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 33 with RepositoryException

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);
    }
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with RepositoryException

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;
    }
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Example 35 with RepositoryException

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);
    }
}
Also used : RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Aggregations

RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)67 IOException (java.io.IOException)24 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)20 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)15 RDF4JException (org.eclipse.rdf4j.RDF4JException)13 HttpResponse (org.apache.http.HttpResponse)11 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)10 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)8 HttpGet (org.apache.http.client.methods.HttpGet)7 Resource (org.eclipse.rdf4j.model.Resource)7 Statement (org.eclipse.rdf4j.model.Statement)6 ArrayList (java.util.ArrayList)5 HttpPut (org.apache.http.client.methods.HttpPut)5 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)5 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)5 BindingSet (org.eclipse.rdf4j.query.BindingSet)5 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)5 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4