Class TransactionOptions (3.30.2)

public final class 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 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 ReadOnlyOptionsBuilder class. A new instance can be created by calling #createReadOnlyOptionsBuilder(). See Also: com.google.firestore.v1.TransactionOptions

Inheritance

java.lang.Object > TransactionOptions

Static Methods

create()

public static TransactionOptions 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. See Also: #createReadWriteOptionsBuilder()

Returns
Type Description
TransactionOptions

The TransactionOptions object.

create(int numberOfAttempts) (deprecated)

public static TransactionOptions create(int numberOfAttempts)

Deprecated. as of 2.0.0, replaced by ReadWriteOptionsBuilder#setNumberOfAttempts(int)

Create a default set of options with a custom number of retry attempts. See Also: #createReadWriteOptionsBuilder()

Parameter
Name Description
numberOfAttempts int

The number of execution attempts.

Returns
Type Description
TransactionOptions

The TransactionOptions object.

create(Executor executor) (deprecated)

public static TransactionOptions create(Executor executor)

Deprecated. as of 2.0.0, replaced by ReadWriteOptionsBuilder#setExecutor(Executor)

Create a default set of options with a custom executor. See Also: #createReadWriteOptionsBuilder()

Parameter
Name Description
executor Executor

The executor to run the user callback code on.

Returns
Type Description
TransactionOptions

The TransactionOptions object.

create(Executor executor, int numberOfAttempts) (deprecated)

public static TransactionOptions create(Executor executor, int numberOfAttempts)

Deprecated. as of 2.0.0, replaced by ReadWriteOptionsBuilder#setExecutor(Executor) and ReadWriteOptionsBuilder#setNumberOfAttempts(int)

Create a default set of options with a custom executor and a custom number of retry attempts. See Also: #createReadWriteOptionsBuilder()

Parameters
Name Description
executor Executor

The executor to run the user callback code on.

numberOfAttempts int

The number of execution attempts.

Returns
Type Description
TransactionOptions

The TransactionOptions object.

createReadOnlyOptionsBuilder()

public static TransactionOptions.ReadOnlyOptionsBuilder createReadOnlyOptionsBuilder()
Returns
Type Description
TransactionOptions.ReadOnlyOptionsBuilder

a new Builder with default values applicable to configuring options for a read-only transaction.

createReadWriteOptionsBuilder()

public static TransactionOptions.ReadWriteOptionsBuilder createReadWriteOptionsBuilder()
Returns
Type Description
TransactionOptions.ReadWriteOptionsBuilder

a new Builder with default values applicable to configuring options for a read-write transaction.

Methods

getExecutor()

public Executor getExecutor()
Returns
Type Description
Executor

Executor to be used to run user callbacks on

getNumberOfAttempts()

public int getNumberOfAttempts()

Returns the maximum number of times a transaction will be attempted before resulting in an error.

Returns
Type Description
int

The max number of attempts to try and commit the transaction.

getReadTime()

public Timestamp getReadTime()

A Timestamp specifying 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 specified Timestamp may not be more than 60 minutes in the past (evaluated when the request is processed by the server).

Returns
Type Description
Timestamp

The specific time to read documents at. A null value means reading the most up to date data.

getType()

public TransactionOptions.TransactionOptionsType getType()

A type flag indicating the type of transaction represented.

Returns
Type Description
TransactionOptions.TransactionOptionsType

The type of transaction this represents. Either read-only or read-write.