/** * Visiting triple patterns in SPARQL algebra. */ @Override public void visit(final OpBGP opBGP) { if(optionalFlag) { opBGP.getPattern().getList().forEach(triple -> optionalTraversals.add(TraversalBuilder.transform(triple))); opBGP.getPattern().getList().forEach(triple -> optionalVariable.add(triple.getObject().toString())); } else opBGP.getPattern().getList().forEach(triple -> traversalList.add(TraversalBuilder.transform(triple))); }
private void delete$(Quad quad) { super.delete(quad) ; record(QuadAction.DELETE, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ; }
private void add$(Quad quad) { super.add(quad) ; record(QuadAction.ADD, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ; }
@Override public void delete(Quad quad) { if ( CheckFirst && ! contains(quad) ) { if ( RecordNoAction ) record(QuadAction.NO_DELETE, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ; return ; } delete$(quad) ; }
@Override public Iterator<Quad> find(Quad quad) { if ( quad == null ) return find(); return find(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()); }
@Test public void countChanges_03() { DatasetGraph dsgBase = DatasetGraphFactory.create() ; DatasetChangesCounter dsgChanges = new DatasetChangesCounter() ; DatasetGraph dsg = new DatasetGraphMonitor(dsgBase, dsgChanges) ; check(dsgChanges, 0, 0, 0, 0) ; dsg.add(quad1) ; dsg.add(quad1) ; dsg.delete(quad1) ; dsg.delete(quad1) ; check(dsgChanges, 1, 1, 1, 1) ; }
/** Check whether a dataset contains a named graph of the given name. * Graph with special names (union and default) return true. */ public static boolean containsGraph(DatasetGraph dsg, Node gn) { if ( Quad.isDefaultGraph(gn) || Quad.isUnionGraph(gn) ) return true ; return dsg.containsGraph(gn) ; }
@Override final public void add(Node g, Node s, Node p, Node o) { if ( Quad.isDefaultGraph(g) ) addToDftGraph(s, p, o) ; else addToNamedGraph(g, s, p, o) ; }
@Override public void begin(ReadWrite mode) { checkTransactional(); transactional.begin(mode); }
@Override public boolean promote(Promote txnType) { checkTransactional(); return transactional.promote(txnType); }
@Override public TxnType transactionType() { checkTransactional(); return transactional.transactionType(); }
public static DatasetGraph create(Graph graph) { // Find the deepest graph, the one that may be attached to a DatasetGraph. Graph graph2 = unwrap(graph); if ( graph2 instanceof GraphView ) { // This becomes a simple class that passes all transaction operations the // underlying dataset and masks the fact here are other graphs in the storage. return new DatasetGraphOne(graph, ((GraphView)graph2).getDataset()); } // Didn't find a GraphView so no backing DatasetGraph; work on the graph as given. return new DatasetGraphOne(graph); }
@Test public void countChanges_04() { DatasetGraph dsgBase = DatasetGraphFactory.create() ; DatasetChangesCounter dsgChanges = new DatasetChangesCounter() ; DatasetGraph dsg = new DatasetGraphMonitor(dsgBase, dsgChanges) ; check(dsgChanges, 0, 0, 0, 0) ; dsg.add(quad1) ; dsg.delete(quad1) ; dsg.add(quad1) ; dsg.delete(quad1) ; check(dsgChanges, 2, 2, 0, 0) ; }
private static GraphTraversal<?, ?> transform(final E_Exists expression) { final OpBGP opBGP = (OpBGP) expression.getGraphPattern(); final List<Triple> triples = opBGP.getPattern().getList(); if (triples.size() != 1) throw new IllegalStateException("Unhandled EXISTS pattern"); final GraphTraversal<?, ?> traversal = TraversalBuilder.transform(triples.get(0)); final Step endStep = traversal.asAdmin().getEndStep(); final String label = (String) endStep.getLabels().iterator().next(); endStep.removeLabel(label); return traversal; }
@Test public void countChanges_02() { DatasetGraph dsgBase = DatasetGraphFactory.create() ; DatasetChangesCounter dsgChanges = new DatasetChangesCounter() ; DatasetGraph dsg = new DatasetGraphMonitor(dsgBase, dsgChanges) ; check(dsgChanges, 0, 0, 0, 0) ; dsg.add(quad1) ; dsg.delete(quad1) ; check(dsgChanges, 1, 1, 0, 0) ; }
private static GraphTraversal<?, ?> transform(final E_NotExists expression) { final OpBGP opBGP = (OpBGP) expression.getGraphPattern(); final List<Triple> triples = opBGP.getPattern().getList(); if (triples.size() != 1) throw new IllegalStateException("Unhandled NOT EXISTS pattern"); final GraphTraversal<?, ?> traversal = TraversalBuilder.transform(triples.get(0)); final Step endStep = traversal.asAdmin().getEndStep(); final String label = (String) endStep.getLabels().iterator().next(); endStep.removeLabel(label); return __.not(traversal); } }
@Test public void countChanges_01() { DatasetGraph dsgBase = DatasetGraphFactory.create() ; DatasetChangesCounter dsgChanges = new DatasetChangesCounter() ; DatasetGraph dsg = new DatasetGraphMonitor(dsgBase, dsgChanges) ; check(dsgChanges, 0, 0, 0, 0) ; dsg.add(quad1) ; check(dsgChanges, 1, 0, 0, 0) ; }