Skip to content

Commit 3af065e

Browse files
authored
feat: Release bundles (#466)
* feat: Release bundles
1 parent 767f995 commit 3af065e

5 files changed

Lines changed: 54 additions & 6 deletions

File tree

google-cloud-firestore/clirr-ignored-differences.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
<!-- see http://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
1919
<differences>
2020

21+
<!-- v2.1.1 -->
22+
<difference>
23+
<differenceType>7012</differenceType>
24+
<className>com/google/cloud/firestore/Firestore</className>
25+
<method>com.google.cloud.firestore.FirestoreBundle$Builder bundleBuilder()</method>
26+
</difference>
27+
<difference>
28+
<differenceType>7012</differenceType>
29+
<className>com/google/cloud/firestore/Firestore</className>
30+
<method>com.google.cloud.firestore.FirestoreBundle$Builder bundleBuilder(java.lang.String)</method>
31+
</difference>
32+
2133
<!-- v2.0.0 -->
2234
<difference>
2335
<differenceType>7002</differenceType>

google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ void getAll(
168168
@Nonnull
169169
WriteBatch batch();
170170

171+
/**
172+
* Returns a FirestoreBundle.Builder {@link FirestoreBundle.Builder} instance using an
173+
* automatically generated bundle ID. When loaded on clients, client SDKs use the bundle ID and
174+
* the timestamp associated with the built bundle to tell if it has been loaded already.
175+
*/
176+
@Nonnull
177+
FirestoreBundle.Builder bundleBuilder();
178+
179+
/**
180+
* Returns a FirestoreBundle.Builder {@link FirestoreBundle.Builder} instance for the given bundle
181+
* ID.
182+
*
183+
* @param bundleId The ID of the bundle. When loaded on clients, client SDKs use this id and the
184+
* timestamp associated with the built bundle to tell if it has been loaded already.
185+
*/
186+
@Nonnull
187+
FirestoreBundle.Builder bundleBuilder(@Nonnull String bundleId);
188+
171189
/**
172190
* Closes the gRPC channels associated with this instance and frees up their resources. This
173191
* method blocks until all channels are closed. Once this method is called, this Firestore client

google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreBundle.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ public static final class Builder {
5454
// The latest read time among all bundled documents and queries.
5555
private Timestamp latestReadTime = Timestamp.MIN_VALUE;
5656

57-
public Builder(String id) {
57+
Builder(String id) {
5858
this.id = id;
5959
}
6060

61+
/** Returns the ID for this bundle. */
62+
public String getId() {
63+
return this.id;
64+
}
65+
6166
/**
62-
* Adds a Firestore document snapshot to the bundle. Both the documents data and the document
67+
* Adds a Firestore document snapshot to the bundle. Both the document data and the document
6368
* read time will be included in the bundle.
6469
*
6570
* @param documentSnapshot A document snapshot to add.
@@ -121,7 +126,7 @@ private Builder add(DocumentSnapshot documentSnapshot, Optional<String> queryNam
121126
}
122127

123128
/**
124-
* Adds a Firestore query snapshots to the bundle. Both the documents in the query snapshots and
129+
* Adds a Firestore query snapshot to the bundle. Both the documents in the query snapshot and
125130
* the query read time will be included in the bundle.
126131
*
127132
* @param queryName The name of the query to add.

google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,19 @@ public <T> ApiFuture<T> runAsyncTransaction(
321321
return transactionRunner.run();
322322
}
323323

324+
@Nonnull
325+
@Override
326+
public FirestoreBundle.Builder bundleBuilder() {
327+
return bundleBuilder(null);
328+
}
329+
330+
@Nonnull
331+
@Override
332+
public FirestoreBundle.Builder bundleBuilder(@Nullable String bundleId) {
333+
String id = bundleId == null ? autoId() : bundleId;
334+
return new FirestoreBundle.Builder(id);
335+
}
336+
324337
/** Returns the name of the Firestore project associated with this client. */
325338
@Override
326339
public String getDatabaseName() {

google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ public ApiFuture<List<T>> consume() {
15661566

15671567
@Test
15681568
public void testBuildingBundleWhenDocumentDoesNotExist() throws Exception {
1569-
FirestoreBundle.Builder bundleBuilder = new FirestoreBundle.Builder("test-bundle");
1569+
FirestoreBundle.Builder bundleBuilder = firestore.bundleBuilder("test-bundle");
15701570
DocumentSnapshot snapshot = randomDoc.get().get();
15711571
bundleBuilder.add(snapshot);
15721572

@@ -1595,7 +1595,7 @@ public void testBuildingBundleWithLimitQuery() throws Exception {
15951595

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

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

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

16361636
// Expected bundle elements are [bundleMetadata, limitToLastQuery,

0 commit comments

Comments
 (0)