use of com.google.firebase.firestore.model.mutation.VerifyMutation 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.VerifyMutation in project firebase-android-sdk by firebase.
the class Transaction method commit.
public Task<Void> commit() {
ensureCommitNotCalled();
if (lastWriteError != null) {
return Tasks.forException(lastWriteError);
}
HashSet<DocumentKey> unwritten = new HashSet<>(readVersions.keySet());
// For each mutation, note that the doc was written.
for (Mutation mutation : mutations) {
unwritten.remove(mutation.getKey());
}
// For each document that was read but not written to, we want to perform a `verify` operation.
for (DocumentKey key : unwritten) {
mutations.add(new VerifyMutation(key, precondition(key)));
}
committed = true;
return datastore.commit(mutations).continueWithTask(Executors.DIRECT_EXECUTOR, task -> {
if (task.isSuccessful()) {
return Tasks.forResult(null);
} else {
return Tasks.forException(task.getException());
}
});
}
Aggregations