Search in sources :

Example 1 with ExceptionConvertingIteration

use of org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration in project rdf4j by eclipse.

the class SPARQLConnection method getStatementGeneral.

private RepositoryResult<Statement> getStatementGeneral(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
    GraphQueryResult gRes = null;
    RepositoryResult<Statement> result = null;
    boolean allGood = false;
    try {
        GraphQuery query = prepareGraphQuery(SPARQL, EVERYTHING, "");
        query.setIncludeInferred(includeInferred);
        setBindings(query, subj, pred, obj, contexts);
        gRes = query.evaluate();
        result = new RepositoryResult<Statement>(new ExceptionConvertingIteration<Statement, RepositoryException>(gRes) {

            @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 (gRes != null) {
                    gRes.close();
                }
            }
        }
    }
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) ExceptionConvertingIteration(org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) SPARQLGraphQuery(org.eclipse.rdf4j.repository.sparql.query.SPARQLGraphQuery) GraphQuery(org.eclipse.rdf4j.query.GraphQuery) GraphQueryResult(org.eclipse.rdf4j.query.GraphQueryResult) 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 2 with ExceptionConvertingIteration

use of org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration in project rdf4j by eclipse.

the class SPARQLConnection method getContextIDs.

public RepositoryResult<Resource> getContextIDs() throws RepositoryException {
    TupleQueryResult iter = null;
    RepositoryResult<Resource> result = null;
    boolean allGood = false;
    try {
        TupleQuery query = prepareTupleQuery(SPARQL, NAMEDGRAPHS, "");
        iter = query.evaluate();
        result = new RepositoryResult<Resource>(new ExceptionConvertingIteration<Resource, RepositoryException>(new ConvertingIteration<BindingSet, Resource, QueryEvaluationException>(iter) {

            @Override
            protected Resource convert(BindingSet bindings) throws QueryEvaluationException {
                return (Resource) bindings.getValue("_");
            }
        }) {

            @Override
            protected RepositoryException convert(Exception e) {
                return new RepositoryException(e);
            }
        });
        allGood = true;
        return result;
    } catch (MalformedQueryException e) {
        throw new RepositoryException(e);
    } catch (QueryEvaluationException e) {
        throw new RepositoryException(e);
    } finally {
        if (!allGood) {
            try {
                if (result != null) {
                    result.close();
                }
            } finally {
                if (iter != null) {
                    iter.close();
                }
            }
        }
    }
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) ExceptionConvertingIteration(org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration) Resource(org.eclipse.rdf4j.model.Resource) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) SPARQLTupleQuery(org.eclipse.rdf4j.repository.sparql.query.SPARQLTupleQuery) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) 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) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Example 3 with ExceptionConvertingIteration

use of org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration 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)

Aggregations

IOException (java.io.IOException)3 ExceptionConvertingIteration (org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration)3 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)3 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)3 UnsupportedQueryLanguageException (org.eclipse.rdf4j.query.UnsupportedQueryLanguageException)3 UpdateExecutionException (org.eclipse.rdf4j.query.UpdateExecutionException)3 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)3 UnknownTransactionStateException (org.eclipse.rdf4j.repository.UnknownTransactionStateException)3 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)3 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)3 Statement (org.eclipse.rdf4j.model.Statement)2 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)2 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)2 SPARQLTupleQuery (org.eclipse.rdf4j.repository.sparql.query.SPARQLTupleQuery)2 Resource (org.eclipse.rdf4j.model.Resource)1 BindingSet (org.eclipse.rdf4j.query.BindingSet)1 GraphQuery (org.eclipse.rdf4j.query.GraphQuery)1 GraphQueryResult (org.eclipse.rdf4j.query.GraphQueryResult)1 SPARQLGraphQuery (org.eclipse.rdf4j.repository.sparql.query.SPARQLGraphQuery)1