public interface TransactionManager 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 resetForRetry()
would create a new TransactionContext
. 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 TransactionManager
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.transactionManager()
Modifier and Type | Interface and Description |
---|---|
static class |
TransactionManager.TransactionState
State of the transaction manager.
|
Modifier and Type | Method and Description |
---|---|
TransactionContext |
begin()
Creates a new read write transaction.
|
void |
close()
Closes the manager.
|
void |
commit()
Commits the currently active transaction.
|
com.google.cloud.Timestamp |
getCommitTimestamp()
Returns the commit timestamp if the transaction committed successfully otherwise it will throw
IllegalStateException . |
TransactionManager.TransactionState |
getState()
Returns the state of the transaction.
|
TransactionContext |
resetForRetry()
Creates a new transaction for retry.
|
void |
rollback()
Rolls back the currently active transaction.
|
TransactionContext begin()
resetForRetry()
.void commit()
AbortedException
.void rollback()
close()
would automatically roll back any active transaction.TransactionContext resetForRetry()
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.com.google.cloud.Timestamp getCommitTimestamp()
IllegalStateException
.TransactionManager.TransactionState getState()
void close()
close
in interface AutoCloseable
Copyright © 2019 Google LLC. All rights reserved.