Class TransactionHandler


  • public final class TransactionHandler
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void endTransaction​(javax.transaction.TransactionManager tm, javax.transaction.Transaction tx, RunnableWithException afterEndTransaction)
      It finished the transaction.
      static void handleExceptionNoThrow​(javax.transaction.Transactional transactional, java.lang.Throwable t, javax.transaction.Transaction tx)
      For cases that the transaction should be marked for rollback ie.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TransactionHandler

        public TransactionHandler()
    • Method Detail

      • handleExceptionNoThrow

        public static void handleExceptionNoThrow​(javax.transaction.Transactional transactional,
                                                  java.lang.Throwable t,
                                                  javax.transaction.Transaction tx)
                                           throws java.lang.IllegalStateException,
                                                  javax.transaction.SystemException
        For cases that the transaction should be marked for rollback ie. when RuntimeException is thrown or when Error is thrown or when the exception si marked in Transactional.rollbackOn() then Transaction.setRollbackOnly() is invoked.
        Throws:
        java.lang.IllegalStateException
        javax.transaction.SystemException
      • endTransaction

        public static void endTransaction​(javax.transaction.TransactionManager tm,
                                          javax.transaction.Transaction tx,
                                          RunnableWithException afterEndTransaction)
                                   throws java.lang.Exception

        It finished the transaction.

        Call TransactionManager.rollback() when the transaction si marked for Status.STATUS_MARKED_ROLLBACK. otherwise the transaction is committed. Either way there is executed the Runnable 'afterEndTransaction' after the transaction is finished.

        Throws:
        java.lang.Exception