@@ -359,27 +359,28 @@ Query createStartAtSnapshotQueryCursor()
359
359
/**
360
360
* Example of a paginated query.
361
361
*/
362
- void paginateCursor () throws InterruptedException , ExecutionException , TimeoutException {
362
+ List < Query > paginateCursor () throws InterruptedException , ExecutionException , TimeoutException {
363
363
// [START fs_paginate_cursor]
364
364
// Construct query for first 25 cities, ordered by population.
365
365
CollectionReference cities = db .collection ("cities" );
366
- ApiFuture < QuerySnapshot > firstPage = cities
366
+ Query firstPage = cities
367
367
.orderBy ("population" )
368
- .limit (25 )
369
- .get ();
368
+ .limit (25 );
370
369
371
370
// Wait for the results of the API call, waiting for a maximum of 30 seconds for a result.
372
- List <QueryDocumentSnapshot > docs = firstPage .get (30 , TimeUnit .SECONDS ).getDocuments ();
371
+ ApiFuture <QuerySnapshot > future = firstPage .get ();
372
+ List <QueryDocumentSnapshot > docs = future .get (30 , TimeUnit .SECONDS ).getDocuments ();
373
373
374
374
// Construct query for the next 25 cities.
375
375
QueryDocumentSnapshot lastDoc = docs .get (docs .size () - 1 );
376
- ApiFuture < QuerySnapshot > secondPage = cities
376
+ Query secondPage = cities
377
377
.orderBy ("population" )
378
378
.startAfter (lastDoc )
379
- .limit (25 )
380
- .get ();
379
+ .limit (25 );
381
380
382
- docs = secondPage .get (30 , TimeUnit .SECONDS ).getDocuments ();
381
+ future = secondPage .get ();
382
+ docs = future .get (30 , TimeUnit .SECONDS ).getDocuments ();
383
383
// [END fs_paginate_cursor]
384
+ return Arrays .asList (firstPage , secondPage );
384
385
}
385
386
}
0 commit comments