ejb3/src/main/java/org/jboss/as/ejb3/tx/CMTTxInterceptor.java
protected void endTransaction(final Transaction tx) {
        ContextTransactionManager tm = ContextTransactionManager.getInstance();
        try {
            if (! tx.equals(tm.getTransaction())) {
                throw EjbLogger.ROOT_LOGGER.wrongTxOnThread(tx, tm.getTransaction());
            }
            final int txStatus = tx.getStatus();
            if (txStatus == Status.STATUS_ACTIVE) {
                // Commit tx
                // This will happen if
                // a) everything goes well
                // b) app. exception was thrown
                tm.commit();
            } else if (txStatus == Status.STATUS_MARKED_ROLLBACK) {
                tm.rollback();
            } else if (txStatus == Status.STATUS_ROLLEDBACK || txStatus == Status.STATUS_ROLLING_BACK) {
                // handle reaper canceled (rolled back) tx case (see WFLY-1346)
                // clear current tx state and throw RollbackException (EJBTransactionRolledbackException)
                tm.rollback();
                throw EjbLogger.ROOT_LOGGER.transactionAlreadyRolledBack(tx);
            } else if (txStatus == Status.STATUS_UNKNOWN) {
                // STATUS_UNKNOWN isn't expected to be reached here but if it does, we need to clear current thread tx.
                // It is possible that calling tm.commit() could succeed but we call tm.rollback, since this is an unexpected
                // tx state that are are handling.
                tm.rollback();
                // if the tm.rollback doesn't fail, we throw an EJBException to reflect the unexpected tx state.
                throw EjbLogger.ROOT_LOGGER.transactionInUnexpectedState(tx, statusAsString(txStatus));
            } else {
                // logically, all of the following (unexpected) tx states are handled here:
                //  Status.STATUS_PREPARED
                //  Status.STATUS_PREPARING
                //  Status.STATUS_COMMITTING
                //  Status.STATUS_NO_TRANSACTION
                //  Status.STATUS_COMMITTED
                tm.suspend();                       // clear current tx state and throw EJBException
                throw EjbLogger.ROOT_LOGGER.transactionInUnexpectedState(tx, statusAsString(txStatus));
            }
        } catch (RollbackException e) {
            throw new EJBTransactionRolledbackException(e.toString(), e);
        } catch (HeuristicMixedException | SystemException | HeuristicRollbackException e) {
            throw new EJBException(e);
        }
    }
protected void endTransaction(final Transaction tx) {
        ContextTransactionManager tm = ContextTransactionManager.getInstance();
        try {
            if (! tx.equals(tm.getTransaction())) {
                throw EjbLogger.ROOT_LOGGER.wrongTxOnThread(tx, tm.getTransaction());
            }
            final int txStatus = tx.getStatus();
            if (txStatus == Status.STATUS_ACTIVE) {
                // Commit tx
                // This will happen if
                // a) everything goes well
                // b) app. exception was thrown
                tm.commit();
            } else if (txStatus == Status.STATUS_MARKED_ROLLBACK) {
                tm.rollback();
            } else if (txStatus == Status.STATUS_ROLLEDBACK || txStatus == Status.STATUS_ROLLING_BACK) {
                // handle reaper canceled (rolled back) tx case (see WFLY-1346)
                // clear current tx state and throw RollbackException (EJBTransactionRolledbackException)
                tm.rollback();
                throw EjbLogger.ROOT_LOGGER.transactionAlreadyRolledBack(tx);
            } else if (txStatus == Status.STATUS_UNKNOWN) {
                // STATUS_UNKNOWN isn't expected to be reached here but if it does, we need to clear current thread tx.
                // It is possible that calling tm.commit() could succeed but we call tm.rollback, since this is an unexpected
                // tx state that are are handling.
                tm.rollback();
                // if the tm.rollback doesn't fail, we throw an EJBException to reflect the unexpected tx state.
                throw EjbLogger.ROOT_LOGGER.transactionInUnexpectedState(tx, statusAsString(txStatus));
            } else {
                // logically, all of the following (unexpected) tx states are handled here:
                //  Status.STATUS_PREPARED
                //  Status.STATUS_PREPARING
                //  Status.STATUS_COMMITTING
                //  Status.STATUS_NO_TRANSACTION
                //  Status.STATUS_COMMITTED
                tm.suspend();                       // clear current tx state and throw EJBException
                throw EjbLogger.ROOT_LOGGER.transactionInUnexpectedState(tx, statusAsString(txStatus));
            }
        } catch (RollbackException e) {
            throw new EJBTransactionRolledbackException(e.toString(), e);
        } catch (HeuristicMixedException | SystemException | HeuristicRollbackException e) {
            throw new EJBException(e);
        }
    }
protected void endTransaction ( final Transaction tx ) { ContextTransactionManager tm = ContextTransactionManager . getInstance ( ) ; try { if ( ! tx . equals ( tm . getTransaction ( ) ) ) { throw EjbLogger . ROOT_LOGGER . wrongTxOnThread ( tx , tm . getTransaction ( ) ) ; } final int txStatus = tx . getStatus ( ) ; if ( txStatus == Status . STATUS_ACTIVE ) { // Commit tx // This will happen if // a) everything goes well // b) app. exception was thrown tm . commit ( ) ; } else if ( txStatus == Status . STATUS_MARKED_ROLLBACK ) { tm . rollback ( ) ; } else if ( txStatus == Status . STATUS_ROLLEDBACK || txStatus == Status . STATUS_ROLLING_BACK ) { // handle reaper canceled (rolled back) tx case (see WFLY-1346) // clear current tx state and throw RollbackException (EJBTransactionRolledbackException) tm . rollback ( ) ; throw EjbLogger . ROOT_LOGGER . transactionAlreadyRolledBack ( tx ) ; } else if ( txStatus == Status . STATUS_UNKNOWN ) { // STATUS_UNKNOWN isn't expected to be reached here but if it does, we need to clear current thread tx. // It is possible that calling tm.commit() could succeed but we call tm.rollback, since this is an unexpected // tx state that are are handling. tm . rollback ( ) ; // if the tm.rollback doesn't fail, we throw an EJBException to reflect the unexpected tx state. throw EjbLogger . ROOT_LOGGER . transactionInUnexpectedState ( tx , statusAsString ( txStatus ) ) ; } else { // logically, all of the following (unexpected) tx states are handled here: //  Status.STATUS_PREPARED //  Status.STATUS_PREPARING //  Status.STATUS_COMMITTING //  Status.STATUS_NO_TRANSACTION //  Status.STATUS_COMMITTED tm . suspend ( ) ; // clear current tx state and throw EJBException throw EjbLogger . ROOT_LOGGER . transactionInUnexpectedState ( tx , statusAsString ( txStatus ) ) ; } } catch ( RollbackException e ) { throw new EJBTransactionRolledbackException ( e . toString ( ) , e ) ; } catch ( HeuristicMixedException | SystemException | HeuristicRollbackException e ) { throw new EJBException ( e ) ; } }
The <code>endTransaction</code> method ends a transaction and
translates any exceptions into
TransactionRolledBack[Local]Exception or SystemException.

@param tx a <code>Transaction</code> value
The <code > endTransaction< / code > method ends a transaction and translates any exceptions into TransactionRolledBack [ Local ] Exception or SystemException .