use of org.apache.jena.query.ResultSet 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.query.ResultSet 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.query.ResultSet in project jena by apache.
the class StoreUtils method containsGraph.
public static boolean containsGraph(Store store, Node graphNode) {
String qs = "SELECT * { GRAPH " + FmtUtils.stringForNode(graphNode) + " { ?s ?p ?o }} LIMIT 1";
Dataset ds = SDBFactory.connectDataset(store);
try (QueryExecution qExec = QueryExecutionFactory.create(qs, ds)) {
ResultSet rs = qExec.execSelect();
return rs.hasNext();
}
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestMultipleEmbedded method multiple_04.
// Two servers, one dataset under two names.
@Test
public void multiple_04() {
DatasetGraph dsg = dataset();
int port1 = FusekiLib.choosePort();
FusekiEmbeddedServer server1 = FusekiEmbeddedServer.create().setPort(port1).add("/ds1", dsg).build().start();
Txn.executeWrite(dsg, () -> dsg.add(q1));
int port2 = FusekiLib.choosePort();
FusekiEmbeddedServer server2 = FusekiEmbeddedServer.create().setPort(port2).add("/ds2", dsg).build().start();
Txn.executeWrite(dsg, () -> dsg.add(q2));
query("http://localhost:" + port1 + "/ds1", "SELECT * {?s ?p ?o}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(2, x);
});
query("http://localhost:" + port2 + "/ds2", "SELECT * {?s ?p ?o}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(2, x);
});
server1.stop();
server2.stop();
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestEmbeddedFuseki method embedded_01.
// Test - build on default port.
@Test
public void embedded_01() {
DatasetGraph dsg = dataset();
// Default port.
int port = 3330;
FusekiEmbeddedServer server = FusekiEmbeddedServer.create().add("/ds", dsg).build();
assertTrue(server.getDataAccessPointRegistry().isRegistered("/ds"));
server.start();
query("http://localhost:" + port + "/ds/query", "SELECT * { ?s ?p ?o}", qExec -> {
ResultSet rs = qExec.execSelect();
assertFalse(rs.hasNext());
});
server.stop();
}
Aggregations