Search in sources :

Example 6 with Result

use of com.example.getstarted.objects.Result in project getting-started-java by GoogleCloudPlatform.

the class FirestoreDao method listBooks.

// [END bookshelf_firestore_documents_to_books]
// [START bookshelf_firestore_list_books]
@Override
public Result<Book> listBooks(String startTitle) {
    Query booksQuery = booksCollection.orderBy("title").limit(10);
    if (startTitle != null) {
        booksQuery = booksQuery.startAfter(startTitle);
    }
    try {
        QuerySnapshot snapshot = booksQuery.get().get();
        List<Book> results = documentsToBooks(snapshot.getDocuments());
        String newCursor = null;
        if (results.size() > 0) {
            newCursor = results.get(results.size() - 1).getTitle();
        }
        return new Result<>(results, newCursor);
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
    return new Result<>(Lists.newArrayList(), null);
}
Also used : Query(com.google.cloud.firestore.Query) Book(com.example.getstarted.objects.Book) ExecutionException(java.util.concurrent.ExecutionException) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot) Result(com.example.getstarted.objects.Result)

Aggregations

Book (com.example.getstarted.objects.Book)6 Result (com.example.getstarted.objects.Result)6 Cursor (com.google.appengine.api.datastore.Cursor)2 Entity (com.google.appengine.api.datastore.Entity)2 FetchOptions (com.google.appengine.api.datastore.FetchOptions)2 PreparedQuery (com.google.appengine.api.datastore.PreparedQuery)2 Query (com.google.appengine.api.datastore.Query)2 Query (com.google.cloud.firestore.Query)2 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2