use of com.google.firebase.firestore.FieldValue.ServerTimestampFieldValue in project firebase-android-sdk by firebase.
the class UserDataReader method parseSentinelFieldValue.
/**
* "Parses" the provided FieldValue, adding any necessary transforms to context.fieldTransforms.
*/
private void parseSentinelFieldValue(com.google.firebase.firestore.FieldValue value, ParseContext context) {
// Sentinels are only supported with writes, and not within arrays.
if (!context.isWrite()) {
throw context.createError(String.format("%s() can only be used with set() and update()", value.getMethodName()));
}
if (context.getPath() == null) {
throw context.createError(String.format("%s() is not currently supported inside arrays", value.getMethodName()));
}
if (value instanceof DeleteFieldValue) {
if (context.getDataSource() == UserData.Source.MergeSet) {
// No transform to add for a delete, but we need to add it to our
// fieldMask so it gets deleted.
context.addToFieldMask(context.getPath());
} else if (context.getDataSource() == UserData.Source.Update) {
hardAssert(context.getPath().length() > 0, "FieldValue.delete() at the top level should have already been handled.");
throw context.createError("FieldValue.delete() can only appear at the top level of your update data");
} else {
// We shouldn't encounter delete sentinels for queries or non-merge set() calls.
throw context.createError("FieldValue.delete() can only be used with update() and " + "set() with SetOptions.merge()");
}
} else if (value instanceof ServerTimestampFieldValue) {
context.addToFieldTransforms(context.getPath(), ServerTimestampOperation.getInstance());
} else if (value instanceof ArrayUnionFieldValue) {
List<Value> parsedElements = parseArrayTransformElements(((ArrayUnionFieldValue) value).getElements());
ArrayTransformOperation arrayUnion = new ArrayTransformOperation.Union(parsedElements);
context.addToFieldTransforms(context.getPath(), arrayUnion);
} else if (value instanceof ArrayRemoveFieldValue) {
List<Value> parsedElements = parseArrayTransformElements(((ArrayRemoveFieldValue) value).getElements());
ArrayTransformOperation arrayRemove = new ArrayTransformOperation.Remove(parsedElements);
context.addToFieldTransforms(context.getPath(), arrayRemove);
} else if (value instanceof com.google.firebase.firestore.FieldValue.NumericIncrementFieldValue) {
com.google.firebase.firestore.FieldValue.NumericIncrementFieldValue numericIncrementFieldValue = (com.google.firebase.firestore.FieldValue.NumericIncrementFieldValue) value;
Value operand = parseQueryValue(numericIncrementFieldValue.getOperand());
NumericIncrementTransformOperation incrementOperation = new NumericIncrementTransformOperation(operand);
context.addToFieldTransforms(context.getPath(), incrementOperation);
} else {
throw Assert.fail("Unknown FieldValue type: %s", Util.typeName(value));
}
}
Aggregations