Interface Transaction
- All Known Implementing Classes:
TransactionAdapter
public interface Transaction
Represents a transaction.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
Enumeration describing the state of the transaction. -
Method Summary
Modifier and TypeMethodDescriptionvoid
commit()
Commit the transaction.void
Roll back the transaction if not rolling back or rolled back already.<T> T
getAttribute
(String key) Get the transaction's context.Deprecated.getRegistered
(Object key) Deprecated.getState()
Get the current state of the transaction.boolean
Check whether the transaction is set rollback only.register
(Object key, TransactionAware transactionAware) Register a new transaction aware object to the transaction to receive callback events, if no such object is registered yet.void
rollback()
Roll back the transaction.void
setAttribute
(String key, Object value) void
Set the transaction rollback only.
-
Method Details
-
getContext
Context getContext()Get the transaction's context.- Returns:
- The transaction's context.
-
commit
Commit the transaction.- Throws:
PersistException
- If committing the transaction failed.RollbackException
- If the transaction was set rollback only (normal rollback).IllegalStateException
- If the transaction is not currently associated with this thread.
-
rollback
void rollback()Roll back the transaction.- Throws:
IllegalStateException
- If the transaction is not currently associated with this thread, or if it is not in State.RUNNING.- See Also:
-
ensureRollback
void ensureRollback()Roll back the transaction if not rolling back or rolled back already.This may be used in finally blocks for example. Otherwise it is recommended to know the state of the tx, and not to guess it.
- Throws:
IllegalStateException
- If the transaction is not currently associated with this thread, or if it is not running nor rolled back nor rolling back.- See Also:
-
setRollbackOnly
void setRollbackOnly()Set the transaction rollback only. A transaction that is set rollback only cannot be committed.commit()
will then throw aRollbackException
.- Throws:
IllegalStateException
- If the transaction is not currently associated with this thread.
-
isRollbackOnly
boolean isRollbackOnly()Check whether the transaction is set rollback only.- Returns:
true
if the transaction is set rollback only.
-
getRegistered
Deprecated.Check for a registered transaction aware object.- Parameters:
key
- The key to check- Returns:
- The registered object or
null
. - Throws:
IllegalStateException
- If the transaction is not currently associated with the thread.
-
register
TransactionAware register(Object key, TransactionAware transactionAware) throws IllegalStateException Register a new transaction aware object to the transaction to receive callback events, if no such object is registered yet.- Parameters:
key
- The key of the transaction aware.transactionAware
- The new transaction aware object.- Returns:
- The registered transaction aware instance after this call, which is either a previously registered one which means nothing was changed, or the one you pass in now.
- Throws:
IllegalStateException
- If the transaction is not currently associated with the thread or the context of the transaction aware object and the transaction mismatch.
-
getState
Transaction.State getState()Get the current state of the transaction.- Returns:
- The current state of the transaction.
-
getExceptions
Deprecated.Retrieve any exceptions that were thrown during commit or rollback. This includes exceptions that were logged only (which may happen ifTransactionAwares
throw exceptions during panic or cleanup.- Returns:
- A list of exceptions thrown during rollack or commit.
-
setAttribute
-
getAttribute
-