Interface Transaction
- All Known Implementing Classes:
TransactionAdapter
public interface Transaction
Represents a transaction.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumEnumeration describing the state of the transaction. -
Method Summary
Modifier and TypeMethodDescriptionvoidcommit()Commit the transaction.voidRoll back the transaction if not rolling back or rolled back already.<T> TgetAttribute(String key) Get the transaction's context.getState()Get the current state of the transaction.booleanCheck 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.voidrollback()Roll back the transaction.voidsetAttribute(String key, Object value) voidSet 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:
trueif the transaction is set rollback only.
-
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.
-
setAttribute
-
getAttribute
-