Skip to content

Commit 2219c82

Browse files
author
Ajay Kannan
committed
minor fixes to afterCursor + test
1 parent a2e60ab commit 2219c82

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResults.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ public interface QueryResults<V> extends Iterator<V> {
3535
Class<?> resultClass();
3636

3737
/**
38-
* Returns the Cursor for the point after the value returned in the last {@link #next} call. Until
39-
* v1beta3 is supported, this field should only be used if you have set a limit and the number of
40-
* results is equal to that limit.
38+
* Returns the Cursor for the point after the value returned in the last {@link #next} call.
39+
* Currently, {@code cursorAfter} returns null in all cases but the last result.
4140
*/
4241
Cursor cursorAfter();
4342
}

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResultsImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ public Class<?> resultClass() {
100100
@Override
101101
public Cursor cursorAfter() {
102102
//return new Cursor(cursor); // only available in v1beta3
103-
return new Cursor(queryResultBatchPb.getEndCursor());
103+
if (!hasNext()) {
104+
return new Cursor(queryResultBatchPb.getEndCursor());
105+
}
106+
return null;
104107
}
105108
}

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ public void testQueryPaginationWithLimit() throws DatastoreRpcException {
478478
}
479479
EasyMock.replay(rpcFactoryMock, rpcMock);
480480
Datastore mockDatastore =
481-
this.options.toBuilder()
481+
options.toBuilder()
482482
.retryParams(RetryParams.defaultInstance())
483483
.serviceRpcFactory(rpcFactoryMock)
484484
.build()

0 commit comments

Comments
 (0)