use of org.apache.jena.sparql.modify.request.UpdateModify in project jena by apache.
the class UpdateBuilderTest method testInsertAndDeleteWithVar.
@Test
public void testInsertAndDeleteWithVar() {
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.modify.request.UpdateModify in project jena by apache.
the class UpdateBuilder method buildWhere.
// build updates with where clauses
private Update buildWhere() {
UpdateModify retval = new UpdateModify();
if (with != null) {
Node graph = values.get(with);
if (graph == null) {
graph = with;
}
retval.setWithIRI(graph);
}
QuadAcc acc;
Iterator<Quad> iter;
if (!inserts.isEmpty()) {
retval.setHasInsertClause(true);
acc = retval.getInsertAcc();
iter = getQuads(inserts);
while (iter.hasNext()) {
acc.addQuad(iter.next());
}
}
if (!deletes.isEmpty()) {
retval.setHasDeleteClause(true);
acc = retval.getDeleteAcc();
iter = getQuads(deletes);
while (iter.hasNext()) {
acc.addQuad(iter.next());
}
}
retval.setElement(whereProcessor.setVars(values).build());
return retval;
}
use of org.apache.jena.sparql.modify.request.UpdateModify in project jena by apache.
the class UpdateBuilderTest method testInsertAndDelete.
@Test
public void testInsertAndDelete() {
UpdateBuilder builder = new UpdateBuilder();
builder.addInsert(new Quad(g, s, p, o));
builder.addDelete(new Triple(s, p, o));
builder.addWhere(null, p, "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(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.modify.request.UpdateModify 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.modify.request.UpdateModify 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());
}
Aggregations