use of org.eclipse.rdf4j.query.GraphQuery in project rdf4j by eclipse.
the class Repositories method graphQuery.
/**
* Performs a SPARQL Construct or Describe query on the given Repository within a transaction and passes
* the results to the given {@link RDFHandler}.
*
* @param repository
* The {@link Repository} to open a connection to.
* @param query
* The SPARQL Construct or Describe query to execute.
* @param handler
* An {@link RDFHandler} 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 graphQuery(Repository repository, String query, RDFHandler handler) throws RepositoryException, UnknownTransactionStateException, MalformedQueryException, QueryEvaluationException {
consume(repository, conn -> {
GraphQuery preparedQuery = conn.prepareGraphQuery(QueryLanguage.SPARQL, query);
preparedQuery.evaluate(handler);
});
}
use of org.eclipse.rdf4j.query.GraphQuery in project rdf4j by eclipse.
the class Repositories method graphQueryNoTransaction.
/**
* Performs a SPARQL Construct or Describe query on the given Repository without opening a transaction and
* passes the results to the given {@link RDFHandler}.
*
* @param repository
* The {@link Repository} to open a connection to.
* @param query
* The SPARQL Construct or Describe query to execute.
* @param handler
* An {@link RDFHandler} 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 graphQueryNoTransaction(Repository repository, String query, RDFHandler handler) throws RepositoryException, UnknownTransactionStateException, MalformedQueryException, QueryEvaluationException {
consumeNoTransaction(repository, conn -> {
GraphQuery preparedQuery = conn.prepareGraphQuery(QueryLanguage.SPARQL, query);
preparedQuery.evaluate(handler);
});
}
use of org.eclipse.rdf4j.query.GraphQuery in project rdf4j by eclipse.
the class SPARQLConnection method exportStatements.
public void exportStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException {
try {
GraphQuery query = prepareGraphQuery(SPARQL, EVERYTHING, "");
setBindings(query, subj, pred, obj, contexts);
query.evaluate(handler);
} catch (MalformedQueryException e) {
throw new RepositoryException(e);
} catch (QueryEvaluationException e) {
throw new RepositoryException(e);
}
}
use of org.eclipse.rdf4j.query.GraphQuery 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();
}
}
}
}
}
Aggregations