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());
}
}
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;
}
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);
}
Aggregations