public void onExit ( Propagation propagation , String interceptionId , TransactionCallback callback ) throws HeuristicRollbackException , HeuristicMixedException , SystemException , InvalidTransactionException { Transaction current = getActiveTransaction ( ) ; if ( callback == null ) { callback = new TransactionCallback ( ) { @ Override public void transactionCommitted ( Transaction transaction ) { // Do nothing } @ Override public void transactionRolledBack ( Transaction transaction ) { // Do nothing } } ; } switch ( propagation ) { case REQUIRES : // Are we the owner of the transaction? if ( owned . contains ( current ) ) { // Owner. try { current . commit ( ) ; // Commit the transaction owned . remove ( current ) ; callback . transactionCommitted ( current ) ; } catch ( RollbackException e ) { owned . remove ( current ) ; e . printStackTrace ( ) ; callback . transactionRolledBack ( current ) ; } } // Else wait for commit. break ; case MANDATORY : // We are never the owner, so just exits the transaction. break ; case SUPPORTED : // Do nothing. break ; case NOT_SUPPORTED : // We may have suspended a transaction if one, resume it // If we have another transaction and we have suspended a transaction, // throw an IllegalStateException because it's impossible to resume // the suspended transaction. If we didn't suspend a transaction, accept the new transaction (user // responsibility) List < Transaction > susp = suspended . get ( Thread . currentThread ( ) ) ; if ( current != null && ! susp . isEmpty ( ) ) { throw new IllegalStateException ( "Error while handling " + interceptionId + " : you cannot start a" + " transaction after having suspended one. We would not be able to resume the suspended " + "transaction" ) ; } else if ( current == null && ! susp . isEmpty ( ) ) { manager . resume ( susp . remove ( susp . size ( ) - 1 ) ) ; } break ; case NEVER : // Do nothing. break ; case REQUIRES_NEW : // We're necessary the owner. try { current . commit ( ) ; // Commit the transaction owned . remove ( current ) ; callback . transactionCommitted ( current ) ; List < Transaction > suspendedTransactions = suspended . get ( Thread . currentThread ( ) ) ; if ( suspendedTransactions != null && ! suspendedTransactions . isEmpty ( ) ) { // suspend the completed transaction. Transaction trans = suspendedTransactions . get ( suspendedTransactions . size ( ) - 1 ) ; manager . suspend ( ) ; suspendedTransactions . remove ( trans ) ; manager . resume ( trans ) ; } } catch ( RollbackException e ) { // The transaction was rolledback rather than committed owned . remove ( current ) ; callback . transactionRolledBack ( current ) ; List < Transaction > suspendedTransactions = suspended . get ( Thread . currentThread ( ) ) ; if ( suspendedTransactions != null && ! suspendedTransactions . isEmpty ( ) ) { // suspend the transaction. Transaction trans = suspendedTransactions . get ( suspendedTransactions . size ( ) - 1 ) ; manager . suspend ( ) ; suspendedTransactions . remove ( trans ) ; manager . resume ( trans ) ; } } break ; default : throw new UnsupportedOperationException ( "Unknown or unsupported propagation policy for " + interceptionId + " :" + propagation ) ; } }
Leaves a transactional bloc . This method decides what do to with the current transaction . This includes committing or resuming a transaction .