-
Notifications
You must be signed in to change notification settings - Fork 615
Tomandersen/transaction options #3664
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
246a067
- Changes to protoc version to make it working for m1 macs.
eldhosembabu f7873ee
- Changes to protoc version to make it working for m1 macs.
eldhosembabu 5a31b19
- Changes to dependency versions to make it working for m1 macs.
eldhosembabu 1208d9d
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu 97518d5
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu b8a85ef
- Reverting the robolectric version change
eldhosembabu 80da16e
Revert "- Changes to dependency versions to make it working for m1 ma…
eldhosembabu cca600e
- Updating robolectric versions to 4.7+ to get support for m1 macs.
eldhosembabu 090773a
Reverting some changes to check
eldhosembabu 73dd784
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu 09e9664
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu 61c4819
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu fcb9e05
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu c3132b1
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu 3191148
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu c64e321
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu 1fc153b
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu e70532f
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu b155fe7
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
eldhosembabu 5119f6b
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
tom-andersen 5c5dcdb
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
tom-andersen af391ae
Merge remote-tracking branch 'origin/master' into m1-mac-fixes
tom-andersen a93bfce
Add TransactionOptions to allow control over number of attempts to co…
tom-andersen 167632b
Add TransactionOptions to allow control over number of attempts to co…
tom-andersen c6d0361
Merge remote-tracking branch 'origin/tomandersen/transactionOptions' …
tom-andersen 2857711
Add missing @NonNull annotation
tom-andersen bee89f6
Fix comments and add api.txt change.
tom-andersen bfe8641
Update CHANGELOG with TransactionOptions
tom-andersen 1d62d46
Improve method comments for TransactionOptions.
tom-andersen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
firebase-firestore/src/main/java/com/google/firebase/firestore/TransactionOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.firestore; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
/** | ||
* Parameter for {@link FirebaseFirestore#runTransaction(TransactionOptions, Transaction.Function)}. | ||
tom-andersen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public final class TransactionOptions { | ||
|
||
static final TransactionOptions DEFAULT = new TransactionOptions.Builder().build(); | ||
static final int DEFAULT_MAX_ATTEMPTS_COUNT = 5; | ||
|
||
private final int maxAttempts; | ||
|
||
private TransactionOptions(int maxAttempts) { | ||
this.maxAttempts = maxAttempts; | ||
} | ||
|
||
/** A Builder for creating {@code TransactionOptions}. */ | ||
public static final class Builder { | ||
private int maxAttempts = DEFAULT_MAX_ATTEMPTS_COUNT; | ||
|
||
/** Constructs a new {@code TransactionOptions} Builder object. */ | ||
public Builder() {} | ||
|
||
/** | ||
* Constructs a new {@code TransactionOptions} Builder based on an existing {@code | ||
* TransactionOptions} object. | ||
*/ | ||
public Builder(@NonNull TransactionOptions options) { | ||
maxAttempts = options.maxAttempts; | ||
} | ||
|
||
/** | ||
* Set maximum number of attempts to commit, after which transaction fails. Default is 5. | ||
* | ||
tom-andersen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @return this builder | ||
tom-andersen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
@NonNull | ||
public Builder setMaxAttempts(int maxAttempts) { | ||
if (maxAttempts < 1) throw new IllegalArgumentException("Max attempts must be at least 1"); | ||
this.maxAttempts = maxAttempts; | ||
return this; | ||
} | ||
|
||
/** | ||
* Build the {@code TransactionOptions} object. | ||
* | ||
* @return the built {@code TransactionOptions} object | ||
tom-andersen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
@NonNull | ||
public TransactionOptions build() { | ||
return new TransactionOptions(maxAttempts); | ||
} | ||
} | ||
|
||
/** | ||
* Get maximum number of attempts to commit, after which transaction fails. Default is 5. | ||
* | ||
* @return maximum number of attempts | ||
tom-andersen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public int getMaxAttempts() { | ||
return maxAttempts; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
TransactionOptions that = (TransactionOptions) o; | ||
|
||
return maxAttempts == that.maxAttempts; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return maxAttempts; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TransactionOptions{" + "maxAttempts=" + maxAttempts + '}'; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.