public synchronized void setRollbackOnly(Throwable reason) { switch (status) { case Status.STATUS_ACTIVE: case Status.STATUS_PREPARING: status = Status.STATUS_MARKED_ROLLBACK; markRollbackCause(reason); break; case Status.STATUS_MARKED_ROLLBACK: case Status.STATUS_ROLLING_BACK: // nothing to do break; default: throw new IllegalStateException("Cannot set rollback only, status is " + getStateString(status)); } }
private void beforeCompletion(List syncs) { int i = 0; while (true) { Synchronization synch; synchronized (this) { if (i == syncs.size()) { return; } else { synch = (Synchronization) syncs.get(i++); } } try { synch.beforeCompletion(); } catch (Exception e) { log.warn("Unexpected exception from beforeCompletion; transaction will roll back", e); synchronized (this) { markRollbackCause(e); status = Status.STATUS_MARKED_ROLLBACK; } } } }
private void endResources(IdentityHashMap<XAResource, TransactionBranch> resourceMap) { while (true) { XAResource xaRes; TransactionBranch manager; int flags; synchronized (this) { Set entrySet = resourceMap.entrySet(); if (entrySet.isEmpty()) { return; } Map.Entry entry = (Map.Entry) entrySet.iterator().next(); xaRes = (XAResource) entry.getKey(); manager = (TransactionBranch) entry.getValue(); flags = (status == Status.STATUS_MARKED_ROLLBACK) ? XAResource.TMFAIL : XAResource.TMSUCCESS; resourceMap.remove(xaRes); } try { xaRes.end(manager.getBranchId(), flags); } catch (XAException e) { log.warn("Error ending association for XAResource " + xaRes + "; transaction will roll back. XA error code: " + e.errorCode, e); synchronized (this) { markRollbackCause(e); status = Status.STATUS_MARKED_ROLLBACK; } } } }
TransactionImpl(Xid xid, TransactionManagerImpl txManager, long transactionTimeoutMilliseconds) throws SystemException { this.txManager = txManager; this.xid = xid; this.timeout = transactionTimeoutMilliseconds + TransactionTimer.getCurrentTime(); try { txManager.getTransactionLog().begin(xid); } catch (LogException e) { markRollbackCause(e); status = Status.STATUS_MARKED_ROLLBACK; SystemException ex = new SystemException("Error logging begin; transaction marked for roll back)"); ex.initCause(e); throw ex; } status = Status.STATUS_ACTIVE; }
markRollbackCause(e); status = Status.STATUS_MARKED_ROLLBACK;
markRollbackCause(new Exception("Transaction has timed out")); status = Status.STATUS_MARKED_ROLLBACK;