Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@ public boolean exists() {
return fields != null;
}

/** Checks whether this DocumentSnapshot contains any fields. */
boolean isEmpty() {
return fields == null || fields.isEmpty();
}

/**
* Returns the fields of the document as a Map or null if the document doesn't exist. Field values
* will be converted to their native Java representation.
Expand Down Expand Up @@ -428,6 +423,15 @@ public DocumentReference getReference() {
return docRef;
}

/** Checks whether this DocumentSnapshot contains any fields. */
boolean isEmpty() {
return fields == null || fields.isEmpty();
}

Map<String, Value> getProtoFields() {
return fields;
}

Write.Builder toPb() {
Preconditions.checkState(exists(), "Can't call toDocument() on a document that doesn't exist");
Write.Builder write = Write.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.firestore;

import static com.google.cloud.firestore.UserDataConverter.NO_DELETES;

import com.google.api.core.InternalApi;
import com.google.cloud.Timestamp;
import com.google.common.base.Preconditions;
import com.google.firestore.v1.Document;
import com.google.firestore.v1.Value;
import java.util.Map;

@InternalApi
public class Internal {
private FirestoreImpl firestore;

@InternalApi
public Internal(FirestoreImpl firestore) {
this.firestore = firestore;
}

@InternalApi
public DocumentSnapshot snapshotFromObject(String documentPath, Object pojo) {
DocumentReference documentReference = firestore.document(documentPath);
Object data = CustomClassMapper.convertToPlainJavaTypes(pojo);
Preconditions.checkArgument(
data instanceof Map, "Can't create a document from an array or primitive");
return DocumentSnapshot.fromObject(
firestore, documentReference, (Map<String, Object>) data, NO_DELETES);
}

@InternalApi
public DocumentSnapshot snapshotFromMap(String documentPath, Map<String, Object> data) {
DocumentReference documentReference = firestore.document(documentPath);
return DocumentSnapshot.fromObject(firestore, documentReference, data, NO_DELETES);
}

@InternalApi
public DocumentSnapshot snapshotFromProto(Timestamp readTime, Document document) {
return DocumentSnapshot.fromDocument(firestore, readTime, document);
}

@InternalApi
public Map<String, Value> protoFromSnapshot(DocumentSnapshot snapshot) {
return snapshot.getProtoFields();
}
}