File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
google-cloud-datastore/src
main/java/com/google/cloud/datastore
test/java/com/google/cloud/datastore Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1616
1717package com .google .cloud .datastore ;
1818
19+ import com .google .datastore .v1 .QueryResultBatch ;
1920import java .util .Iterator ;
2021
2122/**
@@ -66,4 +67,7 @@ public interface QueryResults<V> extends Iterator<V> {
6667 * }</pre>
6768 */
6869 int getSkippedResults ();
70+
71+ /** Returns MoreResults state of the query after the current batch. */
72+ QueryResultBatch .MoreResultsType getMoreResults ();
6973}
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ class QueryResultsImpl<T> extends AbstractIterator<T> implements QueryResults<T>
3737 private boolean lastBatch ;
3838 private Iterator <com .google .datastore .v1 .EntityResult > entityResultPbIter ;
3939 private ByteString cursor ;
40+ private MoreResultsType moreResults ;
4041
4142 QueryResultsImpl (
4243 DatastoreImpl datastore , com .google .datastore .v1 .ReadOptions readOptionsPb , Query <T > query ) {
@@ -74,7 +75,8 @@ private void sendRequest() {
7475 if (mostRecentQueryPb == null ) {
7576 mostRecentQueryPb = requestPb .getQuery ();
7677 }
77- lastBatch = runQueryResponsePb .getBatch ().getMoreResults () != MoreResultsType .NOT_FINISHED ;
78+ moreResults = runQueryResponsePb .getBatch ().getMoreResults ();
79+ lastBatch = moreResults != MoreResultsType .NOT_FINISHED ;
7880 entityResultPbIter = runQueryResponsePb .getBatch ().getEntityResultsList ().iterator ();
7981 actualResultType = ResultType .fromPb (runQueryResponsePb .getBatch ().getEntityResultType ());
8082 if (Objects .equals (queryResultType , ResultType .PROJECTION_ENTITY )) {
@@ -117,4 +119,9 @@ public Cursor getCursorAfter() {
117119 public int getSkippedResults () {
118120 return runQueryResponsePb .getBatch ().getSkippedResults ();
119121 }
122+
123+ @ Override
124+ public MoreResultsType getMoreResults () {
125+ return moreResults ;
126+ }
120127}
Original file line number Diff line number Diff line change @@ -585,6 +585,26 @@ public void testStructuredQueryPagination() throws DatastoreException {
585585 EasyMock .verify (rpcFactoryMock , rpcMock );
586586 }
587587
588+ @ Test
589+ public void testStructuredQueryPaginationWithMoreResults () throws DatastoreException {
590+ List <RunQueryResponse > responses = buildResponsesForQueryPagination ();
591+ for (int i = 0 ; i < responses .size (); i ++) {
592+ EasyMock .expect (rpcMock .runQuery (EasyMock .anyObject (RunQueryRequest .class )))
593+ .andReturn (responses .get (i ));
594+ }
595+ EasyMock .replay (rpcFactoryMock , rpcMock );
596+ Datastore datastore = rpcMockOptions .getService ();
597+ QueryResults <Key > results = datastore .run (Query .newKeyQueryBuilder ().build ());
598+ int count = 0 ;
599+ while (results .hasNext ()) {
600+ count += 1 ;
601+ results .next ();
602+ }
603+ assertEquals (count , 5 );
604+ assertEquals (QueryResultBatch .MoreResultsType .NO_MORE_RESULTS , results .getMoreResults ());
605+ EasyMock .verify (rpcFactoryMock , rpcMock );
606+ }
607+
588608 private List <RunQueryResponse > buildResponsesForQueryPagination () {
589609 Entity entity4 = Entity .newBuilder (KEY4 ).set ("value" , StringValue .of ("value" )).build ();
590610 Entity entity5 = Entity .newBuilder (KEY5 ).set ("value" , "value" ).build ();
You can’t perform that action at this time.
0 commit comments