Search in sources :

Example 1 with DeleteMutation

use of com.google.firebase.firestore.model.mutation.DeleteMutation in project firebase-android-sdk by firebase.

the class RemoteSerializer method decodeMutation.

public Mutation decodeMutation(com.google.firestore.v1.Write mutation) {
    Precondition precondition = mutation.hasCurrentDocument() ? decodePrecondition(mutation.getCurrentDocument()) : Precondition.NONE;
    List<FieldTransform> fieldTransforms = new ArrayList<>();
    for (DocumentTransform.FieldTransform fieldTransform : mutation.getUpdateTransformsList()) {
        fieldTransforms.add(decodeFieldTransform(fieldTransform));
    }
    switch(mutation.getOperationCase()) {
        case UPDATE:
            if (mutation.hasUpdateMask()) {
                return new PatchMutation(decodeKey(mutation.getUpdate().getName()), ObjectValue.fromMap(mutation.getUpdate().getFieldsMap()), decodeDocumentMask(mutation.getUpdateMask()), precondition, fieldTransforms);
            } else {
                return new SetMutation(decodeKey(mutation.getUpdate().getName()), ObjectValue.fromMap(mutation.getUpdate().getFieldsMap()), precondition, fieldTransforms);
            }
        case DELETE:
            return new DeleteMutation(decodeKey(mutation.getDelete()), precondition);
        case VERIFY:
            return new VerifyMutation(decodeKey(mutation.getVerify()), precondition);
        default:
            throw fail("Unknown mutation operation: %d", mutation.getOperationCase());
    }
}
Also used : DocumentTransform(com.google.firestore.v1.DocumentTransform) DeleteMutation(com.google.firebase.firestore.model.mutation.DeleteMutation) Precondition(com.google.firebase.firestore.model.mutation.Precondition) FieldTransform(com.google.firebase.firestore.model.mutation.FieldTransform) ArrayList(java.util.ArrayList) PatchMutation(com.google.firebase.firestore.model.mutation.PatchMutation) VerifyMutation(com.google.firebase.firestore.model.mutation.VerifyMutation) SetMutation(com.google.firebase.firestore.model.mutation.SetMutation)

Example 2 with DeleteMutation

use of com.google.firebase.firestore.model.mutation.DeleteMutation in project firebase-android-sdk by firebase.

the class WriteBatch method delete.

/**
 * Deletes the document referred to by the provided {@code DocumentReference}.
 *
 * @param documentRef The {@code DocumentReference} to delete.
 * @return This {@code WriteBatch} instance. Used for chaining method calls.
 */
@NonNull
public WriteBatch delete(@NonNull DocumentReference documentRef) {
    firestore.validateReference(documentRef);
    verifyNotCommitted();
    mutations.add(new DeleteMutation(documentRef.getKey(), Precondition.NONE));
    return this;
}
Also used : DeleteMutation(com.google.firebase.firestore.model.mutation.DeleteMutation) NonNull(androidx.annotation.NonNull)

Example 3 with DeleteMutation

use of com.google.firebase.firestore.model.mutation.DeleteMutation in project firebase-android-sdk by firebase.

the class QueryEngineTestCase method doesNotIncludeDocumentsDeletedByMutation.

@Test
public void doesNotIncludeDocumentsDeletedByMutation() throws Exception {
    Query query = query("coll");
    addDocument(MATCHING_DOC_A, MATCHING_DOC_B);
    persistQueryMapping(MATCHING_DOC_A.getKey(), MATCHING_DOC_B.getKey());
    // Add an unacknowledged mutation
    addMutation(new DeleteMutation(key("coll/b"), Precondition.NONE));
    ImmutableSortedMap<DocumentKey, Document> docs = expectFullCollectionScan(() -> queryEngine.getDocumentsMatchingQuery(query, LAST_LIMBO_FREE_SNAPSHOT, targetCache.getMatchingKeysForTargetId(TEST_TARGET_ID)));
    assertEquals(emptyMutableDocumentMap().insert(MATCHING_DOC_A.getKey(), MATCHING_DOC_A), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DeleteMutation(com.google.firebase.firestore.model.mutation.DeleteMutation) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Document(com.google.firebase.firestore.model.Document) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Aggregations

DeleteMutation (com.google.firebase.firestore.model.mutation.DeleteMutation)3 NonNull (androidx.annotation.NonNull)1 Query (com.google.firebase.firestore.core.Query)1 Document (com.google.firebase.firestore.model.Document)1 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 MutableDocument (com.google.firebase.firestore.model.MutableDocument)1 FieldTransform (com.google.firebase.firestore.model.mutation.FieldTransform)1 PatchMutation (com.google.firebase.firestore.model.mutation.PatchMutation)1 Precondition (com.google.firebase.firestore.model.mutation.Precondition)1 SetMutation (com.google.firebase.firestore.model.mutation.SetMutation)1 VerifyMutation (com.google.firebase.firestore.model.mutation.VerifyMutation)1 DocumentTransform (com.google.firestore.v1.DocumentTransform)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1