2121import com .google .common .base .Preconditions ;
2222import com .google .common .collect .AbstractIterator ;
2323import com .google .gcloud .datastore .Query .ResultType ;
24+ import com .google .protobuf .ByteString ;
2425
2526import java .util .Iterator ;
2627import java .util .Objects ;
@@ -36,7 +37,7 @@ class QueryResultsImpl<T> extends AbstractIterator<T> implements QueryResults<T>
3637 private DatastoreV1 .QueryResultBatch queryResultBatchPb ;
3738 private boolean lastBatch ;
3839 private Iterator <DatastoreV1 .EntityResult > entityResultPbIter ;
39- // private ByteString cursor; // only available in v1beta3
40+ private ByteString cursor ; // only available in v1beta3
4041
4142
4243 QueryResultsImpl (DatastoreImpl datastore , DatastoreV1 .ReadOptions readOptionsPb ,
@@ -83,6 +84,7 @@ protected T computeNext() {
8384 sendRequest ();
8485 }
8586 if (!entityResultPbIter .hasNext ()) {
87+ cursor = queryResultBatchPb .getEndCursor ();
8688 return endOfData ();
8789 }
8890 DatastoreV1 .EntityResult entityResultPb = entityResultPbIter .next ();
@@ -99,10 +101,7 @@ public Class<?> resultClass() {
99101
100102 @ Override
101103 public Cursor cursorAfter () {
104+ return cursor == null ? null : new Cursor (cursor );
102105 //return new Cursor(cursor); // only available in v1beta3
103- if (!hasNext ()) {
104- return new Cursor (queryResultBatchPb .getEndCursor ());
105- }
106- return null ;
107106 }
108107}
0 commit comments