Search in sources :

Example 56 with RepositoryException

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

the class SPARQLConnection method getStatementsQuadMode.

private RepositoryResult<Statement> getStatementsQuadMode(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws MalformedQueryException, RepositoryException, QueryEvaluationException {
    TupleQueryResult qRes = null;
    RepositoryResult<Statement> result = null;
    boolean allGood = false;
    try {
        TupleQuery tupleQuery = prepareTupleQuery(SPARQL, EVERYTHING_WITH_GRAPH);
        setBindings(tupleQuery, subj, pred, obj, contexts);
        tupleQuery.setIncludeInferred(includeInferred);
        qRes = tupleQuery.evaluate();
        result = new RepositoryResult<Statement>(new ExceptionConvertingIteration<Statement, RepositoryException>(toStatementIteration(qRes, subj, pred, obj)) {

            @Override
            protected RepositoryException convert(Exception e) {
                return new RepositoryException(e);
            }
        });
        allGood = true;
        return result;
    } finally {
        if (!allGood) {
            try {
                if (result != null) {
                    result.close();
                }
            } finally {
                if (qRes != null) {
                    qRes.close();
                }
            }
        }
    }
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) ExceptionConvertingIteration(org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) SPARQLTupleQuery(org.eclipse.rdf4j.repository.sparql.query.SPARQLTupleQuery) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) UpdateExecutionException(org.eclipse.rdf4j.query.UpdateExecutionException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) UnknownTransactionStateException(org.eclipse.rdf4j.repository.UnknownTransactionStateException) UnsupportedQueryLanguageException(org.eclipse.rdf4j.query.UnsupportedQueryLanguageException) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) IOException(java.io.IOException)

Example 57 with RepositoryException

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

the class SPARQLConnection method getStatementsSingleTriple.

private RepositoryResult<Statement> getStatementsSingleTriple(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException {
    if (hasStatement(subj, pred, obj, includeInferred, contexts)) {
        Statement st = getValueFactory().createStatement(subj, pred, obj);
        CloseableIteration<Statement, RepositoryException> cursor;
        cursor = new SingletonIteration<Statement, RepositoryException>(st);
        return new RepositoryResult<Statement>(cursor);
    } else {
        return new RepositoryResult<Statement>(new EmptyIteration<Statement, RepositoryException>());
    }
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) RepositoryResult(org.eclipse.rdf4j.repository.RepositoryResult)

Example 58 with RepositoryException

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

the class SPARQLConnection method commit.

public void commit() throws RepositoryException {
    synchronized (transactionLock) {
        if (isActive()) {
            synchronized (transactionLock) {
                SPARQLUpdate transaction = new SPARQLUpdate(client, null, sparqlTransaction.toString());
                try {
                    transaction.execute();
                } catch (UpdateExecutionException e) {
                    throw new RepositoryException("error executing transaction", e);
                }
                sparqlTransaction = null;
            }
        } else {
            throw new RepositoryException("no transaction active.");
        }
    }
}
Also used : UpdateExecutionException(org.eclipse.rdf4j.query.UpdateExecutionException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) SPARQLUpdate(org.eclipse.rdf4j.repository.sparql.query.SPARQLUpdate)

Example 59 with RepositoryException

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

the class HTTPTupleQuery method evaluate.

public void evaluate(TupleQueryResultHandler handler) throws QueryEvaluationException, TupleQueryResultHandlerException {
    SPARQLProtocolSession client = getHttpClient();
    try {
        conn.flushTransactionState(Protocol.Action.QUERY);
        client.sendTupleQuery(queryLanguage, queryString, baseURI, dataset, includeInferred, getMaxExecutionTime(), handler, getBindingsArray());
    } catch (IOException e) {
        throw new HTTPQueryEvaluationException(e.getMessage(), e);
    } catch (RepositoryException e) {
        throw new HTTPQueryEvaluationException(e.getMessage(), e);
    } catch (MalformedQueryException e) {
        throw new HTTPQueryEvaluationException(e.getMessage(), e);
    }
}
Also used : SPARQLProtocolSession(org.eclipse.rdf4j.http.client.SPARQLProtocolSession) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 60 with RepositoryException

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

the class HTTPRepositoryConnection method begin.

public void begin() throws RepositoryException {
    verifyIsOpen();
    verifyNotTxnActive("Connection already has an active transaction");
    if (this.getRepository().useCompatibleMode()) {
        active = true;
        return;
    }
    try {
        client.beginTransaction(this.getIsolationLevel());
        active = true;
    } catch (RepositoryException e) {
        throw e;
    } 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