diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java index 2da052d40b1e..d1270e52a84a 100644 --- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java +++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java @@ -358,7 +358,7 @@ public ApiFuture get() { * @throws FirestoreException if the Iterable could not be initialized. * @return An Iterable that can be used to fetch all subcollections. */ - public Iterable getCollections() { + public Iterable listCollections() { ListCollectionIdsRequest.Builder request = ListCollectionIdsRequest.newBuilder(); request.setParent(path.toString()); final ListCollectionIdsPagedResponse response; @@ -397,6 +397,18 @@ public void remove() { }; } + /** + * Fetches the subcollections that are direct children of this document. + * + * @deprecated Use `listCollections()`. + * + * @throws FirestoreException if the Iterable could not be initialized. + * @return An Iterable that can be used to fetch all subcollections. + */ + public Iterable getCollections() { + return listCollections(); + } + /** * Starts listening to the document referenced by this DocumentReference. * diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java index 49ae9b1aaa4c..261678b6c932 100644 --- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java +++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java @@ -49,6 +49,17 @@ public interface Firestore extends Service, AutoCloseable { * @return An Iterable that can be used to fetch all collections. */ @Nonnull + Iterable listCollections(); + + /** + * Fetches the root collections that are associated with this Firestore database. + * + * @deprecated Use `listCollections()`. + * + * @throws FirestoreException if the Iterable could not be initialized. + * @return An Iterable that can be used to fetch all collections. + */ + @Nonnull Iterable getCollections(); /** diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index 5301f117f1a9..dbabafa9ff25 100644 --- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -149,9 +149,15 @@ public DocumentReference document(@Nonnull String documentPath) { @Nonnull @Override - public Iterable getCollections() { + public Iterable listCollections() { DocumentReference rootDocument = new DocumentReference(this, this.databasePath); - return rootDocument.getCollections(); + return rootDocument.listCollections(); + } + + @Nonnull + @Override + public Iterable getCollections() { + return listCollections(); } @Nonnull diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java index 55306fd8864d..c072ea50c0e3 100644 --- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java +++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java @@ -552,7 +552,7 @@ public void omitWriteResultForDocumentTransforms() } @Test - public void getCollections() throws Exception { + public void listCollections() throws Exception { // We test with 21 collections since 20 collections are by default returned in a single paged // response. String[] collections = @@ -568,7 +568,7 @@ public void getCollections() throws Exception { } batch.commit().get(); - Iterable collectionRefs = randomDoc.getCollections(); + Iterable collectionRefs = randomDoc.listCollections(); int count = 0; for (CollectionReference collectionRef : collectionRefs) {