You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by GitBox <gi...@apache.org> on 2019/07/01 09:53:41 UTC

[GitHub] [jena] der commented on a change in pull request #580: JENA-1719: Work around for iterators being held across transactions

der commented on a change in pull request #580: JENA-1719: Work around for iterators being held across transactions
URL: https://github.com/apache/jena/pull/580#discussion_r298965979
 
 

 ##########
 File path: jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/SafeTripleIterator.java
 ##########
 @@ -0,0 +1,56 @@
+package org.apache.jena.reasoner.rulesys.impl;
+
+import org.apache.jena.graph.Triple;
+import org.apache.jena.reasoner.TriplePattern;
+import org.apache.jena.reasoner.rulesys.BackwardRuleInfGraphI;
+import org.apache.jena.util.iterator.ClosableIterator;
+import org.apache.jena.util.iterator.ExtendedIterator;
+
+/**
+ * Wrapper around triple searches using in the back chainer to attempt a restart
+ * in the case of a failure such as cross-transaction query.
+ */
+public class SafeTripleIterator implements ClosableIterator<Triple> {
+
+    protected ExtendedIterator<Triple> matchIterator;
+    protected long offset = 0;
+    protected TriplePattern goal;
+    protected BackwardRuleInfGraphI infGraph;
+
+    public SafeTripleIterator(LPInterpreter interpreter, TriplePattern goal) {
+        this.infGraph = interpreter.getEngine().getInfGraph();
+        this.goal = goal;
+        restart();
+    }
+
+    protected void restart() {
+        matchIterator = infGraph.findDataMatches(goal);
+        for (int i = 0; i < offset; i++) matchIterator.next();
 
 Review comment:
   If the data changes then there should have been either an explicit `rebind()` or an implicit `prepare()` call which should clear the tabled goals anyway. If you make changes to the data bypassing both of those then iterators will blow up anyway, don't think the restarting makes this any worse.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services