private Object invokeInTransactionAndUnitOfWork ( MethodInvocation methodInvocation ) throws Throwable { boolean unitOfWorkAlreadyStarted = unitOfWork . isActive ( ) ; if ( ! unitOfWorkAlreadyStarted ) { unitOfWork . begin ( ) ; } Throwable originalThrowable = null ; try { return dslContextProvider . get ( ) . transactionResult ( ( ) -> { try { return methodInvocation . proceed ( ) ; } catch ( Throwable e ) { if ( e instanceof RuntimeException ) { throw ( RuntimeException ) e ; } throw new RuntimeException ( e ) ; } } ) ; } catch ( Throwable t ) { originalThrowable = t ; throw t ; } finally { if ( ! unitOfWorkAlreadyStarted ) { endUnitOfWork ( originalThrowable ) ; } } }
Invokes the method wrapped within a unit of work and a transaction .