Skip to content

Commit 80ba9cc

Browse files
schmidt-sebastiankolea2
authored andcommitted
---
yaml --- r: 32759 b: refs/heads/autosynth-iot c: 7f6dc84 h: refs/heads/master i: 32757: f231ce9 32755: 7cd9967 32751: 740f58e
1 parent adf9123 commit 80ba9cc

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
@@ -131,7 +131,7 @@ refs/heads/autosynth-datastore: f1efc3dc465174f41041acd56cf29badcec3e5bd
131131
refs/heads/autosynth-dialogflow: 73974cc32e5212aec0126472e0bc1442886fedaf
132132
refs/heads/autosynth-errorreporting: effe8001d110ad584187b30aafc473db0dd4a15f
133133
refs/heads/autosynth-firestore: e79eeb26930dfae4439424ad2fda5874eeca54c8
134-
refs/heads/autosynth-iot: 860fe58a81bfd0290844f5c0438ac78f0b2f8ace
134+
refs/heads/autosynth-iot: 7f6dc8461448cf45aa5232abcd7410a8718b4f8d
135135
refs/heads/autosynth-kms: 6b65b0f34c12d141031c7288cdc01e550212d0f6
136136
refs/heads/autosynth-language: e73905aa7672afa47240e65b25c087207f4594f9
137137
refs/heads/autosynth-os-login: 123ba209c5769d0ee067e0ce5848bec13b42a4f4

branches/autosynth-iot/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-iot/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-iot/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)