use of org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration 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();
}
}
}
}
}
use of org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration in project rdf4j by eclipse.
the class SPARQLConnection method getContextIDs.
public RepositoryResult<Resource> getContextIDs() throws RepositoryException {
TupleQueryResult iter = null;
RepositoryResult<Resource> result = null;
boolean allGood = false;
try {
TupleQuery query = prepareTupleQuery(SPARQL, NAMEDGRAPHS, "");
iter = query.evaluate();
result = new RepositoryResult<Resource>(new ExceptionConvertingIteration<Resource, RepositoryException>(new ConvertingIteration<BindingSet, Resource, QueryEvaluationException>(iter) {
@Override
protected Resource convert(BindingSet bindings) throws QueryEvaluationException {
return (Resource) bindings.getValue("_");
}
}) {
@Override
protected RepositoryException convert(Exception e) {
return new RepositoryException(e);
}
});
allGood = true;
return result;
} catch (MalformedQueryException e) {
throw new RepositoryException(e);
} catch (QueryEvaluationException e) {
throw new RepositoryException(e);
} finally {
if (!allGood) {
try {
if (result != null) {
result.close();
}
} finally {
if (iter != null) {
iter.close();
}
}
}
}
}
use of org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration in project rdf4j by eclipse.
the class SPARQLConnection method getStatementsQuadMode.
private RepositoryResult<Statement> getStatementsQuadMode(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws MalformedQueryException, RepositoryException, QueryEvaluationException {
TupleQueryResult qRes = null;
RepositoryResult<Statement> result = null;
boolean allGood = false;
try {
TupleQuery tupleQuery = prepareTupleQuery(SPARQL, EVERYTHING_WITH_GRAPH);
setBindings(tupleQuery, subj, pred, obj, contexts);
tupleQuery.setIncludeInferred(includeInferred);
qRes = tupleQuery.evaluate();
result = new RepositoryResult<Statement>(new ExceptionConvertingIteration<Statement, RepositoryException>(toStatementIteration(qRes, subj, pred, obj)) {
@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 (qRes != null) {
qRes.close();
}
}
}
}
}
Aggregations