public void onEntry ( Propagation propagation , int timeout , String interceptionId ) throws SystemException , NotSupportedException , RollbackException { Transaction transaction = getActiveTransaction ( ) ; switch ( propagation ) { case REQUIRES : // Are we already in a transaction? if ( transaction == null ) { // No, create one if ( timeout > 0 ) { manager . setTransactionTimeout ( timeout ) ; } manager . begin ( ) ; Transaction tx = getActiveTransaction ( ) ; tx . registerSynchronization ( this ) ; owned . add ( tx ) ; } else { // Add the transaction to the transaction list transactions . add ( transaction ) ; } break ; case MANDATORY : if ( transaction == null ) { // Error throw new IllegalStateException ( "The " + interceptionId + " must be called inside a " + "JTA transaction" ) ; } else { if ( transactions . add ( transaction ) ) { transaction . registerSynchronization ( this ) ; } } break ; case SUPPORTED : // if transaction != null, register the callback, else do nothing if ( transaction != null ) { if ( transactions . add ( transaction ) ) { transaction . registerSynchronization ( this ) ; } } // Else do nothing. break ; case NOT_SUPPORTED : if ( transaction != null ) { // Suspend the current transaction. suspended . put ( Thread . currentThread ( ) , transaction ) ; manager . suspend ( ) ; } break ; case NEVER : if ( transaction != null ) { throw new IllegalStateException ( "The " + interceptionId + " must never be called inside a transaction" ) ; } break ; case REQUIRES_NEW : if ( transaction == null ) { // No current transaction, Just creates a new one if ( timeout > 0 ) { manager . setTransactionTimeout ( timeout ) ; } manager . begin ( ) ; Transaction tx = getActiveTransaction ( ) ; owned . add ( tx ) ; } else { // suspend the current transaction suspended . put ( Thread . currentThread ( ) , manager . suspend ( ) ) ; if ( timeout > 0 ) { manager . setTransactionTimeout ( timeout ) ; } manager . begin ( ) ; owned . add ( manager . getTransaction ( ) ) ; } break ; default : throw new UnsupportedOperationException ( "Unknown or unsupported propagation policy for " + interceptionId + " :" + propagation ) ; } }
Enters a transactional bloc .