Search in sources :

Example 66 with RepositoryException

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

the class Connections method consumeRDFCollection.

/**
 * Retrieve all {@link Statement}s that together form the RDF Collection starting with the supplied start
 * resource and send them to the supplied {@link Consumer}.
 *
 * @param conn
 *        the {@link RepositoryConnection} to use for statement retrieval.
 * @param head
 *        the start resource of the RDF Collection. May not be {@code null}.
 * @param collectionConsumer
 *        a {@link Consumer} function to which all retrieved statements will be reported. May not be
 *        {@code null}.
 * @param contexts
 *        the context(s) from which to read the RDF Collection. This argument is an optional vararg and
 *        can be left out.
 * @throws RepositoryException
 *         if an error occurred while reading the collection statements, for example if a cycle is
 *         detected in the RDF collection, or some other anomaly which makes it non-wellformed.
 * @see RDFCollections
 * @see <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Schema 1.1 section on Collection
 *      vocabulary</a>.
 */
public static void consumeRDFCollection(RepositoryConnection conn, Resource head, Consumer<Statement> collectionConsumer, Resource... contexts) throws RepositoryException {
    GetStatementOptional statementSupplier = (s, p, o, c) -> getStatement(conn, s, p, o, c);
    Function<String, Supplier<RepositoryException>> exceptionSupplier = Repositories::repositoryException;
    RDFCollections.extract(statementSupplier, head, collectionConsumer, exceptionSupplier, contexts);
}
Also used : Resource(org.eclipse.rdf4j.model.Resource) Collection(java.util.Collection) RepositoryResult(org.eclipse.rdf4j.repository.RepositoryResult) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Model(org.eclipse.rdf4j.model.Model) Value(org.eclipse.rdf4j.model.Value) Objects(java.util.Objects) Consumer(java.util.function.Consumer) RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) RDFCollections(org.eclipse.rdf4j.model.util.RDFCollections) Statement(org.eclipse.rdf4j.model.Statement) GetStatementOptional(org.eclipse.rdf4j.model.util.GetStatementOptional) Optional(java.util.Optional) IRI(org.eclipse.rdf4j.model.IRI) GetStatementOptional(org.eclipse.rdf4j.model.util.GetStatementOptional) Supplier(java.util.function.Supplier)

Example 67 with RepositoryException

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

the class AbstractRepositoryConnection method add.

@Override
public void add(Iterable<? extends Statement> statements, Resource... contexts) throws RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    boolean localTransaction = startLocalTransaction();
    try {
        for (Statement st : statements) {
            addWithoutCommit(st, contexts);
        }
        conditionalCommit(localTransaction);
    } catch (RepositoryException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (RuntimeException e) {
        conditionalRollback(localTransaction);
        throw e;
    }
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

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