97 lines
3.9 KiB
Java
97 lines
3.9 KiB
Java
|
package com.google.firebase.firestore;
|
||
|
|
||
|
import com.google.android.gms.tasks.Task;
|
||
|
import com.google.firebase.firestore.core.UserData;
|
||
|
import com.google.firebase.firestore.model.DocumentKey;
|
||
|
import com.google.firebase.firestore.model.ResourcePath;
|
||
|
import com.google.firebase.firestore.model.mutation.Precondition;
|
||
|
import com.google.firebase.firestore.util.Executors;
|
||
|
import com.google.firebase.firestore.util.Preconditions;
|
||
|
import com.google.firebase.firestore.util.Util;
|
||
|
import java.util.Collections;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public class DocumentReference {
|
||
|
private final FirebaseFirestore firestore;
|
||
|
private final DocumentKey key;
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public DocumentReference(DocumentKey documentKey, FirebaseFirestore firebaseFirestore) {
|
||
|
this.key = (DocumentKey) Preconditions.checkNotNull(documentKey);
|
||
|
this.firestore = firebaseFirestore;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public static DocumentReference forPath(ResourcePath resourcePath, FirebaseFirestore firebaseFirestore) {
|
||
|
if (resourcePath.length() % 2 != 0) {
|
||
|
StringBuilder sb = new StringBuilder("Invalid document reference. Document references must have an even number of segments, but ");
|
||
|
sb.append(resourcePath.canonicalString());
|
||
|
sb.append(" has ");
|
||
|
sb.append(resourcePath.length());
|
||
|
throw new IllegalArgumentException(sb.toString());
|
||
|
}
|
||
|
return new DocumentReference(DocumentKey.fromPath(resourcePath), firebaseFirestore);
|
||
|
}
|
||
|
|
||
|
public String getId() {
|
||
|
return this.key.getDocumentId();
|
||
|
}
|
||
|
|
||
|
public String getPath() {
|
||
|
return this.key.getPath().canonicalString();
|
||
|
}
|
||
|
|
||
|
public Task<Void> set(Object obj) {
|
||
|
return set(obj, SetOptions.OVERWRITE);
|
||
|
}
|
||
|
|
||
|
public Task<Void> set(Object obj, SetOptions setOptions) {
|
||
|
UserData.ParsedSetData parseSetData;
|
||
|
Preconditions.checkNotNull(obj, "Provided data must not be null.");
|
||
|
Preconditions.checkNotNull(setOptions, "Provided options must not be null.");
|
||
|
if (setOptions.isMerge()) {
|
||
|
parseSetData = this.firestore.getUserDataReader().parseMergeData(obj, setOptions.getFieldMask());
|
||
|
} else {
|
||
|
parseSetData = this.firestore.getUserDataReader().parseSetData(obj);
|
||
|
}
|
||
|
return this.firestore.getClient().write(Collections.singletonList(parseSetData.toMutation(this.key, Precondition.NONE))).continueWith(Executors.DIRECT_EXECUTOR, Util.voidErrorTransformer());
|
||
|
}
|
||
|
|
||
|
public Task<Void> update(Map<String, Object> map) {
|
||
|
return update(this.firestore.getUserDataReader().parseUpdateData(map));
|
||
|
}
|
||
|
|
||
|
public Task<Void> update(String str, Object obj, Object... objArr) {
|
||
|
return update(this.firestore.getUserDataReader().parseUpdateData(Util.collectUpdateArguments(1, str, obj, objArr)));
|
||
|
}
|
||
|
|
||
|
private Task<Void> update(UserData.ParsedUpdateData parsedUpdateData) {
|
||
|
return this.firestore.getClient().write(Collections.singletonList(parsedUpdateData.toMutation(this.key, Precondition.exists(true)))).continueWith(Executors.DIRECT_EXECUTOR, Util.voidErrorTransformer());
|
||
|
}
|
||
|
|
||
|
public boolean equals(Object obj) {
|
||
|
if (this == obj) {
|
||
|
return true;
|
||
|
}
|
||
|
if (!(obj instanceof DocumentReference)) {
|
||
|
return false;
|
||
|
}
|
||
|
DocumentReference documentReference = (DocumentReference) obj;
|
||
|
return this.key.equals(documentReference.key) && this.firestore.equals(documentReference.firestore);
|
||
|
}
|
||
|
|
||
|
public int hashCode() {
|
||
|
return (this.key.hashCode() * 31) + this.firestore.hashCode();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public DocumentKey getKey() {
|
||
|
return this.key;
|
||
|
}
|
||
|
|
||
|
public FirebaseFirestore getFirestore() {
|
||
|
return this.firestore;
|
||
|
}
|
||
|
}
|