Search in sources :

Example 11 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException in project graal by graphik-team.

the class RDF4jStore method termsByPredicatePosition.

@Override
public CloseableIterator<Term> termsByPredicatePosition(Predicate p, int position) throws AtomSetException {
    TupleQuery query = null;
    TupleQueryResult results = null;
    try {
        if (position == 0) {
            query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?x <" + utils.createURI(p) + "> ?y }");
        } else if (position == 1) {
            query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?y <" + utils.createURI(p) + "> ?x }");
        } else {
            throw new WrongArityException("Position should be 0 for subject or 1 for object.");
        }
        results = query.evaluate();
    } catch (RepositoryException e) {
        throw new AtomSetException(e);
    } catch (MalformedQueryException e) {
        throw new AtomSetException(e);
    } catch (QueryEvaluationException e) {
        throw new AtomSetException(e);
    }
    return new TermsIterator(results, "x", this.utils);
}
Also used : QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) WrongArityException(fr.lirmm.graphik.graal.api.store.WrongArityException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Example 12 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException in project rdf4j by eclipse.

the class SPARQLConnection method hasStatement.

public boolean hasStatement(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException {
    try {
        BooleanQuery query = prepareBooleanQuery(SPARQL, SOMETHING, "");
        setBindings(query, subj, pred, obj, contexts);
        return query.evaluate();
    } catch (MalformedQueryException e) {
        throw new RepositoryException(e);
    } catch (QueryEvaluationException e) {
        throw new RepositoryException(e);
    }
}
Also used : BooleanQuery(org.eclipse.rdf4j.query.BooleanQuery) SPARQLBooleanQuery(org.eclipse.rdf4j.repository.sparql.query.SPARQLBooleanQuery) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Example 13 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException 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 14 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException 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 15 with QueryEvaluationException

use of org.eclipse.rdf4j.query.QueryEvaluationException 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

QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)16 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)15 IOException (java.io.IOException)9 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)9 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)9 BindingSet (org.eclipse.rdf4j.query.BindingSet)6 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)5 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)4 Value (org.eclipse.rdf4j.model.Value)4 ArrayList (java.util.ArrayList)3 ExceptionConvertingIteration (org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration)3 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)3 Resource (org.eclipse.rdf4j.model.Resource)3 Binding (org.eclipse.rdf4j.query.Binding)3 UnsupportedQueryLanguageException (org.eclipse.rdf4j.query.UnsupportedQueryLanguageException)3 UpdateExecutionException (org.eclipse.rdf4j.query.UpdateExecutionException)3 UnknownTransactionStateException (org.eclipse.rdf4j.repository.UnknownTransactionStateException)3 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)3 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)3 Model (org.eclipse.rdf4j.model.Model)2