Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Release bundles #466

Merged
merged 7 commits into from Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 124-129 below, for add() doc, remove plural so "Adds a Firestore query snapshot to..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

*
* @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