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 ClassesNested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.tx.Transaction
Transaction.State -
Constructor Summary
Constructors -
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.
-
Constructor Details
-
TransactionAdapter
-
-
Method Details
-
getContext
Description copied from interface:TransactionGet the transaction's context.- Specified by:
getContextin interfaceTransaction- Returns:
- The transaction's context.
-
commit
Description copied from interface:TransactionCommit the transaction.- Specified by:
commitin interfaceTransaction- Throws:
PersistException- If committing the transaction failed.
-
rollback
public void rollback()Description copied from interface:TransactionRoll back the transaction.- Specified by:
rollbackin interfaceTransaction- See Also:
-
ensureRollback
public void ensureRollback()Description copied from interface:TransactionRoll 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:
ensureRollbackin interfaceTransaction- See Also:
-
setRollbackOnly
public void setRollbackOnly()Description copied from interface:TransactionSet the transaction rollback only. A transaction that is set rollback only cannot be committed.Transaction.commit()will then throw aRollbackException.- Specified by:
setRollbackOnlyin interfaceTransaction
-
isRollbackOnly
public boolean isRollbackOnly()Description copied from interface:TransactionCheck whether the transaction is set rollback only.- Specified by:
isRollbackOnlyin interfaceTransaction- Returns:
trueif the transaction is set rollback only.
-
register
public TransactionAware register(Object key, TransactionAware transactionAware) throws IllegalStateException Description copied from interface:TransactionRegister a new transaction aware object to the transaction to receive callback events, if no such object is registered yet.- Specified by:
registerin 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:
setAttributein interfaceTransaction
-
getAttribute
- Specified by:
getAttributein interfaceTransaction
-
getState
Description copied from interface:TransactionGet the current state of the transaction.- Specified by:
getStatein interfaceTransaction- Returns:
- The current state of the transaction.
-