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:08:39 UTC
[GitHub] [jena] rvesse commented on a change in pull request #580:
JENA-1719: Work around for iterators being held across transactions
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_r298946940
##########
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:
Doesn't this needs to defend against the case where the data changes rendering the offset invalid i.e. it might no longer be possible to call `next()` the expected number of times resulting in a `NoSuchElementException`
----------------------------------------------------------------
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