@Override protected void registerSynchronization_impl(AbstractSynchronizationListener listener, Object txn) throws Exception { final TransactionImpl transaction = (TransactionImpl) txn; final Synchronization synchronization = (Synchronization) listener; transaction.registerInterposedSynchronization(synchronization); } }
private TransactionImpl getActiveTransactionImpl() { TransactionImpl tx = (TransactionImpl)threadTx.get(); if (tx == null) { throw new IllegalStateException("No tx on thread"); } if (tx.getStatus() != Status.STATUS_ACTIVE && tx.getStatus() != Status.STATUS_MARKED_ROLLBACK) { throw new IllegalStateException("Transaction " + tx + " is not active"); } return tx; }
void preparedCommit() throws HeuristicRollbackException, HeuristicMixedException, SystemException { try { commitResources(resourceManagers); } finally { afterCompletion(); synchronized (this) { status = Status.STATUS_NO_TRANSACTION; } } }
private void beforePrepare() { synchronized (this) { switch (status) { case Status.STATUS_ACTIVE: case Status.STATUS_MARKED_ROLLBACK: break; default: throw new IllegalStateException("Status is " + getStateString(status)); } } beforeCompletion(); endResources(); }
int prepare() throws SystemException, RollbackException { beforePrepare(); int result = XAResource.XA_RDONLY; try { boolean willCommit = internalPrepare(); rollbackResources(rms); throw new RollbackException("Unable to commit"); afterCompletion(); synchronized (this) { status = Status.STATUS_NO_TRANSACTION;
public void rollback() throws IllegalStateException, SystemException { List rms; synchronized (this) { switch (status) { case Status.STATUS_ACTIVE: status = Status.STATUS_MARKED_ROLLBACK; break; case Status.STATUS_MARKED_ROLLBACK: break; default: throw new IllegalStateException("Status is " + getStateString(status)); } rms = resourceManagers; } endResources(); try { try { rollbackResources(rms, false); } catch (HeuristicMixedException e) { throw (SystemException)new SystemException("Unable to roll back due to heuristics").initCause(e); } } finally { afterCompletion(); synchronized (this) { status = Status.STATUS_NO_TRANSACTION; } } }
public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException, SecurityException, SystemException { beforePrepare(); rollbackResourcesDuringCommit(resourceManagers, false); if (timedout) { throw new RollbackException("Unable to commit: Transaction timeout"); commitResource(manager); return; try { willCommit = internalPrepare(); } catch (SystemException e) { rollbackResources(resourceManagers); throw e; commitResources(resourceManagers); } else { rollbackResourcesDuringCommit(resourceManagers, true); afterCompletion(); synchronized (this) { status = Status.STATUS_NO_TRANSACTION;
public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException, SecurityException, SystemException { beforePrepare(); markRollbackCause(new Exception("Transaction has timed out")); status = Status.STATUS_MARKED_ROLLBACK; rollbackResources(resourceManagers, false); RollbackException rollbackException = new RollbackException("Unable to commit: transaction marked for rollback"); if (markRollbackCause != null) { commitResource(manager); return; try { willCommit = internalPrepare(); } catch (SystemException e) { rollbackResources(resourceManagers, false); throw e; commitResources(resourceManagers); } else { rollbackResources(resourceManagers, true); throw new RollbackException("transaction rolled back due to problems in prepare"); afterCompletion(); synchronized (this) { status = Status.STATUS_NO_TRANSACTION;
break; default: throw new IllegalStateException("Status is " + getStateString(status)); activeXaResources.put(xaRes, addBranchXid(xaRes, branchId)); return true; } catch (XAException e) { log.warn("Unable to enlist XAResource " + xaRes + ", errorCode: " + e.errorCode, e); setRollbackOnly(); return false;
public Transaction importXid(Xid xid, long transactionTimeoutMilliseconds) throws XAException, SystemException { if (transactionTimeoutMilliseconds < 0) { throw new SystemException("transaction timeout must be positive or 0 to reset to default"); } return new TransactionImpl(xid, this, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds)); }
public Object getTransactionKey() { TransactionImpl tx = (TransactionImpl) getTransaction(); return tx == null ? null: tx.getTransactionKey(); }
public Object getResource(Object key) { TransactionImpl tx = getActiveTransactionImpl(); return tx.getResource(key); }
break; default: throw new IllegalStateException("Status is " + getStateString(status)); activeXaResources.put(xaRes, addBranchXid(xaRes, branchId)); return true; } catch (XAException e) {
private void afterCompletion() { // this does not synchronize because nothing can modify our state at this time afterCompletion(interposedSyncList); afterCompletion(syncList); }
private void beforeCompletion() { beforeCompletion(syncList); beforeCompletion(interposedSyncList); }
externalTx.addBranchXid(xaResource, xid);
private EntityManager getEntityManager(boolean activeRequired) { TransactionImpl transaction = (TransactionImpl) transactionManager.getTransaction(); if (activeRequired && (transaction == null || transaction.getStatus() != Status.STATUS_ACTIVE)) { throw new TransactionRequiredException("No active transaction"); } if (transaction == null) { return null; } EntityManagerWrapper entityManagerWrapper = (EntityManagerWrapper) transactionManager.getResource(persistenceUnit); if (entityManagerWrapper == null) { EntityManager entityManager = createEntityManager(); entityManagerWrapper = new EntityManagerWrapperTxScoped(entityManager); transactionManager.putResource(persistenceUnit, entityManagerWrapper); try { transaction.registerSynchronization(entityManagerWrapper); } catch (javax.transaction.RollbackException e) { throw (TransactionRequiredException) new TransactionRequiredException("No active transaction").initCause(e); } catch (SystemException e) { throw (TransactionRequiredException) new TransactionRequiredException("No active transaction").initCause(e); } } return entityManagerWrapper.getEntityManager(); }
int prepare() throws SystemException, RollbackException { beforePrepare(); int result = XAResource.XA_RDONLY; try { boolean willCommit = internalPrepare(); rollbackResources(rms); throw new RollbackException("Unable to commit"); afterCompletion(); synchronized (this) { status = Status.STATUS_NO_TRANSACTION;
break; default: throw new IllegalStateException("Status is " + getStateString(status)); beforeCompletion(); endResources(); try { rollbackResources(rms); } catch (LogException e) { try { rollbackResources(rms); } catch (Exception se) { log.error("Unable to rollback after failure to log decision", se.getCause()); afterCompletion(); synchronized (this) { status = Status.STATUS_NO_TRANSACTION;
public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException, SecurityException, SystemException { beforePrepare(); rollbackResourcesDuringCommit(resourceManagers, false); if (timedout) { throw new RollbackException("Unable to commit: Transaction timeout"); commitResource(manager); return; try { willCommit = internalPrepare(); } catch (SystemException e) { rollbackResources(resourceManagers); throw e; commitResources(resourceManagers); } else { rollbackResourcesDuringCommit(resourceManagers, true); afterCompletion(); synchronized (this) { status = Status.STATUS_NO_TRANSACTION;