Skip to content

Commit

Permalink
feat: Release bundles (#466)
Browse files Browse the repository at this point in the history
* feat: Release bundles
  • Loading branch information
wu-hui committed Dec 2, 2020
1 parent 767f995 commit 3af065e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
12 changes: 12 additions & 0 deletions google-cloud-firestore/clirr-ignored-differences.xml
Expand Up @@ -18,6 +18,18 @@
<!-- see http://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
<differences>

<!-- v2.1.1 -->
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/firestore/Firestore</className>
<method>com.google.cloud.firestore.FirestoreBundle$Builder bundleBuilder()</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/firestore/Firestore</className>
<method>com.google.cloud.firestore.FirestoreBundle$Builder bundleBuilder(java.lang.String)</method>
</difference>

<!-- v2.0.0 -->
<difference>
<differenceType>7002</differenceType>
Expand Down
Expand Up @@ -168,6 +168,24 @@ void getAll(
@Nonnull
WriteBatch batch();

/**
* Returns a FirestoreBundle.Builder {@link FirestoreBundle.Builder} instance using an
* automatically generated bundle ID. When loaded on clients, client SDKs use the bundle ID and
* the timestamp associated with the built bundle to tell if it has been loaded already.
*/
@Nonnull
FirestoreBundle.Builder bundleBuilder();

/**
* Returns a FirestoreBundle.Builder {@link FirestoreBundle.Builder} instance for the given bundle
* ID.
*
* @param bundleId The ID of the bundle. When loaded on clients, client SDKs use this id and the
* timestamp associated with the built bundle to tell if it has been loaded already.
*/
@Nonnull
FirestoreBundle.Builder bundleBuilder(@Nonnull String bundleId);

/**
* Closes the gRPC channels associated with this instance and frees up their resources. This
* method blocks until all channels are closed. Once this method is called, this Firestore client
Expand Down
Expand Up @@ -54,12 +54,17 @@ public static final class Builder {
// The latest read time among all bundled documents and queries.
private Timestamp latestReadTime = Timestamp.MIN_VALUE;

public Builder(String id) {
Builder(String id) {
this.id = id;
}

/** Returns the ID for this bundle. */
public String getId() {
return this.id;
}

/**
* Adds a Firestore document snapshot to the bundle. Both the documents data and the document
* Adds a Firestore document snapshot to the bundle. Both the document data and the document
* read time will be included in the bundle.
*
* @param documentSnapshot A document snapshot to add.
Expand Down Expand Up @@ -121,7 +126,7 @@ private Builder add(DocumentSnapshot documentSnapshot, Optional<String> queryNam
}

/**
* Adds a Firestore query snapshots to the bundle. Both the documents in the query snapshots and
* Adds a Firestore query snapshot to the bundle. Both the documents in the query snapshot and
* the query read time will be included in the bundle.
*
* @param queryName The name of the query to add.
Expand Down
Expand Up @@ -321,6 +321,19 @@ public <T> ApiFuture<T> runAsyncTransaction(
return transactionRunner.run();
}

@Nonnull
@Override
public FirestoreBundle.Builder bundleBuilder() {
return bundleBuilder(null);
}

@Nonnull
@Override
public FirestoreBundle.Builder bundleBuilder(@Nullable String bundleId) {
String id = bundleId == null ? autoId() : bundleId;
return new FirestoreBundle.Builder(id);
}

/** Returns the name of the Firestore project associated with this client. */
@Override
public String getDatabaseName() {
Expand Down
Expand Up @@ -1566,7 +1566,7 @@ public ApiFuture<List<T>> consume() {

@Test
public void testBuildingBundleWhenDocumentDoesNotExist() throws Exception {
FirestoreBundle.Builder bundleBuilder = new FirestoreBundle.Builder("test-bundle");
FirestoreBundle.Builder bundleBuilder = firestore.bundleBuilder("test-bundle");
DocumentSnapshot snapshot = randomDoc.get().get();
bundleBuilder.add(snapshot);

Expand Down Expand Up @@ -1595,7 +1595,7 @@ public void testBuildingBundleWithLimitQuery() throws Exception {

Query limitQuery = randomColl.orderBy("counter", Direction.DESCENDING).limit(1);
QuerySnapshot limitQuerySnap = limitQuery.get().get();
FirestoreBundle.Builder bundleBuilder = new FirestoreBundle.Builder("test-bundle");
FirestoreBundle.Builder bundleBuilder = firestore.bundleBuilder("test-bundle");
bundleBuilder.add("limit", limitQuerySnap);

// Expected bundle elements are [bundleMetadata, limitQuery,
Expand Down Expand Up @@ -1630,7 +1630,7 @@ public void testBuildingBundleWithLimitToLastQuery() throws Exception {

Query limitToLastQuery = randomColl.orderBy("counter").limitToLast(1);
QuerySnapshot limitToLastQuerySnap = limitToLastQuery.get().get();
FirestoreBundle.Builder bundleBuilder = new FirestoreBundle.Builder("test-bundle");
FirestoreBundle.Builder bundleBuilder = firestore.bundleBuilder("test-bundle");
bundleBuilder.add("limitToLast", limitToLastQuerySnap);

// Expected bundle elements are [bundleMetadata, limitToLastQuery,
Expand Down

0 comments on commit 3af065e

Please sign in to comment.