rvesse 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_r298948482
##########
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:
For the case of `restart()` under `next()` this is fine but for `restart()`
under `hasNext()` you'd expect to get a `false` return not an exception
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services