Search in sources :

Example 1 with UnsupportedQueryTypeException

use of org.apache.stanbol.entityhub.servicesapi.query.UnsupportedQueryTypeException 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

UnsupportedQueryTypeException (org.apache.stanbol.entityhub.servicesapi.query.UnsupportedQueryTypeException)1 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)1 MalformedQueryException (org.openrdf.query.MalformedQueryException)1 TupleQuery (org.openrdf.query.TupleQuery)1