Skip to content

Commit ce06f00

Browse files
schmidt-sebastiankolea2
authored andcommitted
---
yaml --- r: 34903 b: refs/heads/autosynth-trace c: 7f6dc84 h: refs/heads/master i: 34901: 8b6ffe5 34899: c0d073c 34895: fe98193
1 parent 864e915 commit ce06f00

10 files changed

Lines changed: 456 additions & 218 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ refs/heads/autosynth-spanner: d963fe4368e79cf6abae5d511785e8ced8ac57f4
141141
refs/heads/autosynth-speech: c563dcd420cce0a37c39b1b9c24be1b9ba604dc7
142142
refs/heads/autosynth-tasks: 25d1eafe8cb66b00e3dad765dac74a5b45b83e63
143143
refs/heads/autosynth-texttospeech: 7a3ad430dddaed7a76f2026064502680c9339915
144-
refs/heads/autosynth-trace: 860fe58a81bfd0290844f5c0438ac78f0b2f8ace
144+
refs/heads/autosynth-trace: 7f6dc8461448cf45aa5232abcd7410a8718b4f8d
145145
refs/heads/autosynth-websecurityscanner: fa561b356aabcd92d415ae8dc88fd8d87dbc5b23
146146
refs/heads/bigquerystorage: 06db74d123d7f8a3ef48755c2fcabed09faf8e64
147147
refs/heads/elharo-patch-1: ce159ef828d3c545991ff78e7b6e0d912a9453e9

branches/autosynth-trace/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionReference.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class CollectionReference extends Query {
5959
*/
6060
@Nonnull
6161
public String getId() {
62-
return path.getId();
62+
return options.getCollectionId();
6363
}
6464

6565
/**
@@ -69,7 +69,7 @@ public String getId() {
6969
*/
7070
@Nullable
7171
public DocumentReference getParent() {
72-
ResourcePath parent = path.getParent();
72+
ResourcePath parent = options.getParentPath();
7373
return parent.isDocument() ? new DocumentReference(firestore, parent) : null;
7474
}
7575

@@ -81,7 +81,7 @@ public DocumentReference getParent() {
8181
*/
8282
@Nonnull
8383
public String getPath() {
84-
return path.getPath();
84+
return getResourcePath().getPath();
8585
}
8686

8787
/**
@@ -104,10 +104,10 @@ public DocumentReference document() {
104104
*/
105105
@Nonnull
106106
public DocumentReference document(@Nonnull String childPath) {
107-
ResourcePath documentPath = path.append(childPath);
107+
ResourcePath documentPath = getResourcePath().append(childPath);
108108
Preconditions.checkArgument(
109109
documentPath.isDocument(),
110-
String.format("Path should point to a Document Reference: %s", path));
110+
String.format("Path should point to a Document Reference: %s", getPath()));
111111
return new DocumentReference(firestore, documentPath);
112112
}
113113

@@ -124,8 +124,8 @@ public DocumentReference document(@Nonnull String childPath) {
124124
@Nonnull
125125
public Iterable<DocumentReference> listDocuments() {
126126
ListDocumentsRequest.Builder request = ListDocumentsRequest.newBuilder();
127-
request.setParent(path.getParent().toString());
128-
request.setCollectionId(this.getId());
127+
request.setParent(options.getParentPath().toString());
128+
request.setCollectionId(options.getCollectionId());
129129
request.setMask(DocumentMask.getDefaultInstance());
130130
request.setShowMissing(true);
131131

@@ -206,4 +206,9 @@ public ApiFuture<DocumentReference> add(Object pojo) {
206206
}
207207
return add((Map<String, Object>) converted);
208208
}
209+
210+
/** Returns a resource path pointing to this collection. */
211+
ResourcePath getResourcePath() {
212+
return options.getParentPath().append(options.getCollectionId());
213+
}
209214
}

branches/autosynth-trace/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ public interface Firestore extends Service<FirestoreOptions>, AutoCloseable {
6262
@Nonnull
6363
Iterable<CollectionReference> getCollections();
6464

65+
/**
66+
* Creates and returns a new @link{Query} that includes all documents in the database that are
67+
* contained in a collection or subcollection with the given @code{collectionId}.
68+
*
69+
* @param collectionId Identifies the collections to query over. Every collection or subcollection
70+
* with this ID as the last segment of its path will be included. Cannot contain a slash.
71+
* @return The created Query.
72+
*/
73+
Query collectionGroup(@Nonnull String collectionId);
74+
6575
/**
6676
* Executes the given updateFunction and then attempts to commit the changes applied within the
6777
* transaction. If any document read within the transaction has changed, the updateFunction will

branches/autosynth-trace/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ public WriteBatch batch() {
106106
@Nonnull
107107
@Override
108108
public CollectionReference collection(@Nonnull String collectionPath) {
109-
return new CollectionReference(this, databasePath.append(collectionPath));
109+
ResourcePath path = databasePath.append(collectionPath);
110+
Preconditions.checkArgument(
111+
path.isCollection(), "Invalid path specified. Path should point to a collection");
112+
return new CollectionReference(this, path);
110113
}
111114

112115
@Nonnull
@@ -244,6 +247,16 @@ public void onCompleted() {
244247
return futureList;
245248
}
246249

250+
@Nonnull
251+
@Override
252+
public Query collectionGroup(@Nonnull final String collectionId) {
253+
Preconditions.checkArgument(
254+
!collectionId.contains("/"),
255+
String.format(
256+
"Invalid collectionId '%s'. Collection IDs must not contain '/'.", collectionId));
257+
return new Query(this, collectionId);
258+
}
259+
247260
@Nonnull
248261
@Override
249262
public <T> ApiFuture<T> runTransaction(@Nonnull final Transaction.Function<T> updateFunction) {
@@ -401,6 +414,11 @@ String getDatabaseName() {
401414
return databasePath.getDatabaseName().toString();
402415
}
403416

417+
/** Returns a path to the Firestore project associated with this client. */
418+
ResourcePath getResourcePath() {
419+
return databasePath;
420+
}
421+
404422
/** Returns the underlying RPC client. */
405423
FirestoreRpc getClient() {
406424
return firestoreClient;

0 commit comments

Comments
 (0)