Search in sources :

Example 1 with UpdateBuilder

use of org.apache.jena.arq.querybuilder.UpdateBuilder 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());
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) UpdateModify(org.apache.jena.sparql.modify.request.UpdateModify) Var(org.apache.jena.sparql.core.Var) Element(org.apache.jena.sparql.syntax.Element) UpdateBuilder(org.apache.jena.arq.querybuilder.UpdateBuilder) Update(org.apache.jena.update.Update) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 2 with UpdateBuilder

use of org.apache.jena.arq.querybuilder.UpdateBuilder in project jena by apache.

the class StreamRDFToConnection method flush.

/**
 * Flushes the buffer to the connection.
 */
private void flush() {
    UpdateBuilder builder = new UpdateBuilder();
    builder.addPrefixes(model);
    builder.addInsert(model);
    builder.addInsertQuads(quads);
    connection.begin(TxnType.WRITE);
    connection.update(builder.build());
    connection.commit();
    model.removeAll();
    quads.clear();
}
Also used : UpdateBuilder(org.apache.jena.arq.querybuilder.UpdateBuilder)

Aggregations

UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)2 Triple (org.apache.jena.graph.Triple)1 Quad (org.apache.jena.sparql.core.Quad)1 Var (org.apache.jena.sparql.core.Var)1 UpdateModify (org.apache.jena.sparql.modify.request.UpdateModify)1 Element (org.apache.jena.sparql.syntax.Element)1 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)1 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)1 Update (org.apache.jena.update.Update)1 Test (org.junit.Test)1