use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.
the class UpdateEngineWorker method elementFromQuads.
protected Element elementFromQuads(List<Quad> quads) {
ElementGroup el = new ElementGroup();
ElementTriplesBlock x = new ElementTriplesBlock();
// Maybe empty??
el.addElement(x);
Node g = Quad.defaultGraphNodeGenerated;
for (Quad q : quads) {
if (q.getGraph() != g) {
g = q.getGraph();
x = new ElementTriplesBlock();
if (g == null || g == Quad.defaultGraphNodeGenerated)
el.addElement(x);
else {
ElementNamedGraph eng = new ElementNamedGraph(g, x);
el.addElement(eng);
}
}
x.addTriple(q.asTriple());
}
return el;
}
use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.
the class UpdateBuilderTest method testInsertAndDeleteWithVariableNode.
@Test
public void testInsertAndDeleteWithVariableNode() {
UpdateBuilder builder = new UpdateBuilder();
Node v = NodeFactory.createVariable("v");
builder.addInsert(new Quad(g, s, v, o));
builder.addDelete(new Triple(s, v, o));
builder.addWhere(null, v, "foo");
Update update = builder.build();
assertTrue(update instanceof UpdateModify);
UpdateModify um = (UpdateModify) update;
List<Quad> quads = um.getInsertQuads();
assertEquals(1, quads.size());
Quad q = quads.get(0);
assertEquals(g, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(v, q.getPredicate());
assertEquals(o, q.getObject());
assertTrue(Var.isVar(q.getPredicate()));
quads = um.getDeleteQuads();
assertEquals(1, quads.size());
q = quads.get(0);
assertEquals(Quad.defaultGraphNodeGenerated, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(v, q.getPredicate());
assertEquals(o, q.getObject());
assertTrue(Var.isVar(q.getPredicate()));
Element e = um.getWherePattern();
assertTrue(e instanceof ElementGroup);
ElementGroup eg = (ElementGroup) e;
assertEquals(1, eg.getElements().size());
ElementPathBlock epb = (ElementPathBlock) eg.getElements().get(0);
Triple t = epb.getPattern().get(0).asTriple();
assertEquals(Node.ANY, t.getSubject());
assertEquals(v, t.getPredicate());
assertEquals(builder.makeNode("foo"), t.getObject());
assertTrue(Var.isVar(t.getPredicate()));
}
use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.
the class UpdateBuilderTest method testInsertAndDeleteWithVarReplacement.
@Test
public void testInsertAndDeleteWithVarReplacement() {
UpdateBuilder builder = new UpdateBuilder();
Var v = Var.alloc("v");
builder.addInsert(new Quad(g, s, v, o));
builder.addDelete(new Triple(s, v, o));
builder.addWhere(null, v, "foo");
builder.setVar(v, p);
Update update = builder.build();
assertTrue(update instanceof UpdateModify);
UpdateModify um = (UpdateModify) update;
List<Quad> quads = um.getInsertQuads();
assertEquals(1, quads.size());
Quad q = quads.get(0);
assertEquals(g, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(p, q.getPredicate());
assertEquals(o, q.getObject());
quads = um.getDeleteQuads();
assertEquals(1, quads.size());
q = quads.get(0);
assertEquals(Quad.defaultGraphNodeGenerated, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(p, q.getPredicate());
assertEquals(o, q.getObject());
Element e = um.getWherePattern();
assertTrue(e instanceof ElementGroup);
ElementGroup eg = (ElementGroup) e;
assertEquals(1, eg.getElements().size());
ElementPathBlock epb = (ElementPathBlock) eg.getElements().get(0);
Triple t = epb.getPattern().get(0).asTriple();
assertEquals(Node.ANY, t.getSubject());
assertEquals(p, t.getPredicate());
assertEquals(builder.makeNode("foo"), t.getObject());
}
use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.
the class UpdateBuilderTest method testInsertAndDeleteWithVariableNodeReplacement.
@Test
public void testInsertAndDeleteWithVariableNodeReplacement() {
UpdateBuilder builder = new UpdateBuilder();
Node v = NodeFactory.createVariable("v");
builder.addInsert(new Quad(g, s, v, o));
builder.addDelete(new Triple(s, v, o));
builder.addWhere(null, v, "foo");
builder.setVar(v, p);
Update update = builder.build();
assertTrue(update instanceof UpdateModify);
UpdateModify um = (UpdateModify) update;
List<Quad> quads = um.getInsertQuads();
assertEquals(1, quads.size());
Quad q = quads.get(0);
assertEquals(g, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(p, q.getPredicate());
assertEquals(o, q.getObject());
quads = um.getDeleteQuads();
assertEquals(1, quads.size());
q = quads.get(0);
assertEquals(Quad.defaultGraphNodeGenerated, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(p, q.getPredicate());
assertEquals(o, q.getObject());
Element e = um.getWherePattern();
assertTrue(e instanceof ElementGroup);
ElementGroup eg = (ElementGroup) e;
assertEquals(1, eg.getElements().size());
ElementPathBlock epb = (ElementPathBlock) eg.getElements().get(0);
Triple t = epb.getPattern().get(0).asTriple();
assertEquals(Node.ANY, t.getSubject());
assertEquals(p, t.getPredicate());
assertEquals(builder.makeNode("foo"), t.getObject());
}
use of org.apache.jena.sparql.syntax.ElementGroup in project jena by apache.
the class ARQParserBase method createQueryPattern.
protected ElementGroup createQueryPattern(Template t) {
ElementGroup elg = new ElementGroup();
Map<Node, BasicPattern> graphs = t.getGraphPattern();
for (Node n : graphs.keySet()) {
Element el = new ElementPathBlock(graphs.get(n));
if (!Quad.defaultGraphNodeGenerated.equals(n)) {
ElementGroup e = new ElementGroup();
e.addElement(el);
el = new ElementNamedGraph(n, e);
}
elg.addElement(el);
}
return elg;
}
Aggregations