@Test public void testInsert2() { DatasetGraph gStore = getEmptyDatasetGraph() ; UpdateModify insert = new UpdateModify() ; insert.getInsertAcc().addTriple(triple1) ; UpdateAction.execute(insert, gStore) ; assertTrue(graphContains(gStore.getDefaultGraph(), triple1)) ; }
/** * This code is equivalent to the SPARQL query below. * * <p><pre><code> * WITH trellis:PreferServerManaged * DELETE { IDENTIFIER dc:modified ?time } * INSERT { IDENTIFIER dc:modified TIME } * WHERE { IDENTIFIER dc:modified ?time } . * </code></pre></p> */ private UpdateRequest buildUpdateModificationRequest(final IRI identifier, final Literal time) { final UpdateRequest req = new UpdateRequest(); final Var modified = Var.alloc(MODIFIED); final UpdateDeleteInsert modify = new UpdateDeleteInsert(); modify.setWithIRI(rdf.asJenaNode(PreferServerManaged)); modify.getDeleteAcc().addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), modified)); modify.getInsertAcc().addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), rdf.asJenaNode(time))); final ElementGroup eg = new ElementGroup(); final ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), modified)); eg.addElement(epb); modify.setElement(eg); req.add(modify); return req; }
/** * This code is equivalent to the SPARQL query below. * * <p><pre><code> * WITH trellis:PreferServerManaged * DELETE { IDENTIFIER dc:modified ?time } * INSERT { IDENTIFIER dc:modified TIME } * WHERE { IDENTIFIER dc:modified ?time } . * </code></pre></p> */ private UpdateRequest buildUpdateModificationRequest(final IRI identifier, final Literal time) { final UpdateRequest req = new UpdateRequest(); final Var modified = Var.alloc(MODIFIED); final UpdateDeleteInsert modify = new UpdateDeleteInsert(); modify.setWithIRI(rdf.asJenaNode(PreferServerManaged)); modify.getDeleteAcc().addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), modified)); modify.getInsertAcc().addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), rdf.asJenaNode(time))); final ElementGroup eg = new ElementGroup(); final ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), modified)); eg.addElement(epb); modify.setElement(eg); req.add(modify); return req; }
@Test public void testDelete2() { DatasetGraph gStore = getEmptyDatasetGraph() ; defaultGraphData(gStore, graph1) ; QuadAcc acc = new QuadAcc() ; UpdateDeleteWhere delete = new UpdateDeleteWhere(acc) ; acc.addTriple(SSE.parseTriple("(?s ?p ?o)")) ; UpdateAction.execute(delete, gStore) ; assertTrue("Not empty", graphEmpty(gStore.getDefaultGraph())) ; }
@Test public void testInsert4() { DatasetGraph gStore = getEmptyDatasetGraph() ; defaultGraphData(gStore, graph1) ; UpdateModify insert = new UpdateModify() ; insert.getInsertAcc().addTriple(SSE.parseTriple("(?s <http://example/p> 1066)")) ; Element element = QueryFactory.createElement("{ ?s <http://example/p> 2007 }" ) ; insert.setElement(element) ; UpdateAction.execute(insert, gStore) ; assertTrue(graphContains(gStore.getDefaultGraph(), triple2)) ; }
@Test public void testModify1() { DatasetGraph gStore = getEmptyDatasetGraph() ; defaultGraphData(gStore, data2()) ; namedGraphData(gStore, graphIRI, Factory.createDefaultGraph()) ; UpdateModify modify = new UpdateModify() ; Element element = QueryFactory.createElement("{ ?s <http://example/p> ?o }" ) ; modify.setElement(element) ; modify.getInsertAcc().addQuad(new Quad(graphIRI, triple1)) ; modify.getDeleteAcc().addTriple(SSE.parseTriple("(?s <http://example/p> ?o)")) ; modify.getDeleteAcc().addQuad(SSE.parseQuad("(<http://example/graph> ?s <http://example/p> ?o)")) ; UpdateAction.execute(modify, gStore) ; assertFalse(graphEmpty(gStore.getGraph(graphIRI))) ; assertTrue(graphEmpty(gStore.getDefaultGraph())) ; assertTrue(graphContains(gStore.getGraph(graphIRI), triple1)) ; }
@Test public void testModify2() { // Use blank nodes (will expose any problems in serialization when spill occurs) Triple t = new Triple(org.apache.jena.graph.NodeFactory.createBlankNode(),p,o2); DatasetGraph gStore = getEmptyDatasetGraph() ; // Set the threshold to in order to force spill to disk gStore.getContext().set(ARQ.spillToDiskThreshold, 0L) ; defaultGraphData(gStore, data(t)) ; namedGraphData(gStore, graphIRI, data(t)); UpdateModify modify = new UpdateModify() ; Element element = QueryFactory.createElement("{ ?s <http://example/p> ?o }" ) ; modify.setElement(element) ; modify.getInsertAcc().addQuad(new Quad(graphIRI, triple1)) ; modify.getDeleteAcc().addTriple(SSE.parseTriple("(?s <http://example/p> ?o)")) ; modify.getDeleteAcc().addQuad(SSE.parseQuad("(<http://example/graph> ?s <http://example/p> ?o)")) ; UpdateAction.execute(modify, gStore) ; assertFalse(graphEmpty(gStore.getGraph(graphIRI))) ; assertTrue(graphEmpty(gStore.getDefaultGraph())) ; assertTrue(graphContains(gStore.getGraph(graphIRI), triple1)) ; assertFalse(graphContains(gStore.getGraph(graphIRI), t)); }
@Test public void testModifyInitialBindings() { DatasetGraph gStore = getEmptyDatasetGraph() ; defaultGraphData(gStore, data12()) ; namedGraphData(gStore, graphIRI, Factory.createDefaultGraph()) ; Binding initialBinding = BindingFactory.binding(Var.alloc("o"), o1) ; UpdateModify modify = new UpdateModify() ; Element element = QueryFactory.createElement("{ ?s <http://example/p> ?o }" ) ; modify.setElement(element) ; modify.getInsertAcc().addQuad(new Quad(graphIRI, triple1)) ; modify.getDeleteAcc().addTriple(SSE.parseTriple("(?s <http://example/p> ?o)")) ; modify.getDeleteAcc().addQuad(SSE.parseQuad("(<http://example/graph> ?s <http://example/p> ?o)")) ; UpdateAction.execute(modify, gStore, initialBinding) ; assertFalse(graphEmpty(gStore.getGraph(graphIRI))) ; assertFalse(graphEmpty(gStore.getDefaultGraph())) ; assertTrue(graphContains(gStore.getGraph(graphIRI), triple1)) ; assertTrue(graphContains(gStore.getDefaultGraph(), triple2)) ; assertFalse(graphContains(gStore.getDefaultGraph(), triple1)) ; }