Package com.google.cloud.firestore
Class TransactionOptions
java.lang.Object
com.google.cloud.firestore.TransactionOptions
Options specifying the behavior of Firestore Transactions.
A transaction in Firestore can be either read-write or read-only.
The default set of options is a read-write transaction with a maximum number of 5 attempts.
This attempt count can be customized via the TransactionOptions.ReadWriteOptionsBuilder.setNumberOfAttempts(int) method. A new instance of a builder can be
created by calling createReadWriteOptionsBuilder().
A read-only transaction can be configured via the TransactionOptions.ReadOnlyOptionsBuilder class. A new
instance can be created by calling createReadOnlyOptionsBuilder().
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final classA typesafe builder class representing those options that are applicable when configuring a transaction to be read-only.static final classA typesafe builder class representing those options that are applicable when configuring a transaction to be read-write.static enum -
Method Summary
Modifier and TypeMethodDescriptionstatic TransactionOptionscreate()Create a default set of options suitable for most use cases.static TransactionOptionscreate(int numberOfAttempts) Deprecated.static TransactionOptionsDeprecated.as of 2.0.0, replaced byTransactionOptions.Builder.setExecutor(Executor)static TransactionOptionsDeprecated.as of 2.0.0, replaced byTransactionOptions.Builder.setExecutor(Executor)andTransactionOptions.ReadWriteOptionsBuilder.setNumberOfAttempts(int)intReturns the maximum number of times a transaction will be attempted before resulting in an error.com.google.protobuf.TimestampATimestampspecifying the time documents are to be read at.getType()A type flag indicating the type of transaction represented.
-
Method Details
-
getNumberOfAttempts
public int getNumberOfAttempts()Returns the maximum number of times a transaction will be attempted before resulting in an error.- Returns:
- The max number of attempts to try and commit the transaction.
-
getExecutor
- Returns:
- Executor to be used to run user callbacks on
-
getType
A type flag indicating the type of transaction represented.- Returns:
- The type of transaction this represents. Either read-only or read-write.
-
getReadTime
ATimestampspecifying the time documents are to be read at. If null, the server will read documents at the most up to date available. If non-null, the specifiedTimestampmay not be more than 60 minutes in the past (evaluated when the request is processed by the server).- Returns:
- The specific time to read documents at. A null value means reading the most up to date data.
-
create
Create a default set of options suitable for most use cases. Transactions will be opened as ReadWrite transactions and attempted up to 5 times.- Returns:
- The TransactionOptions object.
- See Also:
-
create
Deprecated.as of 2.0.0, replaced byTransactionOptions.ReadWriteOptionsBuilder.setNumberOfAttempts(int)Create a default set of options with a custom number of retry attempts.- Parameters:
numberOfAttempts- The number of execution attempts.- Returns:
- The TransactionOptions object.
- See Also:
-
create
Deprecated.as of 2.0.0, replaced byTransactionOptions.Builder.setExecutor(Executor)Create a default set of options with a custom executor.- Parameters:
executor- The executor to run the user callback code on.- Returns:
- The TransactionOptions object.
- See Also:
-
create
@Nonnull @Deprecated public static TransactionOptions create(@Nullable Executor executor, int numberOfAttempts) Deprecated.as of 2.0.0, replaced byTransactionOptions.Builder.setExecutor(Executor)andTransactionOptions.ReadWriteOptionsBuilder.setNumberOfAttempts(int)Create a default set of options with a custom executor and a custom number of retry attempts.- Parameters:
executor- The executor to run the user callback code on.numberOfAttempts- The number of execution attempts.- Returns:
- The TransactionOptions object.
- See Also:
-
createReadWriteOptionsBuilder
- Returns:
- a new Builder with default values applicable to configuring options for a read-write transaction.
-
createReadOnlyOptionsBuilder
- Returns:
- a new Builder with default values applicable to configuring options for a read-only transaction.
-
TransactionOptions.ReadWriteOptionsBuilder.setNumberOfAttempts(int)