Example #1
0
  private XATransactionContext getTransactionContext() {
    try {
      Transaction transaction = getCurrentTransaction();
      EhcacheXAResourceImpl xaResource =
          (EhcacheXAResourceImpl) transactionToXAResourceMap.get(transaction);
      if (xaResource == null) {
        return null;
      }
      XATransactionContext transactionContext = xaResource.getCurrentTransactionContext();

      if (transactionContext == null) {
        transactionManagerLookup.register(xaResource, false);
        LOG.debug("creating new XA context");
        transactionContext = xaResource.createTransactionContext();
        xaResource.addTwoPcExecutionListener(new UnregisterXAResource());
      } else {
        transactionContext = xaResource.getCurrentTransactionContext();
      }

      LOG.debug("using XA context {}", transactionContext);
      return transactionContext;
    } catch (SystemException e) {
      throw new TransactionException("cannot get the current transaction", e);
    } catch (RollbackException e) {
      throw new TransactionException("transaction rolled back", e);
    }
  }
Example #2
0
 /**
  * Get or create the XAResource of this XA store
  *
  * @return the EhcacheXAResource of this store
  * @throws SystemException when something goes wrong with the transaction manager
  */
 public EhcacheXAResourceImpl getOrCreateXAResource() throws SystemException {
   Transaction transaction = getCurrentTransaction();
   EhcacheXAResourceImpl xaResource =
       (EhcacheXAResourceImpl) transactionToXAResourceMap.get(transaction);
   if (xaResource == null) {
     LOG.debug("creating new XAResource");
     xaResource =
         new EhcacheXAResourceImpl(
             cache,
             underlyingStore,
             transactionManagerLookup,
             softLockManager,
             transactionIdFactory,
             copyStrategy,
             commitObserver,
             rollbackObserver,
             recoveryObserver);
     transactionToXAResourceMap.put(transaction, xaResource);
     xaResource.addTwoPcExecutionListener(new CleanupXAResource(getCurrentTransaction()));
   }
   return xaResource;
 }