Search in sources :

Example 1 with DatasetGraphWrapper

use of org.apache.jena.sparql.core.DatasetGraphWrapper in project jena by apache.

the class TestUpdateOperations method delete_insert_where_01.

// Check constant and template quads 
@Test
public void delete_insert_where_01() {
    DatasetGraph dsg0 = DatasetGraphFactory.create();
    UpdateRequest req = UpdateFactory.create("INSERT DATA { <x> <p> 2 . <z> <q> 2 . <z> <q> 3 . }");
    UpdateAction.execute(req, dsg0);
    assertEquals(3, dsg0.getDefaultGraph().size());
    AtomicLong counterIns = new AtomicLong(0);
    AtomicLong counterDel = new AtomicLong(0);
    DatasetGraph dsg = new DatasetGraphWrapper(dsg0) {

        @Override
        public void add(Quad quad) {
            counterIns.incrementAndGet();
            super.add(quad);
        }

        @Override
        public void delete(Quad quad) {
            counterDel.incrementAndGet();
            super.delete(quad);
        }
    };
    // WHERE clause doubles the effect.
    String s = "DELETE { ?x <p> 2 . <z> <q> 2 } INSERT { ?x <p> 1 . <x> <q> 1  } WHERE { ?x <p> ?o {} UNION {} }";
    req = UpdateFactory.create(s);
    UpdateAction.execute(req, dsg);
    // 3 : 1 constant, 2 from template.
    assertEquals(3, counterIns.get());
    assertEquals(3, counterIns.get());
    assertEquals(3, dsg.getDefaultGraph().size());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) AtomicLong(java.util.concurrent.atomic.AtomicLong) DatasetGraphWrapper(org.apache.jena.sparql.core.DatasetGraphWrapper) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BaseTest (org.apache.jena.atlas.junit.BaseTest)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 DatasetGraphWrapper (org.apache.jena.sparql.core.DatasetGraphWrapper)1 Quad (org.apache.jena.sparql.core.Quad)1 Test (org.junit.Test)1