Search in sources :

Example 1 with InsertBindingSetCursor

use of org.eclipse.rdf4j.repository.sparql.query.InsertBindingSetCursor in project rdf4j by eclipse.

the class RepositoryFederatedService method select.

/**
 * Evaluate the provided sparqlQueryString at the initialized {@link Repository} of this
 * {@link FederatedService}. Insert bindings into SELECT query and evaluate
 */
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> select(Service service, Set<String> projectionVars, BindingSet bindings, String baseUri) throws QueryEvaluationException {
    try {
        String sparqlQueryString = service.getSelectQueryString(projectionVars);
        TupleQuery query = getConnection().prepareTupleQuery(QueryLanguage.SPARQL, sparqlQueryString, baseUri);
        Iterator<Binding> bIter = bindings.iterator();
        while (bIter.hasNext()) {
            Binding b = bIter.next();
            if (service.getServiceVars().contains(b.getName()))
                query.setBinding(b.getName(), b.getValue());
        }
        TupleQueryResult res = query.evaluate();
        // insert original bindings again
        InsertBindingSetCursor result = new InsertBindingSetCursor(res, bindings);
        if (service.isSilent())
            return new SilentIteration(result);
        else
            return result;
    } catch (MalformedQueryException e) {
        throw new QueryEvaluationException(e);
    } catch (RepositoryException e) {
        throw new QueryEvaluationException("Repository for endpoint " + rep.toString() + " could not be initialized.", e);
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) InsertBindingSetCursor(org.eclipse.rdf4j.repository.sparql.query.InsertBindingSetCursor) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Aggregations

Binding (org.eclipse.rdf4j.query.Binding)1 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)1 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)1 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)1 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)1 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)1 InsertBindingSetCursor (org.eclipse.rdf4j.repository.sparql.query.InsertBindingSetCursor)1