/** Same comment as for {@link #prepare(javax.transaction.xa.Xid)} applies for commit. */
 public void commit(Xid externalXid, boolean isOnePhase) throws XAException {
   Xid xid = convertXid(externalXid);
   LocalXaTransaction localTransaction = getLocalTransactionAndValidate(xid);
   if (trace)
     log.tracef(
         "Committing transaction %s. One phase? %s",
         localTransaction.getGlobalTransaction(), isOnePhase);
   if (isOnePhase && !configuration.isOnePhaseCommit()) {
     // isOnePhase being true means that we're the only participant in the distributed transaction
     // and TM does the
     // 1PC optimization. We run a 2PC though, as running only 1PC has a high chance of leaving the
     // cluster in
     // inconsistent state.
     try {
       txCoordinator.prepare(localTransaction);
       txCoordinator.commit(localTransaction, false);
     } catch (XAException e) {
       if (trace)
         log.tracef("Couldn't commit 1PC transaction %s, trying to rollback.", localTransaction);
       try {
         rollback(xid);
         throw new XAException(XAException.XA_HEURRB); // this is a heuristic rollback
       } catch (XAException e1) {
         log.couldNotRollbackPrepared1PcTransaction(localTransaction, e1);
         // inform the TM that a resource manager error has occurred in the transaction branch
         // (XAER_RMERR).
         throw new XAException(XAException.XAER_RMERR);
       }
     }
   } else {
     txCoordinator.commit(localTransaction, configuration.isOnePhaseCommit());
   }
   forgetSuccessfullyCompletedTransaction(recoveryManager, xid, localTransaction);
 }
 @Override
 public void beforeCompletion() {
   log.tracef("beforeCompletion called for %s", localTransaction);
   try {
     txCoordinator.prepare(localTransaction);
   } catch (XAException e) {
     throw new CacheException(
         "Could not prepare. ", e); // todo shall we just swallow this exception?
   }
 }
 /**
  * This can be call for any transaction object. See Section 3.4.6 (Resource Sharing) from JTA spec
  * v1.1.
  */
 public int prepare(Xid externalXid) throws XAException {
   Xid xid = convertXid(externalXid);
   LocalXaTransaction localTransaction = getLocalTransactionAndValidate(xid);
   if (!configuration.isOnePhaseCommit()) {
     return txCoordinator.prepare(localTransaction);
   } else {
     if (trace) log.tracef("Skipping prepare as we're configured to run 1PC. Xid=%s", externalXid);
     return XA_OK;
   }
 }