use of org.apache.jena.query.ResultSet in project jena by apache.
the class FusekiBuilder method addServiceEP.
private static void addServiceEP(DataService dataService, OperationName opName, Resource svc, Property property) {
String p = "<" + property.getURI() + ">";
ResultSet rs = query("SELECT * { ?svc " + p + " ?ep}", svc.getModel(), "svc", svc);
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
String epName = soln.getLiteral("ep").getLexicalForm();
Endpoint operation = new Endpoint(opName, epName);
addServiceEP(dataService, opName, epName);
//log.info(" " + opName.name + " = " + dataAccessPoint.getName() + "/" + epName) ;
}
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class FusekiBuilder method getOne.
public static RDFNode getOne(Resource svc, String property) {
String ln = property.substring(property.indexOf(':') + 1);
ResultSet rs = FusekiLib.query("SELECT * { ?svc " + property + " ?x}", svc.getModel(), "svc", svc);
if (!rs.hasNext())
throw new FusekiConfigException("No " + ln + " for service " + FusekiLib.nodeLabel(svc));
RDFNode x = rs.next().get("x");
if (rs.hasNext())
throw new FusekiConfigException("Multiple " + ln + " for service " + FusekiLib.nodeLabel(svc));
return x;
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestEmbeddedFuseki method embedded_03.
// Different dataset name.
@Test
public void embedded_03() {
DatasetGraph dsg = dataset();
int port = FusekiLib.choosePort();
FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).add("/ds1", dsg).build();
server.start();
try {
// Add while live.
Txn.executeWrite(dsg, () -> {
Quad q = SSE.parseQuad("(_ :s :p _:b)");
dsg.add(q);
});
query("http://localhost:" + port + "/ds1/query", "SELECT * { ?s ?p ?o}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(1, x);
});
} finally {
server.stop();
}
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestMultipleEmbedded method multiple_03.
// Two servers, two datasets.
@Test
public void multiple_03() {
DatasetGraph dsg1 = dataset();
DatasetGraph dsg2 = dataset();
// Same name.
int port1 = FusekiLib.choosePort();
FusekiEmbeddedServer server1 = FusekiEmbeddedServer.create().setPort(port1).add("/ds", dsg1).build().start();
Txn.executeWrite(dsg1, () -> dsg1.add(q1));
int port2 = FusekiLib.choosePort();
FusekiEmbeddedServer server2 = FusekiEmbeddedServer.create().setPort(port2).add("/ds", dsg2).build().start();
Txn.executeWrite(dsg2, () -> dsg2.add(q2));
query("http://localhost:" + port1 + "/ds/", "SELECT * {?s ?p 1}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(1, x);
});
query("http://localhost:" + port2 + "/ds/", "SELECT * {?s ?p 1}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(0, x);
});
server1.stop();
// server2 still running
query("http://localhost:" + port2 + "/ds/", "SELECT * {?s ?p 2}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(1, x);
});
server2.stop();
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class AlgebraExec method main.
public static void main(String[] argv) {
String BASE = "http://example/";
BasicPattern bp = new BasicPattern();
Var var_x = Var.alloc("x");
Var var_z = Var.alloc("z");
// ---- Build expression
bp.add(new Triple(var_x, NodeFactory.createURI(BASE + "p"), var_z));
Op op = new OpBGP(bp);
//Expr expr = ExprUtils.parse("?z < 2 ") ;
Expr expr = new E_LessThan(new ExprVar(var_z), NodeValue.makeNodeInteger(2));
op = OpFilter.filter(expr, op);
// ---- Example setup
Model m = makeModel();
m.write(System.out, "TTL");
System.out.println("--------------");
System.out.print(op);
System.out.println("--------------");
// ---- Execute expression
QueryIterator qIter = Algebra.exec(op, m.getGraph());
// -------- Either read the query iterator directly ...
if (false) {
for (; qIter.hasNext(); ) {
Binding b = qIter.nextBinding();
Node n = b.get(var_x);
System.out.println(NodeFmtLib.displayStr(n));
System.out.println(b);
}
qIter.close();
} else {
// -------- Or make ResultSet from it (but not both - reading an
// iterator consumes the current solution)
List<String> varNames = new ArrayList<>();
varNames.add("x");
varNames.add("z");
ResultSet rs = new ResultSetStream(varNames, m, qIter);
ResultSetFormatter.out(rs);
qIter.close();
}
System.exit(0);
}
Aggregations