Search in sources :

Example 51 with DocumentSnapshot

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());
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot)

Example 52 with DocumentSnapshot

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());
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) DocumentReference(com.google.cloud.firestore.DocumentReference)

Example 53 with DocumentSnapshot

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();
    }
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot)

Example 54 with DocumentSnapshot

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");
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Example 55 with DocumentSnapshot

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());
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) CollectionReference(com.google.cloud.firestore.CollectionReference) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test) BaseIntegrationTest(com.example.firestore.BaseIntegrationTest)

Aggregations

DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)103 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)73 Test (org.junit.Test)52 DocumentReference (com.google.cloud.firestore.DocumentReference)49 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)23 ExecutionException (java.util.concurrent.ExecutionException)13 CollectionReference (com.google.cloud.firestore.CollectionReference)12 Query (com.google.cloud.firestore.Query)12 BaseIntegrationTest (com.example.firestore.BaseIntegrationTest)10 SingleField (com.google.cloud.firestore.LocalFirestoreHelper.SingleField)9 WriteResult (com.google.cloud.firestore.WriteResult)9 ArrayList (java.util.ArrayList)8 FileSystemExecutionException (bio.terra.service.filedata.exception.FileSystemExecutionException)6 HashMap (java.util.HashMap)6 BulkWriter (com.google.cloud.firestore.BulkWriter)5 City (com.example.firestore.snippets.model.City)4 Timestamp (com.google.cloud.Timestamp)4 FirestoreBundleTest.verifyNamedQuery (com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery)4 AllSupportedTypes (com.google.cloud.firestore.LocalFirestoreHelper.AllSupportedTypes)4 WriteBatch (com.google.cloud.firestore.WriteBatch)4