LocalTransaction getOrAttach(Transaction transaction, CreationListener.CreatedBy createdBy) { LocalTransaction txn = (LocalTransaction) provider.getResource(transaction, LOCAL_TXN_KEY); boolean isNew = false; if (txn == null) { // use LOCAL_TXN_KEY so we can be reasonably assured that there will be no deadlock synchronized (LOCAL_TXN_KEY) { txn = (LocalTransaction) provider.getResource(transaction, LOCAL_TXN_KEY); if (txn == null) { provider.putResource(transaction, LOCAL_TXN_KEY, txn = new LocalTransaction(this, transaction)); isNew = true; } } } if (isNew) { notifyCreationListeners(txn, createdBy); } return txn; }
void commitAndDissociate() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, SystemException { if (isImported()) { throw Log.log.commitOnImported(); } notifyAssociationListeners(false); try { owner.getProvider().getTransactionManager().commit(); } catch (RollbackException re) { addRollbackExceptions(re); throw re; } finally { final XAOutflowedResources outflowedResources = RemoteTransactionContext.getOutflowedResources(this); if (outflowedResources == null || outflowedResources.getEnlistedSubordinates() == 0) { // we can drop the mapping, since we are both a master and have no enlisted subordinates owner.getProvider().dropLocal(transaction); } } }
@Override protected void handleImpl(HttpServerExchange exchange, ImportResult<LocalTransaction> transaction) throws Exception { transaction.getTransaction().commit(); } }
/** * Returns the XAResourceRegistry file for {@code transaction}. * * @param transaction the transaction * @return the XAResourceRegistry for {@code transaction}. If there is no such registry file, a new one is created. * @throws SystemException if an unexpected failure occurs when creating the registry file */ XAResourceRegistry getXAResourceRegistryFile(LocalTransaction transaction) throws SystemException { XAResourceRegistry registry = (XAResourceRegistry) transaction.getResource(XA_RESOURCE_REGISTRY_KEY); if (registry != null) return registry; registry = new XAResourceRegistryFile(transaction.getXid()); transaction.putResource(XA_RESOURCE_REGISTRY_KEY, registry); return registry; }
return xaResource; final XAResourceRegistry resourceRegistry = transaction.getProvider().getXAResourceRegistry(transaction); xaResource = new SubordinateXAResource(location, parentName, resourceRegistry); if (resourceRegistry != null) { resourceRegistry.addResource(xaResource, location); if (! transaction.enlistResource(xaResource)) { throw Log.log.couldNotEnlist(); int status = transaction.getStatus(); if (status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK) try { transaction.registerSynchronization(new Synchronization() { public void beforeCompletion() { try { status = transaction.getStatus(); if (status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK) { throw e;
/** * Outflow the given local transaction to the given location. The returned handle * must be used to confirm or forget the enlistment attempt either immediately or at some point in the future; * failure to do so may cause the transaction to be rolled back with an error. * * @param location the location to outflow to (must not be {@code null}) * @param transaction the transaction (must not be {@code null}) * @return the enlistment handle (not {@code null}) * @throws SystemException if the transaction manager fails for some reason * @throws RollbackException if the transaction has been rolled back in the meantime * @throws IllegalStateException if no transaction is active * @throws UnsupportedOperationException if the provider for the location does not support outflow */ public XAOutflowHandle outflowTransaction(final URI location, final LocalTransaction transaction) throws SystemException, IllegalStateException, UnsupportedOperationException, RollbackException { Assert.checkNotNullParam("location", location); Assert.checkNotNullParam("transaction", transaction); XAOutflowedResources outflowedResources = getOutflowedResources(transaction); if (outflowedResources == null) { synchronized (transaction.getOutflowLock()) { outflowedResources = getOutflowedResources(transaction); if (outflowedResources == null) { transaction.putResource(outflowKey, outflowedResources = new XAOutflowedResources(transaction)); } } } SubordinateXAResource resource = outflowedResources.getOrEnlist(location, transaction.getParentName()); return resource.addHandle(resource.getXid()); }
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, SystemException { if (isImported()) { throw Log.log.commitOnImported(); } try { owner.getProvider().commitLocal(transaction); } catch (RollbackException re) { addRollbackExceptions(re); throw re; } finally { final XAOutflowedResources outflowedResources = RemoteTransactionContext.getOutflowedResources(this); if (outflowedResources == null || outflowedResources.getEnlistedSubordinates() == 0) { // we can drop the mapping, since we are both a master and have no enlisted subordinates owner.getProvider().dropLocal(transaction); } } }
public boolean enlistResource(final XAResource xaRes) throws RollbackException, IllegalStateException, SystemException { Assert.checkNotNullParam("xaRes", xaRes); final int estimatedRemainingTime = max(1, getEstimatedRemainingTime()); try { xaRes.setTransactionTimeout(estimatedRemainingTime); } catch (XAException e) { throw Log.log.setTimeoutFailed(estimatedRemainingTime, e); } return transaction.enlistResource(xaRes); }
static XAOutflowedResources getOutflowedResources(final LocalTransaction transaction) { return (XAOutflowedResources) transaction.getResource(outflowKey); }
public boolean equals(final Object obj) { return obj instanceof LocalTransaction && equals((LocalTransaction) obj); }
return xaResource; final XAResourceRegistry resourceRegistry = transaction.getProvider().getXAResourceRegistry(transaction); xaResource = new SubordinateXAResource(location, parentName, resourceRegistry); if (resourceRegistry != null) { resourceRegistry.addResource(xaResource, location); if (! transaction.enlistResource(xaResource)) { throw Log.log.couldNotEnlist(); int status = transaction.getStatus(); if (status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK) try { transaction.registerSynchronization(new Synchronization() { public void beforeCompletion() { try { status = transaction.getStatus(); if (status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK) { throw e;
/** * Returns the XAResourceRegistry file for {@code transaction}. * * @param transaction the transaction * @return the XAResourceRegistry for {@code transaction}. If there is no such registry file, a new one is created. * @throws SystemException if an unexpected failure occurs when creating the registry file */ XAResourceRegistry getXAResourceRegistryFile(LocalTransaction transaction) throws SystemException { XAResourceRegistry registry = (XAResourceRegistry) transaction.getResource(XA_RESOURCE_REGISTRY_KEY); if (registry != null) return registry; registry = new XAResourceRegistryFile(transaction.getXid()); transaction.putResource(XA_RESOURCE_REGISTRY_KEY, registry); return registry; }
/** * Outflow the given local transaction to the given location. The returned handle * must be used to confirm or forget the enlistment attempt either immediately or at some point in the future; * failure to do so may cause the transaction to be rolled back with an error. * * @param location the location to outflow to (must not be {@code null}) * @param transaction the transaction (must not be {@code null}) * @return the enlistment handle (not {@code null}) * @throws SystemException if the transaction manager fails for some reason * @throws RollbackException if the transaction has been rolled back in the meantime * @throws IllegalStateException if no transaction is active * @throws UnsupportedOperationException if the provider for the location does not support outflow */ public XAOutflowHandle outflowTransaction(final URI location, final LocalTransaction transaction) throws SystemException, IllegalStateException, UnsupportedOperationException, RollbackException { Assert.checkNotNullParam("location", location); Assert.checkNotNullParam("transaction", transaction); XAOutflowedResources outflowedResources = getOutflowedResources(transaction); if (outflowedResources == null) { synchronized (transaction.getOutflowLock()) { outflowedResources = getOutflowedResources(transaction); if (outflowedResources == null) { transaction.putResource(outflowKey, outflowedResources = new XAOutflowedResources(transaction)); } } } SubordinateXAResource resource = outflowedResources.getOrEnlist(location, transaction.getParentName()); return resource.addHandle(resource.getXid()); }
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, SystemException { if (isImported()) { throw Log.log.commitOnImported(); } try { owner.getProvider().commitLocal(transaction); } catch (RollbackException re) { addRollbackExceptions(re); throw re; } finally { final XAOutflowedResources outflowedResources = RemoteTransactionContext.getOutflowedResources(this); if (outflowedResources == null || outflowedResources.getEnlistedSubordinates() == 0) { // we can drop the mapping, since we are both a master and have no enlisted subordinates owner.getProvider().dropLocal(transaction); } } }
public boolean enlistResource(final XAResource xaRes) throws RollbackException, IllegalStateException, SystemException { Assert.checkNotNullParam("xaRes", xaRes); final int estimatedRemainingTime = max(1, getEstimatedRemainingTime()); try { xaRes.setTransactionTimeout(estimatedRemainingTime); } catch (XAException e) { throw Log.log.setTimeoutFailed(estimatedRemainingTime, e); } return transaction.enlistResource(xaRes); }
static XAOutflowedResources getOutflowedResources(final LocalTransaction transaction) { return (XAOutflowedResources) transaction.getResource(outflowKey); }
public boolean equals(final Object obj) { return obj instanceof LocalTransaction && equals((LocalTransaction) obj); }
return xaResource; final XAResourceRegistry resourceRegistry = transaction.getProvider().getXAResourceRegistry(transaction); xaResource = new SubordinateXAResource(location, parentName, resourceRegistry); if (resourceRegistry != null) { resourceRegistry.addResource(xaResource, location); if (! transaction.enlistResource(xaResource)) { throw Log.log.couldNotEnlist(); int status = transaction.getStatus(); if (status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK) try { transaction.registerSynchronization(new Synchronization() { public void beforeCompletion() { try { status = transaction.getStatus(); if (status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK) { throw e;