Class TransactionAdapter
java.lang.Object
ch.tocco.nice2.persist.core.impl.hibernate.legacy.TransactionAdapter
- All Implemented Interfaces:
Transaction
Adapter between hibernate and nice Transactions.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.tx.Transaction
Transaction.State
-
Constructor Summary
-
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.Retrieve any exceptions that were thrown during commit or rollback.getRegistered
(Object key) Check for a registered transaction aware object.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.
-
Constructor Details
-
TransactionAdapter
-
-
Method Details
-
getContext
Description copied from interface:Transaction
Get the transaction's context.- Specified by:
getContext
in interfaceTransaction
- Returns:
- The transaction's context.
-
commit
Description copied from interface:Transaction
Commit the transaction.- Specified by:
commit
in interfaceTransaction
- Throws:
PersistException
- If committing the transaction failed.
-
rollback
public void rollback()Description copied from interface:Transaction
Roll back the transaction.- Specified by:
rollback
in interfaceTransaction
- See Also:
-
ensureRollback
public void ensureRollback()Description copied from interface:Transaction
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.
- Specified by:
ensureRollback
in interfaceTransaction
- See Also:
-
setRollbackOnly
public void setRollbackOnly()Description copied from interface:Transaction
Set the transaction rollback only. A transaction that is set rollback only cannot be committed.Transaction.commit()
will then throw aRollbackException
.- Specified by:
setRollbackOnly
in interfaceTransaction
-
isRollbackOnly
public boolean isRollbackOnly()Description copied from interface:Transaction
Check whether the transaction is set rollback only.- Specified by:
isRollbackOnly
in interfaceTransaction
- Returns:
true
if the transaction is set rollback only.
-
getRegistered
Description copied from interface:Transaction
Check for a registered transaction aware object.- Specified by:
getRegistered
in interfaceTransaction
- Parameters:
key
- The key to check- Returns:
- The registered object or
null
.
-
register
public TransactionAware register(Object key, TransactionAware transactionAware) throws IllegalStateException Description copied from interface:Transaction
Register a new transaction aware object to the transaction to receive callback events, if no such object is registered yet.- Specified by:
register
in interfaceTransaction
- 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.
-
setAttribute
- Specified by:
setAttribute
in interfaceTransaction
-
getAttribute
- Specified by:
getAttribute
in interfaceTransaction
-
getState
Description copied from interface:Transaction
Get the current state of the transaction.- Specified by:
getState
in interfaceTransaction
- Returns:
- The current state of the transaction.
-
getExceptions
Description copied from interface:Transaction
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.- Specified by:
getExceptions
in interfaceTransaction
- Returns:
- A list of exceptions thrown during rollack or commit.
-