/** * Constructor for HeuristicCompletionException. * @param outcomeState the outcome state of the transaction * @param cause the root cause from the transaction API in use */ public HeuristicCompletionException(int outcomeState, Throwable cause) { super("Heuristic completion: outcome state is " + getStateString(outcomeState), cause); this.outcomeState = outcomeState; }
throw new HeuristicCompletionException(HeuristicCompletionException.STATE_MIXED, ex); throw new HeuristicCompletionException(HeuristicCompletionException.STATE_ROLLED_BACK, ex);
@Test public void jtaTransactionManagerWithHeuristicMixedExceptionOnCommit() throws Exception { UserTransaction ut = mock(UserTransaction.class); given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE); willThrow(new HeuristicMixedException("heuristic exception")).given(ut).commit(); try { JtaTransactionManager ptm = newJtaTransactionManager(ut); TransactionTemplate tt = new TransactionTemplate(ptm); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { // something transactional TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @Override public void afterCompletion(int status) { assertTrue("Correct completion status", status == TransactionSynchronization.STATUS_UNKNOWN); } }); } }); fail("Should have thrown HeuristicCompletionException"); } catch (HeuristicCompletionException ex) { // expected assertTrue(ex.getOutcomeState() == HeuristicCompletionException.STATE_MIXED); } verify(ut).begin(); }
throw new HeuristicCompletionException(HeuristicCompletionException.STATE_MIXED, ex); throw new HeuristicCompletionException(HeuristicCompletionException.STATE_ROLLED_BACK, ex);
@Test public void jtaTransactionManagerWithHeuristicRollbackExceptionOnCommit() throws Exception { UserTransaction ut = mock(UserTransaction.class); given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE); willThrow(new HeuristicRollbackException("heuristic exception")).given(ut).commit(); try { JtaTransactionManager ptm = newJtaTransactionManager(ut); TransactionTemplate tt = new TransactionTemplate(ptm); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { // something transactional TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @Override public void afterCompletion(int status) { assertTrue("Correct completion status", status == TransactionSynchronization.STATUS_UNKNOWN); } }); } }); fail("Should have thrown HeuristicCompletionException"); } catch (HeuristicCompletionException ex) { // expected assertTrue(ex.getOutcomeState() == HeuristicCompletionException.STATE_ROLLED_BACK); } verify(ut).begin(); }
protected void doCommit(DefaultTransactionStatus status) { JtaTransactionObject txObject = (JtaTransactionObject) status.getTransaction(); try { txObject.getUserTransaction().commit(); } catch (RollbackException ex) { throw new UnexpectedRollbackException( "JTA transaction unexpectedly rolled back (maybe due to a timeout)", ex); } catch (HeuristicMixedException ex) { throw new HeuristicCompletionException(HeuristicCompletionException.STATE_MIXED, ex); } catch (HeuristicRollbackException ex) { throw new HeuristicCompletionException(HeuristicCompletionException.STATE_ROLLED_BACK, ex); } catch (SystemException ex) { throw new TransactionSystemException("JTA failure on commit", ex); } }
/** * Constructor for HeuristicCompletionException. * @param outcomeState the outcome state of the transaction * @param cause the root cause from the transaction API in use */ public HeuristicCompletionException(int outcomeState, Throwable cause) { super("Heuristic completion: outcome state is " + getStateString(outcomeState), cause); this.outcomeState = outcomeState; }
int transactionState = firstTransactionManagerFailed ? HeuristicCompletionException.STATE_ROLLED_BACK : HeuristicCompletionException.STATE_MIXED; throw new HeuristicCompletionException(transactionState, commitException);
/** * Constructor for HeuristicCompletionException. * @param outcomeState the outcome state of the transaction * @param cause the root cause from the transaction API in use */ public HeuristicCompletionException(int outcomeState, Throwable cause) { super("Heuristic completion: outcome state is " + getStateString(outcomeState), cause); this.outcomeState = outcomeState; }
int transactionState = firstTransactionManagerFailed ? HeuristicCompletionException.STATE_ROLLED_BACK : HeuristicCompletionException.STATE_MIXED; throw new HeuristicCompletionException(transactionState, commitException);
/** * Constructor for HeuristicCompletionException. * @param outcomeState the outcome state of the transaction * @param cause the root cause from the transaction API in use */ public HeuristicCompletionException(int outcomeState, Throwable cause) { super("Heuristic completion: outcome state is " + getStateString(outcomeState), cause); this.outcomeState = outcomeState; }
throw new HeuristicCompletionException(HeuristicCompletionException.STATE_MIXED, ex); throw new HeuristicCompletionException(HeuristicCompletionException.STATE_ROLLED_BACK, ex);
/** * Constructor for HeuristicCompletionException. * @param outcomeState the outcome state of the transaction * @param ex root cause from transaction API in use */ public HeuristicCompletionException(int outcomeState, Throwable ex) { super("Heuristic completion: outcome state is " + getStateString(outcomeState), ex); this.outcomeState = outcomeState; }
throw new HeuristicCompletionException(HeuristicCompletionException.STATE_MIXED, ex); throw new HeuristicCompletionException(HeuristicCompletionException.STATE_ROLLED_BACK, ex);
int transactionState = firstTransactionManagerFailed ? HeuristicCompletionException.STATE_ROLLED_BACK : HeuristicCompletionException.STATE_MIXED; throw new HeuristicCompletionException(transactionState, commitException);