Search in sources :

Example 86 with TupleQuery

use of org.openrdf.query.TupleQuery in project stanbol by apache.

the class SesameYard method executeSparqlFieldQuery.

/**
 * Returns the SPARQL result set for a given {@link SparqlFieldQuery} that
 * was executed on this yard
 * @param con the repository connection to use
 * @param fieldQuery the SparqlFieldQuery instance
 * @param limit the maximum number of results
 * @return the results of the SPARQL query in the {@link #contexts} of the
 * Sesame Repository
 * @throws RepositoryException on any error while using the parsed connection
 * @throws QueryEvaluationException  on any error while executing the query
 * @throws YardException if the SPARQL query created for the parsed FieldQuery
 * was illegal formatted or if the {@link #repository} does not support
 * SPARQL.
 */
private TupleQueryResult executeSparqlFieldQuery(RepositoryConnection con, final SparqlFieldQuery fieldQuery, int limit, boolean select) throws RepositoryException, YardException, QueryEvaluationException {
    log.debug("> execute FieldQuery: {}", fieldQuery);
    String sparqlQueryString = SparqlQueryUtils.createSparqlSelectQuery(fieldQuery, select, limit, SparqlEndpointTypeEnum.Sesame);
    log.debug(" - SPARQL Query: {}", sparqlQueryString);
    TupleQuery sparqlOuery;
    try {
        sparqlOuery = con.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQueryString);
    } catch (MalformedQueryException e) {
        log.error("Unable to pparse SPARQL Query generated for a FieldQuery");
        log.error("FieldQuery: {}", fieldQuery);
        log.error("SPARQL Query: {}", sparqlQueryString);
        log.error("Exception ", e);
        throw new YardException("Unable to parse SPARQL query generated for the parse FieldQuery", e);
    } catch (UnsupportedQueryTypeException e) {
        String message = "The Sesame Repository '" + repository + "'(class: " + repository.getClass().getName() + ") does not support SPARQL!";
        log.error(message, e);
        throw new YardException(message, e);
    }
    if (dataset != null) {
        // respect the configured contexts
        sparqlOuery.setDataset(dataset);
    }
    return sparqlOuery.evaluate();
}
Also used : YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) MalformedQueryException(org.openrdf.query.MalformedQueryException) UnsupportedQueryTypeException(org.apache.stanbol.entityhub.servicesapi.query.UnsupportedQueryTypeException) TupleQuery(org.openrdf.query.TupleQuery)

Aggregations

TupleQuery (org.openrdf.query.TupleQuery)86 Update (org.openrdf.query.Update)33 RepositoryConnection (org.openrdf.repository.RepositoryConnection)27 URI (org.openrdf.model.URI)13 BindingSet (org.openrdf.query.BindingSet)12 MalformedQueryException (org.openrdf.query.MalformedQueryException)11 TupleQueryResult (org.openrdf.query.TupleQueryResult)11 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10 RepositoryException (org.openrdf.repository.RepositoryException)10 SailRepository (org.openrdf.repository.sail.SailRepository)10 HashSet (java.util.HashSet)8 Literal (org.openrdf.model.Literal)8 TupleQueryResultHandlerException (org.openrdf.query.TupleQueryResultHandlerException)8 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)8 Sail (org.openrdf.sail.Sail)7 StatementImpl (org.openrdf.model.impl.StatementImpl)6 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)5 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)5 Test (org.junit.Test)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3