From 3bd620be870bc764d7feafabbb91676956a0511e Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 2 Oct 2018 12:15:30 -0700 Subject: [PATCH] Deprecate getCollections in favor of listCollections --- .../google/cloud/firestore/DocumentReference.java | 14 +++++++++++++- .../java/com/google/cloud/firestore/Firestore.java | 11 +++++++++++ .../com/google/cloud/firestore/FirestoreImpl.java | 10 ++++++++-- .../google/cloud/firestore/it/ITSystemTest.java | 4 ++-- 4 files changed, 34 insertions(+), 5 deletions(-) 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) {