use of org.eclipse.rdf4j.query.TupleQueryResult in project rdf4j by eclipse.
the class HTTPRepositoryConnection method getContextIDs.
public RepositoryResult<Resource> getContextIDs() throws RepositoryException {
try {
List<Resource> contextList = new ArrayList<Resource>();
TupleQueryResult contextIDs = client.getContextIDs();
try {
while (contextIDs.hasNext()) {
BindingSet bindingSet = contextIDs.next();
Value context = bindingSet.getValue("contextID");
if (context instanceof Resource) {
contextList.add((Resource) context);
}
}
} finally {
contextIDs.close();
}
return createRepositoryResult(contextList);
} catch (QueryEvaluationException e) {
throw new RepositoryException(e);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
use of org.eclipse.rdf4j.query.TupleQueryResult in project graal by graphik-team.
the class RDF4jStore method termsByPredicatePosition.
@Override
public CloseableIterator<Term> termsByPredicatePosition(Predicate p, int position) throws AtomSetException {
TupleQuery query = null;
TupleQueryResult results = null;
try {
if (position == 0) {
query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?x <" + utils.createURI(p) + "> ?y }");
} else if (position == 1) {
query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?y <" + utils.createURI(p) + "> ?x }");
} else {
throw new WrongArityException("Position should be 0 for subject or 1 for object.");
}
results = query.evaluate();
} catch (RepositoryException e) {
throw new AtomSetException(e);
} catch (MalformedQueryException e) {
throw new AtomSetException(e);
} catch (QueryEvaluationException e) {
throw new AtomSetException(e);
}
return new TermsIterator(results, "x", this.utils);
}
use of org.eclipse.rdf4j.query.TupleQueryResult 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.query.TupleQueryResult 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();
}
}
}
}
}
use of org.eclipse.rdf4j.query.TupleQueryResult in project rdf4j by eclipse.
the class SPARQLTSVCustomTest method testSES2126QuotedLiteralIntegerAsStringImplicitType.
/**
* Only Literals with the XML Schema numeric types should be simplified.
*
* @throws Exception
*/
@Test
public void testSES2126QuotedLiteralIntegerAsStringImplicitType() throws Exception {
List<String> bindingNames = Arrays.asList("test");
TupleQueryResult tqr = new IteratingTupleQueryResult(bindingNames, Arrays.asList(new ListBindingSet(bindingNames, SimpleValueFactory.getInstance().createLiteral("1"))));
String result = writeTupleResult(tqr);
assertEquals("?test\n\"1\"\n", result);
}
Aggregations