use of org.eclipse.rdf4j.query.TupleQuery in project graal by graphik-team.
the class RDF4jStore method match.
@Override
public CloseableIterator<Atom> match(Atom atom) throws AtomSetException {
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(atom);
StringWriter s = new StringWriter();
SparqlConjunctiveQueryWriter w = new SparqlConjunctiveQueryWriter(s, this.utils.getURIzer());
try {
w.write(query);
w.close();
} catch (IOException e1) {
throw new AtomSetException("Error while converting to SPARQL " + atom, e1);
}
TupleQuery sparqlQuery = this.connection.prepareTupleQuery(s.toString());
TupleQueryResult result = sparqlQuery.evaluate();
return new TupleQueryResultAtomIterator(result, atom, utils);
}
use of org.eclipse.rdf4j.query.TupleQuery in project nextprot-api by calipho-sib.
the class PhenotypicTTLIntegrationTest method doTupleQuery.
private TupleQueryResult doTupleQuery(String sparqlQuery) throws RepositoryException, QueryEvaluationException, MalformedQueryException {
RepositoryConnection conn = testRepo.getConnection();
TupleQuery query = (TupleQuery) conn.prepareQuery(QueryLanguage.SPARQL, sparqlQuery);
TupleQueryResult result = query.evaluate();
return result;
}
use of org.eclipse.rdf4j.query.TupleQuery in project rdf4j by eclipse.
the class Repositories method tupleQueryNoTransaction.
/**
* Performs a SPARQL Select query on the given Repository without opening a transaction and passes the
* results to the given {@link TupleQueryResultHandler}.
*
* @param repository
* The {@link Repository} to open a connection to.
* @param query
* The SPARQL Select query to execute.
* @param handler
* A {@link TupleQueryResultHandler} that consumes the results.
* @throws RepositoryException
* If there was an exception dealing with the Repository.
* @throws UnknownTransactionStateException
* If the transaction state was not properly recognised. (Optional specific exception)
* @throws MalformedQueryException
* If the supplied query is malformed
* @throws QueryEvaluationException
* If there was an error evaluating the query
*/
public static void tupleQueryNoTransaction(Repository repository, String query, TupleQueryResultHandler handler) throws RepositoryException, UnknownTransactionStateException, MalformedQueryException, QueryEvaluationException {
consumeNoTransaction(repository, conn -> {
TupleQuery preparedQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
preparedQuery.evaluate(handler);
});
}
use of org.eclipse.rdf4j.query.TupleQuery in project rdf4j by eclipse.
the class Repositories method tupleQuery.
/**
* Performs a SPARQL Select query on the given Repository within a transaction and passes the results to
* the given {@link TupleQueryResultHandler}.
*
* @param repository
* The {@link Repository} to open a connection to.
* @param query
* The SPARQL Select query to execute.
* @param handler
* A {@link TupleQueryResultHandler} that consumes the results.
* @throws RepositoryException
* If there was an exception dealing with the Repository.
* @throws UnknownTransactionStateException
* If the transaction state was not properly recognised. (Optional specific exception)
* @throws MalformedQueryException
* If the supplied query is malformed
* @throws QueryEvaluationException
* If there was an error evaluating the query
*/
public static void tupleQuery(Repository repository, String query, TupleQueryResultHandler handler) throws RepositoryException, UnknownTransactionStateException, MalformedQueryException, QueryEvaluationException {
consume(repository, conn -> {
TupleQuery preparedQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
preparedQuery.evaluate(handler);
});
}
use of org.eclipse.rdf4j.query.TupleQuery 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);
}
}
Aggregations