@Test public void canBeCommittedIfSubclassOfIgnoredExceptionThrown() { Transactional transactional = createNiceMock(Transactional.class); EntityTransaction transaction = createStrictMock(EntityTransaction.class); expect(transaction.getRollbackOnly()).andReturn(false); expect(transactional.rollbackOn()).andReturn(asArray(Exception.class)); expect(transactional.ignore()).andReturn(asArray(IOException.class)); replayAll(); boolean canCommit = rollbackIfNecessary(transactional, new FileNotFoundException("rolling back"), transaction); Assert.assertTrue("Should be allowed to commit, since subclass of ignored exception was thrown", canCommit); verifyAll(); }
static boolean rollbackIfNecessary(Transactional transactional, Exception e, EntityTransaction txn) { if (txn.getRollbackOnly()) { txn.rollback(); return false; } boolean commit = true; for (Class<? extends Exception> rollBackOn : transactional.rollbackOn()) { if (rollBackOn.isInstance(e)) { commit = false; for (Class<? extends Exception> exceptOn : transactional.ignore()) { if (exceptOn.isInstance(e)) { commit = true; break; } } if (!commit) { txn.rollback(); } break; } } return commit; }
AmbariJpaLocalTxnInterceptor implements MethodInterceptor { static boolean rollbackIfNecessary(Transactional transactional, Exception e, EntityTransaction txn) { if (txn.getRollbackOnly()) { txn.rollback(); return false; } boolean commit = true; for (Class<? extends Exception> rollBackOn : transactional.rollbackOn()) { if (rollBackOn.isInstance(e)) { commit = false; for (Class<? extends Exception> exceptOn : transactional.ignore()) { if (exceptOn.isInstance(e)) { commit = true; break; } } if (!commit) { txn.rollback(); } break; } } return commit; } }
AmbariJpaLocalTxnInterceptor implements MethodInterceptor { static boolean rollbackIfNecessary(Transactional transactional, Exception e, EntityTransaction txn) { if (txn.getRollbackOnly()) { txn.rollback(); return false; } boolean commit = true; for (Class<? extends Exception> rollBackOn : transactional.rollbackOn()) { if (rollBackOn.isInstance(e)) { commit = false; for (Class<? extends Exception> exceptOn : transactional.ignore()) { if (exceptOn.isInstance(e)) { commit = true; break; } } if (!commit) { txn.rollback(); } break; } } return commit; }  }
AmbariJpaLocalTxnInterceptor implements MethodInterceptor { static boolean rollbackIfNecessary(Transactional transactional, Exception e, EntityTransaction txn) { if (txn.getRollbackOnly()) { txn.rollback(); return false; } boolean commit = true; for (Class<? extends Exception> rollBackOn : transactional.rollbackOn()) { if (rollBackOn.isInstance(e)) { commit = false; for (Class<? extends Exception> exceptOn : transactional.ignore()) { if (exceptOn.isInstance(e)) { commit = true; break; } } if (!commit) { txn.rollback(); } break; } } return commit; }  @Override Object invoke(MethodInvocation methodInvocation); }
AmbariJpaLocalTxnInterceptor implements MethodInterceptor { static boolean rollbackIfNecessary(Transactional transactional, Exception e, EntityTransaction txn) { if (txn.getRollbackOnly()) { txn.rollback(); return false; } boolean commit = true; for (Class<? extends Exception> rollBackOn : transactional.rollbackOn()) { if (rollBackOn.isInstance(e)) { commit = false; for (Class<? extends Exception> exceptOn : transactional.ignore()) { if (exceptOn.isInstance(e)) { commit = true; break; } } if (!commit) { txn.rollback(); } break; } } return commit; }  @Override Object invoke(MethodInvocation methodInvocation);  }