Class TransactionAdapter

java.lang.Object
ch.tocco.nice2.persist.core.impl.hibernate.legacy.TransactionAdapter
All Implemented Interfaces:
Transaction

public class TransactionAdapter extends Object implements Transaction
Adapter between hibernate and nice Transactions.
  • Constructor Details

  • Method Details

    • getContext

      public Context getContext()
      Description copied from interface: Transaction
      Get the transaction's context.
      Specified by:
      getContext in interface Transaction
      Returns:
      The transaction's context.
    • commit

      public void commit() throws PersistException
      Description copied from interface: Transaction
      Commit the transaction.
      Specified by:
      commit in interface Transaction
      Throws:
      PersistException - If committing the transaction failed.
    • rollback

      public void rollback()
      Description copied from interface: Transaction
      Roll back the transaction.
      Specified by:
      rollback in interface Transaction
      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 interface Transaction
      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 a RollbackException.
      Specified by:
      setRollbackOnly in interface Transaction
    • isRollbackOnly

      public boolean isRollbackOnly()
      Description copied from interface: Transaction
      Check whether the transaction is set rollback only.
      Specified by:
      isRollbackOnly in interface Transaction
      Returns:
      true if the transaction is set rollback only.
    • getRegistered

      public TransactionAware getRegistered(Object key)
      Description copied from interface: Transaction
      Check for a registered transaction aware object.
      Specified by:
      getRegistered in interface Transaction
      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 interface Transaction
      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

      public void setAttribute(String key, Object value)
      Specified by:
      setAttribute in interface Transaction
    • getAttribute

      public <T> T getAttribute(String key)
      Specified by:
      getAttribute in interface Transaction
    • getState

      public Transaction.State getState()
      Description copied from interface: Transaction
      Get the current state of the transaction.
      Specified by:
      getState in interface Transaction
      Returns:
      The current state of the transaction.
    • getExceptions

      public List<Throwable> 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 if TransactionAwares throw exceptions during panic or cleanup.
      Specified by:
      getExceptions in interface Transaction
      Returns:
      A list of exceptions thrown during rollack or commit.