@Test(expected = ApplicationRuntimeException.class) public void beginAndRollbackTransaction() throws Exception { transactionFactory.expectNoTransaction(); transactionFactory.expectBeginTransaction(); transactionFactory.expectSetRollbackOnly(); transactionFactory.expectRollbackTransaction(); transactionFactory.replay(); try { InvocationContext ic = createNiceMock(InvocationContext.class); expect(ic.proceed()).andThrow(new ApplicationRuntimeException()); replay(ic); interceptor.applyTransaction(ic); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof Error) { throw (Error) e.getTargetException(); } else { throw (Exception) e.getTargetException(); } } finally { transactionFactory.verify(); } }
@AroundInvoke public Object applyTransaction(InvocationContext ic) throws Exception { boolean transactionStarted = beginTransactionIfNeeded(); try { Object result = ic.proceed(); return result; } catch (Exception e) { rollbackTransactionIfNeeded(transactionStarted, e); throw e; } finally { handleTransactionEnd(transactionStarted); } }
RequiredTransactionInterceptor extends AbstractTransactionAttributeInterceptor { @AroundInvoke public Object applyTransaction(InvocationContext ic) throws Exception { boolean transactionStarted = beginTransactionIfNeeded(); try { Object result = ic.proceed(); return result; } catch (Exception e) { rollbackTransactionIfNeeded(transactionStarted, e); throw e; } finally { handleTransactionEnd(transactionStarted); } } }
RequiredTransactionInterceptor extends AbstractTransactionAttributeInterceptor { @AroundInvoke public Object applyTransaction(InvocationContext ic) throws Exception { boolean transactionStarted = beginTransactionIfNeeded(); try { Object result = ic.proceed(); return result; } catch (Exception e) { rollbackTransactionIfNeeded(transactionStarted, e); throw e; } finally { handleTransactionEnd(transactionStarted); } }  }
RequiredTransactionInterceptor extends AbstractTransactionAttributeInterceptor { @AroundInvoke public Object applyTransaction(InvocationContext ic) throws Exception { boolean transactionStarted = beginTransactionIfNeeded(); try { Object result = ic.proceed(); return result; } catch (Exception e) { rollbackTransactionIfNeeded(transactionStarted, e); throw e; } finally { handleTransactionEnd(transactionStarted); } }  @AroundInvoke Object applyTransaction(InvocationContext ic); }
RequiredTransactionInterceptor extends AbstractTransactionAttributeInterceptor { @AroundInvoke public Object applyTransaction(InvocationContext ic) throws Exception { boolean transactionStarted = beginTransactionIfNeeded(); try { Object result = ic.proceed(); return result; } catch (Exception e) { rollbackTransactionIfNeeded(transactionStarted, e); throw e; } finally { handleTransactionEnd(transactionStarted); } }  @AroundInvoke Object applyTransaction(InvocationContext ic);  }