use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper in project jena by apache.
the class QueryTest method unique.
private static ResultSetRewindable unique(ResultSetRewindable results) {
// VERY crude. Utilises the fact that bindings have value equality.
List<Binding> x = new ArrayList<>();
Set<Binding> seen = new HashSet<>();
for (; results.hasNext(); ) {
Binding b = results.nextBinding();
if (seen.contains(b))
continue;
seen.add(b);
x.add(b);
}
QueryIterator qIter = new QueryIterPlainWrapper(x.iterator());
ResultSet rs = new ResultSetStream(results.getResultVars(), ModelFactory.createDefaultModel(), qIter);
return ResultSetFactory.makeRewindable(rs);
}
use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper in project jena by apache.
the class QueryTest method convertToStrings.
private ResultSetRewindable convertToStrings(ResultSetRewindable resultsActual) {
List<Binding> bindings = new ArrayList<>();
while (resultsActual.hasNext()) {
Binding b = resultsActual.nextBinding();
BindingMap b2 = BindingFactory.create();
for (String vn : resultsActual.getResultVars()) {
Var v = Var.alloc(vn);
Node n = b.get(v);
String s;
if (n == null)
s = "";
else if (n.isBlank())
s = "_:" + n.getBlankNodeLabel();
else
s = NodeFunctions.str(n);
b2.add(v, NodeFactory.createLiteral(s));
}
bindings.add(b2);
}
ResultSet rs = new ResultSetStream(resultsActual.getResultVars(), null, new QueryIterPlainWrapper(bindings.iterator()));
return ResultSetFactory.makeRewindable(rs);
}
use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper in project jena by apache.
the class SQLBridgeBase method assembleResults.
@Override
public final QueryIterator assembleResults(ResultSetJDBC rs, Binding binding, ExecutionContext execCxt) {
if (execCxt == null || execCxt.getContext().isTrueOrUndef(SDB.jdbcStream)) {
// Stream
return new QueryIterSQL(rs, binding, execCxt);
}
// Debugging or problems with unreleasing JDBC ResultSets - read all in now.
QueryIterator qIter = new QueryIterSQL(rs, binding, execCxt);
List<Binding> results = new ArrayList<Binding>();
for (; qIter.hasNext(); ) results.add(qIter.nextBinding());
qIter.close();
return new QueryIterPlainWrapper(results.iterator(), execCxt);
}
use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper in project jena by apache.
the class BuilderResultSet method build.
public static ResultSet build(Item item) {
BuilderLib.checkTagged(item, Tags.tagResultSet, "Not a (resultset ...)");
ItemList list = item.getList();
List<Var> vars = BuilderNode.buildVarList(list.get(1));
// skip tag, skip vars.
int start = 2;
List<Binding> bindings = new ArrayList<>();
for (int i = start; i < list.size(); i++) {
Item itemRow = list.get(i);
Binding b = BuilderBinding.build(itemRow);
bindings.add(b);
}
QueryIterator qIter = new QueryIterPlainWrapper(bindings.listIterator());
return new ResultSetStream(Var.varNames(vars), null, qIter);
}
use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper in project jena by apache.
the class XMLInputSAX method worker.
private void worker(InputSource in, Model model) {
if (model == null)
model = GraphFactory.makeJenaDefaultModel();
try {
XMLReader xr = XMLReaderFactory.createXMLReader();
xr.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
// ResultSetXMLHandler1 handler = new ResultSetXMLHandler1() ;
ResultSetXMLHandler2 handler = new ResultSetXMLHandler2();
xr.setContentHandler(handler);
xr.parse(in);
if (handler.isBooleanResult) {
// Set superclass member
set(handler.askResult);
return;
}
ResultSetStream rss = new ResultSetStream(handler.variables, model, new QueryIterPlainWrapper(handler.results.iterator()));
// Set superclass member
set(rss);
} catch (SAXException ex) {
throw new ResultSetException("Problems parsing file (SAXException)", ex);
} catch (IOException ex) {
throw new ResultSetException("Problems parsing file (IOException)", ex);
}
}
Aggregations