Skip to content

Commit

Permalink
Deprecate getCollections in favor of listCollections (googleapis#3758)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Oct 4, 2018
1 parent 7f74c5a commit f69710d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public ApiFuture<DocumentSnapshot> get() {
* @throws FirestoreException if the Iterable could not be initialized.
* @return An Iterable that can be used to fetch all subcollections.
*/
public Iterable<CollectionReference> getCollections() {
public Iterable<CollectionReference> listCollections() {
ListCollectionIdsRequest.Builder request = ListCollectionIdsRequest.newBuilder();
request.setParent(path.toString());
final ListCollectionIdsPagedResponse response;
Expand Down Expand Up @@ -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<CollectionReference> getCollections() {
return listCollections();
}

/**
* Starts listening to the document referenced by this DocumentReference.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public interface Firestore extends Service<FirestoreOptions>, AutoCloseable {
* @return An Iterable that can be used to fetch all collections.
*/
@Nonnull
Iterable<CollectionReference> 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<CollectionReference> getCollections();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,15 @@ public DocumentReference document(@Nonnull String documentPath) {

@Nonnull
@Override
public Iterable<CollectionReference> getCollections() {
public Iterable<CollectionReference> listCollections() {
DocumentReference rootDocument = new DocumentReference(this, this.databasePath);
return rootDocument.getCollections();
return rootDocument.listCollections();
}

@Nonnull
@Override
public Iterable<CollectionReference> getCollections() {
return listCollections();
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -568,7 +568,7 @@ public void getCollections() throws Exception {
}
batch.commit().get();

Iterable<CollectionReference> collectionRefs = randomDoc.getCollections();
Iterable<CollectionReference> collectionRefs = randomDoc.listCollections();

int count = 0;
for (CollectionReference collectionRef : collectionRefs) {
Expand Down

0 comments on commit f69710d

Please sign in to comment.