use of com.google.cloud.firestore.DocumentSnapshot in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreDefaultClassMapper method documentToEntity.
public <T> T documentToEntity(Document document, Class<T> clazz) {
DocumentSnapshot documentSnapshot = INTERNAL.snapshotFromProto(Timestamp.now(), document);
T entity = documentSnapshot.toObject(clazz);
return setUpdateTime(entity, documentSnapshot.getUpdateTime());
}
use of com.google.cloud.firestore.DocumentSnapshot in project spring-cloud-gcp by GoogleCloudPlatform.
the class FirestoreSampleApp method readDocumentToMap.
private void readDocumentToMap() throws ExecutionException, InterruptedException {
DocumentReference docRef = this.firestore.document("users/ada");
ApiFuture<DocumentSnapshot> documentSnapshotApiFuture = docRef.get();
DocumentSnapshot document = documentSnapshotApiFuture.get();
System.out.println("read: " + document.getData());
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-docs-samples by GoogleCloudPlatform.
the class QuickstartIT method deleteAllDocuments.
private void deleteAllDocuments() throws Exception {
ApiFuture<QuerySnapshot> future = db.collection("users").get();
QuerySnapshot querySnapshot = future.get();
for (DocumentSnapshot doc : querySnapshot.getDocuments()) {
// block on delete operation
db.document("users/" + doc.getId()).delete().get();
}
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-docs-samples by GoogleCloudPlatform.
the class ManageDataSnippetsIT method testUpdateNestedFields.
@Test
public void testUpdateNestedFields() throws Exception {
manageDataSnippets.updateNestedFields();
DocumentReference docRef = db.collection("users").document("frank");
DocumentSnapshot snapshot = getDocumentData(docRef);
assertEquals((long) snapshot.getLong("age"), 13);
assertEquals(snapshot.getString("favorites.color"), "Red");
assertEquals(snapshot.getString("favorites.food"), "Pizza");
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-docs-samples by GoogleCloudPlatform.
the class ManageDataSnippetsIT method testWriteBatchIsSuccessful.
@Test
public void testWriteBatchIsSuccessful() throws Exception {
manageDataSnippets.writeBatch();
CollectionReference collection = db.collection("cities");
ApiFuture<DocumentSnapshot> document = collection.document("NYC").get();
assertTrue(document.get().exists());
DocumentReference documentReference = collection.document("SF");
Map<String, Object> data = getDocumentDataAsMap(documentReference);
assertTrue(data.containsKey("population"));
document = collection.document("LA").get();
assertFalse(document.get().exists());
}
Aggregations