private Object executeMutableTransaction ( ManagedMethodSPI managedMethod , Object [ ] args ) throws Throwable { // store transaction session on current thread via transactional resource utility // it may happen to have multiple nested transaction on current thread // since all are created by the same transactional resource, all are part of the same session // and there is no harm if storeSession is invoked multiple times // also performance penalty is comparable with the effort to prevent this multiple write Transaction transaction = transactionalResource . createTransaction ( ) ; transactionalResource . storeSession ( transaction . getSession ( ) ) ; try { Object result = managedMethod . invoke ( managedInstance , args ) ; transaction . commit ( ) ; if ( transaction . unused ( ) ) { log . debug ( "Method |%s| superfluously declared transactional." , managedMethod ) ; } return result ; } catch ( Throwable throwable ) { transaction . rollback ( ) ; throw throwable ( throwable , "Mutable transactional method |%s| invocation fail." , managedMethod ) ; } finally { if ( transaction . close ( ) ) { // it may happen to have multiple nested transaction on this thread // if this is the case, remove session from current thread only if outermost transaction is closed // of course if not nested transactions, remove at once transactionalResource . releaseSession ( ) ; } } }
Helper method for mutable transaction execution .