use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippetsIT method testOrderByNameDescWithLimitQuery.
@Test
public void testOrderByNameDescWithLimitQuery() throws Exception {
Query q = queryDataSnippets.createOrderByNameDescWithLimitQuery();
List<String> result = getResults(q);
List<String> expectedResults = Arrays.asList("DC", "TOK", "SF");
assertTrue(Objects.equals(result, expectedResults));
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippetsIT method testInvalidRangeWithOrderByQuery.
@Test(expected = Exception.class)
public void testInvalidRangeWithOrderByQuery() throws Exception {
Query q = queryDataSnippets.createInvalidRangeWithOrderByQuery();
getResults(q);
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippetsIT method testOrderByNameWithLimitQuery.
@Test
public void testOrderByNameWithLimitQuery() throws Exception {
Query q = queryDataSnippets.createOrderByNameWithLimitQuery();
List<String> result = getResults(q);
List<String> expectedResults = Arrays.asList("BJ", "LA", "SF");
assertEquals(result, expectedResults);
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippetsIT method testWhereWithOrderByAndLimitQuery.
@Test
public void testWhereWithOrderByAndLimitQuery() throws Exception {
Query q = queryDataSnippets.createWhereWithOrderByAndLimitQuery();
List<String> result = getResults(q);
List<String> expectedResults = Arrays.asList("LA", "TOK");
assertEquals(result, expectedResults);
}
use of com.google.cloud.firestore.Query in project getting-started-java by GoogleCloudPlatform.
the class FirestoreDao method listBooksByUser.
// [END bookshelf_firestore_list_books]
// [START bookshelf_firestore_list_by_user]
@Override
public Result<Book> listBooksByUser(String userId, String startTitle) {
Query booksQuery = booksCollection.orderBy("title").whereEqualTo(Book.CREATED_BY_ID, userId).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);
}
Aggregations