use of com.google.firestore.v1.DocumentTransform in project java-firestore by googleapis.
the class UpdateBuilder method performUpdate.
private T performUpdate(@Nonnull DocumentReference documentReference, @Nonnull final Map<FieldPath, Object> fields, @Nonnull Precondition precondition) {
verifyNotCommitted();
Preconditions.checkArgument(!fields.isEmpty(), "Data for update() cannot be empty.");
Tracing.getTracer().getCurrentSpan().addAnnotation(TraceUtil.SPAN_NAME_UPDATEDOCUMENT);
Map<String, Object> deconstructedMap = expandObject(fields);
DocumentSnapshot documentSnapshot = DocumentSnapshot.fromObject(firestore, documentReference, deconstructedMap, new EncodingOptions() {
@Override
public boolean allowDelete(FieldPath fieldPath) {
return fields.containsKey(fieldPath);
}
@Override
public boolean allowTransform() {
return true;
}
});
List<FieldPath> fieldPaths = new ArrayList<>(fields.keySet());
DocumentTransform documentTransform = DocumentTransform.fromFieldPathMap(documentReference, fields);
fieldPaths.removeAll(documentTransform.getFields());
FieldMask fieldMask = new FieldMask(fieldPaths);
Write.Builder write = documentSnapshot.toPb();
write.setCurrentDocument(precondition.toPb());
write.setUpdateMask(fieldMask.toPb());
if (!documentTransform.isEmpty()) {
write.addAllUpdateTransforms(documentTransform.toPb());
}
writes.add(new WriteOperation(documentReference, write));
return wrapResult(writes.size() - 1);
}
Aggregations