Author: rvesse
Date: Fri Apr 5 21:41:04 2013
New Revision: 1465137
URL: http://svn.apache.org/r1465137
Log:
Some improvements to ResultSetPeeking to minimize the change of getting out of
sync with the underlying result set
Fixes a bug in XmlInputStaX where row number was incremented prematurely in
hasNext(), should be incremented in next() to align with all other result set
implementations
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/ResultSetPeeking.java
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/XMLInputStAX.java
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/ResultSetPeeking.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/ResultSetPeeking.java?rev=1465137&r1=1465136&r2=1465137&view=diff
==============================================================================
---
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/ResultSetPeeking.java
(original)
+++
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/ResultSetPeeking.java
Fri Apr 5 21:41:04 2013
@@ -63,9 +63,11 @@ public class ResultSetPeeking implements
@Override
public boolean hasNext() {
- if (this.hasPeeked())
+ if (this.hasPeeked()) {
return true;
- return this.results.hasNext();
+ } else {
+ return this.canPeek();
+ }
}
@Override
@@ -85,9 +87,11 @@ public class ResultSetPeeking implements
this.peeked = null;
this.rowNumber++;
return b;
- } else if (this.results.hasNext()) {
+ } else if (this.canPeek()) {
+ Binding b = this.peekBinding();
+ this.peeked = null;
this.rowNumber++;
- return this.results.nextBinding();
+ return b;
} else {
throw new NoSuchElementException();
}
@@ -125,7 +129,7 @@ public class ResultSetPeeking implements
} else if (diff >= 1) {
// If difference between what we think the row number is and that
of
// the underlying result set is > 1 then someone has moved
positions
- // in the underying result set independently
+ // in the underlying result set independently
// Sync up with current position and report false
if (warnOnSyncErrors)
LOGGER.warn("Underlying result set was moved forward " + (diff
- 1)
@@ -142,6 +146,14 @@ public class ResultSetPeeking implements
"Underlying result set position has moved backwards, this
result set is no longer usable");
}
}
+
+ /**
+ * Gets whether we can peek
+ * @return True if we can peek, false otherwise
+ */
+ private boolean canPeek() {
+ return this.results.hasNext();
+ }
@Override
public QuerySolution peek() {
@@ -152,7 +164,7 @@ public class ResultSetPeeking implements
public Binding peekBinding() {
if (this.hasPeeked()) {
return this.peeked;
- } else if (this.results.hasNext()) {
+ } else if (this.canPeek()) {
this.peeked = this.results.nextBinding();
return this.peeked;
} else {
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/XMLInputStAX.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/XMLInputStAX.java?rev=1465137&r1=1465136&r2=1465137&view=diff
==============================================================================
---
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/XMLInputStAX.java
(original)
+++
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/XMLInputStAX.java
Fri Apr 5 21:41:04 2013
@@ -236,7 +236,6 @@ class XMLInputStAX extends SPARQLResult
ex.printStackTrace(System.err) ;
staxError("XMLStreamException: "+ex.getMessage(), ex) ;
}
- row++ ;
boolean b = (binding != null) ;
//parser.close() ; // Some way to close the input stream.
if (!b)
@@ -258,6 +257,7 @@ class XMLInputStAX extends SPARQLResult
if ( ! hasNext() )
throw new NoSuchElementException("End of XML Results") ;
Binding r = binding ;
+ row++ ;
binding = null ;
return r ;
}