@Override public void begin() { currentTransaction = new TestTransaction(gtridGenerator.incrementAndGet()); }
fireBeforeCompletion(); fireInMiddleOf2PC(); fireAfterCompletion(Status.STATUS_COMMITTED);
private void executeWhileIn2PC(AtomicReference<Throwable> exception, Callable<?> callable) { testTransactionManager.getCurrentTransaction().registerTwoPcListener(() -> { try { Thread t = new Thread(() -> { try { // this runs while the committing TX is in-doubt callable.call(); } catch (Throwable t1) { exception.set(t1); } }); t.start(); t.join(); } catch (Throwable e) { exception.set(e); } }); }
@Override public void rollback() throws IllegalStateException, SystemException { try { Set<Map.Entry<XAResource, TestXid>> entries = xids.entrySet(); // delist for (Map.Entry<XAResource, TestXid> entry : entries) { try { entry.getKey().end(entry.getValue(), XAResource.TMSUCCESS); } catch (XAException e) { throw (SystemException) new SystemException(XAException.XAER_RMERR).initCause(e); } } // rollback for (Map.Entry<XAResource, TestXid> entry : entries) { try { entry.getKey().rollback(entry.getValue()); } catch (XAException e) { throw (SystemException) new SystemException(XAException.XAER_RMERR).initCause(e); } } } finally { fireAfterCompletion(Status.STATUS_ROLLEDBACK); } }
@Override public void rollback() throws IllegalStateException, SecurityException, SystemException { currentTransaction.rollback(); currentTransaction = null; }
@Override public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { currentTransaction.commit(); currentTransaction = null; }