Search in sources :

Example 1 with ParsedSetData

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;
}
Also used : ParsedSetData(com.google.firebase.firestore.core.UserData.ParsedSetData) NonNull(androidx.annotation.NonNull)

Example 2 with ParsedSetData

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());
}
Also used : ParsedSetData(com.google.firebase.firestore.core.UserData.ParsedSetData) NonNull(androidx.annotation.NonNull)

Example 3 with ParsedSetData

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;
}
Also used : ParsedSetData(com.google.firebase.firestore.core.UserData.ParsedSetData) NonNull(androidx.annotation.NonNull)

Example 4 with ParsedSetData

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);
}
Also used : UserDataReader(com.google.firebase.firestore.UserDataReader) ParsedSetData(com.google.firebase.firestore.core.UserData.ParsedSetData) FieldTransform(com.google.firebase.firestore.model.mutation.FieldTransform) ArrayList(java.util.ArrayList) SetMutation(com.google.firebase.firestore.model.mutation.SetMutation)

Aggregations

ParsedSetData (com.google.firebase.firestore.core.UserData.ParsedSetData)4 NonNull (androidx.annotation.NonNull)3 UserDataReader (com.google.firebase.firestore.UserDataReader)1 FieldTransform (com.google.firebase.firestore.model.mutation.FieldTransform)1 SetMutation (com.google.firebase.firestore.model.mutation.SetMutation)1 ArrayList (java.util.ArrayList)1