use of com.google.firebase.firestore.core.UserData.ParsedSetData in project firebase-android-sdk by firebase.
the class WriteBatch method set.
/**
* Writes to the document referred to by the provided {@code DocumentReference}. If the document
* does not yet exist, it will be created. If you pass {@code SetOptions}, the provided data can
* be merged into an existing document.
*
* @param documentRef The {@code DocumentReference} to overwrite.
* @param data The data to write to the document (e.g. a Map or a POJO containing the desired
* document contents).
* @param options An object to configure the set behavior.
* @return This {@code WriteBatch} instance. Used for chaining method calls.
*/
@NonNull
public WriteBatch set(@NonNull DocumentReference documentRef, @NonNull Object data, @NonNull SetOptions options) {
firestore.validateReference(documentRef);
checkNotNull(data, "Provided data must not be null.");
checkNotNull(options, "Provided options must not be null.");
verifyNotCommitted();
ParsedSetData parsed = options.isMerge() ? firestore.getUserDataReader().parseMergeData(data, options.getFieldMask()) : firestore.getUserDataReader().parseSetData(data);
mutations.add(parsed.toMutation(documentRef.getKey(), Precondition.NONE));
return this;
}
use of com.google.firebase.firestore.core.UserData.ParsedSetData in project firebase-android-sdk by firebase.
the class DocumentReference method set.
/**
* Writes to the document referred to by this {@code DocumentReference}. If the document does not
* yet exist, it will be created. If you pass {@code SetOptions}, the provided data can be merged
* into an existing document.
*
* @param data The data to write to the document (e.g. a Map or a POJO containing the desired
* document contents).
* @param options An object to configure the set behavior.
* @return A Task that will be resolved when the write finishes.
*/
@NonNull
public Task<Void> set(@NonNull Object data, @NonNull SetOptions options) {
checkNotNull(data, "Provided data must not be null.");
checkNotNull(options, "Provided options must not be null.");
ParsedSetData parsed = options.isMerge() ? firestore.getUserDataReader().parseMergeData(data, options.getFieldMask()) : firestore.getUserDataReader().parseSetData(data);
return firestore.getClient().write(Collections.singletonList(parsed.toMutation(key, Precondition.NONE))).continueWith(Executors.DIRECT_EXECUTOR, voidErrorTransformer());
}
use of com.google.firebase.firestore.core.UserData.ParsedSetData in project firebase-android-sdk by firebase.
the class Transaction method set.
/**
* Writes to the document referred to by the provided DocumentReference. If the document does not
* yet exist, it will be created. If you pass {@code SetOptions}, the provided data can be merged
* into an existing document.
*
* @param documentRef The {@code DocumentReference} to overwrite.
* @param data The data to write to the document (e.g. a Map or a POJO containing the desired
* document contents).
* @param options An object to configure the set behavior.
* @return This {@code Transaction} instance. Used for chaining method calls.
*/
@NonNull
public Transaction set(@NonNull DocumentReference documentRef, @NonNull Object data, @NonNull SetOptions options) {
firestore.validateReference(documentRef);
checkNotNull(data, "Provided data must not be null.");
checkNotNull(options, "Provided options must not be null.");
ParsedSetData parsed = options.isMerge() ? firestore.getUserDataReader().parseMergeData(data, options.getFieldMask()) : firestore.getUserDataReader().parseSetData(data);
transaction.set(documentRef.getKey(), parsed);
return this;
}
use of com.google.firebase.firestore.core.UserData.ParsedSetData in project firebase-android-sdk by firebase.
the class TestUtil method setMutation.
public static SetMutation setMutation(String path, Map<String, Object> values) {
UserDataReader dataReader = new UserDataReader(DatabaseId.forProject("project"));
ParsedSetData parsed = dataReader.parseSetData(values);
// The order of the transforms doesn't matter, but we sort them so tests can assume a particular
// order.
ArrayList<FieldTransform> fieldTransforms = new ArrayList<>(parsed.getFieldTransforms());
Collections.sort(fieldTransforms, (ft1, ft2) -> ft1.getFieldPath().compareTo(ft2.getFieldPath()));
return new SetMutation(key(path), parsed.getData(), Precondition.NONE, fieldTransforms);
}
Aggregations