Ejemplo n.º 1
0
 /** 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);
 }