public interface AsyncTransactionManager extends AutoCloseable
TransactionContext
for a description of transaction semantics.
At any point in time there can be at most one active transaction in this manager. When that
transaction is committed, if it fails with an ABORTED
error, calling resetForRetryAsync()
would create a new AsyncTransactionManager.TransactionContextFuture
. The newly created
transaction would use the same session thus increasing its lock priority. If the transaction is
committed successfully, or is rolled back or commit fails with any error other than ABORTED
, the manager is considered complete and no further transactions are allowed to be
created in it.
Every AsyncTransactionManager
should either be committed or rolled back. Failure to do
so can cause resources to be leaked and deadlocks. Easiest way to guarantee this is by calling
close()
in a finally block.
DatabaseClient#transactionManagerAsync()
Modifier and Type | Interface and Description |
---|---|
static interface |
AsyncTransactionManager.AsyncTransactionFunction<I,O>
Each step in a transaction chain is defined by an
AsyncTransactionManager.AsyncTransactionFunction . |
static interface |
AsyncTransactionManager.AsyncTransactionStep<I,O>
AsyncTransactionManager.AsyncTransactionStep is returned by TransactionContextFuture#then(AsyncTransactionFunction) and AsyncTransactionStep#then(AsyncTransactionFunction) and allows transaction steps that should
be executed serially to be chained together. |
static interface |
AsyncTransactionManager.CommitTimestampFuture
ApiFuture that returns the commit Timestamp of a Cloud Spanner transaction that
is executed using an AsyncTransactionManager . |
static interface |
AsyncTransactionManager.TransactionContextFuture
ApiFuture that returns a TransactionContext and that supports chaining of
multiple AsyncTransactionManager.TransactionContextFuture s to form a transaction. |
Modifier and Type | Method and Description |
---|---|
AsyncTransactionManager.TransactionContextFuture |
beginAsync()
Creates a new read write transaction.
|
void |
close()
Closes the manager.
|
com.google.api.core.ApiFuture<Void> |
closeAsync()
Closes the transaction manager.
|
com.google.api.core.ApiFuture<CommitResponse> |
getCommitResponse()
Returns the
CommitResponse of this transaction. |
TransactionManager.TransactionState |
getState()
Returns the state of the transaction.
|
AsyncTransactionManager.TransactionContextFuture |
resetForRetryAsync()
Creates a new transaction for retry.
|
com.google.api.core.ApiFuture<Void> |
rollbackAsync()
Rolls back the currently active transaction.
|
AsyncTransactionManager.TransactionContextFuture beginAsync()
#resetForRetry()
.com.google.api.core.ApiFuture<Void> rollbackAsync()
close()
would automatically roll back any active transaction.AsyncTransactionManager.TransactionContextFuture resetForRetryAsync()
ABORTED
. In all other cases, this will throw an IllegalStateException
. Users should backoff before calling this method. Backoff delay is
specified by SpannerException.getRetryDelayInMillis()
on the SpannerException
throw by the previous commit call.TransactionManager.TransactionState getState()
com.google.api.core.ApiFuture<CommitResponse> getCommitResponse()
CommitResponse
of this transaction.void close()
close
in interface AutoCloseable
com.google.api.core.ApiFuture<Void> closeAsync()
ApiFuture
is
done when the transaction (if any) has been rolled back.Copyright © 2022 Google LLC. All rights reserved.