Java Code Examples for javax.transaction.xa.XAException#XA_HEURRB

The following examples show how to use javax.transaction.xa.XAException#XA_HEURRB . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleTransactionStrategy.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void rollback(Xid xid)
		throws HeuristicMixedException, HeuristicCommitException, IllegalStateException, SystemException {
	try {
		this.terminator.rollback(xid);
	} catch (XAException xaex) {
		switch (xaex.errorCode) {
		case XAException.XA_HEURRB:
			break;
		case XAException.XA_HEURMIX:
			throw new HeuristicMixedException();
		case XAException.XA_HEURCOM:
			throw new HeuristicCommitException();
		default:
			logger.error("Unknown state in rollingback transaction phase.", xaex);
			throw new SystemException();
		}
	} catch (RuntimeException rex) {
		logger.error("Unknown state in rollingback transaction phase.", rex);
		throw new SystemException();
	}
}
 
Example 2
Source File: SimpleTransactionStrategy.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void commit(Xid xid, boolean onePhaseCommit)
		throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
	try {
		this.terminator.commit(xid, onePhaseCommit);
	} catch (XAException xaex) {
		switch (xaex.errorCode) {
		case XAException.XA_HEURCOM:
			break;
		case XAException.XA_HEURMIX:
			throw new HeuristicMixedException();
		case XAException.XA_HEURRB:
			throw new HeuristicRollbackException();
		default:
			logger.error("Unknown state in committing transaction phase.", xaex);
			throw new SystemException();
		}
	} catch (RuntimeException rex) {
		logger.error("Unknown state in committing transaction phase.", rex);
		throw new SystemException();
	}
}
 
Example 3
Source File: XATestUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Return a string for the error code of the XAException.
*/
public static String errorCode(XAException e)
{
    String error;
    switch(e.errorCode)
    {
    case XAException.XA_HEURCOM : error = "XA_HEURCOM "; break;
    case XAException.XA_HEURHAZ : error = "XA_HEURHAZ"; break;
    case XAException.XA_HEURMIX : error = "XA_HEURMIX"; break;
    case XAException.XA_HEURRB : error = "XA_HEURRB "; break;
    case XAException.XA_NOMIGRATE : error = "XA_NOMIGRATE "; break;
    case XAException.XA_RBCOMMFAIL : error = "XA_RBCOMMFAIL "; break;
    case XAException.XA_RBDEADLOCK : error = "XA_RBDEADLOCK "; break;
    case XAException.XA_RBINTEGRITY : error = "XA_RBINTEGRITY "; break;
    case XAException.XA_RBOTHER : error = "XA_RBOTHER "; break;
    case XAException.XA_RBPROTO : error = "XA_RBPROTO "; break;
    case XAException.XA_RBROLLBACK : error = "XA_RBROLLBACK "; break;
    case XAException.XA_RBTIMEOUT : error = "XA_RBTIMEOUT "; break;
    case XAException.XA_RBTRANSIENT : error = "XA_RBTRANSIENT "; break;
    case XAException.XA_RDONLY : error = "XA_RDONLY "; break;
    case XAException.XA_RETRY : error = "XA_RETRY "; break;
    case XAException.XAER_ASYNC : error = "XAER_ASYNC "; break;
    case XAException.XAER_DUPID : error = "XAER_DUPID "; break;
    case XAException.XAER_INVAL : error = "XAER_INVAL "; break;
    case XAException.XAER_NOTA : error = "XAER_NOTA "; break;
    case XAException.XAER_OUTSIDE : error = "XAER_OUTSIDE "; break;
    case XAException.XAER_PROTO : error = "XAER_PROTO "; break;
    case XAException.XAER_RMERR : error = "XAER_RMERR "; break;
    case XAException.XAER_RMFAIL : error = "XAER_RMFAIL "; break;
    default: error = Integer.toString(e.errorCode); break;
    }        
    return error;
}
 
Example 4
Source File: XATestUtil.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Return a string for the error code of the XAException.
*/
public static String errorCode(XAException e)
{
    String error;
    switch(e.errorCode)
    {
    case XAException.XA_HEURCOM : error = "XA_HEURCOM "; break;
    case XAException.XA_HEURHAZ : error = "XA_HEURHAZ"; break;
    case XAException.XA_HEURMIX : error = "XA_HEURMIX"; break;
    case XAException.XA_HEURRB : error = "XA_HEURRB "; break;
    case XAException.XA_NOMIGRATE : error = "XA_NOMIGRATE "; break;
    case XAException.XA_RBCOMMFAIL : error = "XA_RBCOMMFAIL "; break;
    case XAException.XA_RBDEADLOCK : error = "XA_RBDEADLOCK "; break;
    case XAException.XA_RBINTEGRITY : error = "XA_RBINTEGRITY "; break;
    case XAException.XA_RBOTHER : error = "XA_RBOTHER "; break;
    case XAException.XA_RBPROTO : error = "XA_RBPROTO "; break;
    case XAException.XA_RBROLLBACK : error = "XA_RBROLLBACK "; break;
    case XAException.XA_RBTIMEOUT : error = "XA_RBTIMEOUT "; break;
    case XAException.XA_RBTRANSIENT : error = "XA_RBTRANSIENT "; break;
    case XAException.XA_RDONLY : error = "XA_RDONLY "; break;
    case XAException.XA_RETRY : error = "XA_RETRY "; break;
    case XAException.XAER_ASYNC : error = "XAER_ASYNC "; break;
    case XAException.XAER_DUPID : error = "XAER_DUPID "; break;
    case XAException.XAER_INVAL : error = "XAER_INVAL "; break;
    case XAException.XAER_NOTA : error = "XAER_NOTA "; break;
    case XAException.XAER_OUTSIDE : error = "XAER_OUTSIDE "; break;
    case XAException.XAER_PROTO : error = "XAER_PROTO "; break;
    case XAException.XAER_RMERR : error = "XAER_RMERR "; break;
    case XAException.XAER_RMFAIL : error = "XAER_RMFAIL "; break;
    default: error = Integer.toString(e.errorCode); break;
    }        
    return error;
}
 
Example 5
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void invokeOnePhaseCommit(XAResourceArchive archive) throws XAException {
	try {
		archive.commit(archive.getXid(), true);
	} catch (XAException xaex) {
		switch (xaex.errorCode) {
		case XAException.XA_HEURCOM:
		case XAException.XA_HEURHAZ:
		case XAException.XA_HEURMIX:
		case XAException.XA_HEURRB:
			logger.warn("An error occurred in one phase commit: {}, transaction has been completed!",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			throw xaex;
		case XAException.XAER_RMFAIL:
			logger.warn("An error occurred in one phase commit: {}",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			throw xaex;
		case XAException.XAER_NOTA:
		case XAException.XAER_INVAL:
		case XAException.XAER_PROTO:
			logger.warn("An error occurred in one phase commit: {}",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			throw new XAException(XAException.XAER_RMERR);
		case XAException.XAER_RMERR:
		case XAException.XA_RBCOMMFAIL:
		case XAException.XA_RBDEADLOCK:
		case XAException.XA_RBINTEGRITY:
		case XAException.XA_RBOTHER:
		case XAException.XA_RBPROTO:
		case XAException.XA_RBROLLBACK:
		case XAException.XA_RBTIMEOUT:
		case XAException.XA_RBTRANSIENT:
		default:
			logger.warn("An error occurred in one phase commit: {}, transaction has been rolled back!",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			throw new XAException(XAException.XA_HEURRB);
		}
	}
}
 
Example 6
Source File: XAResourceArchive.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void commit(Xid ignore, boolean onePhase) throws XAException {
	if (this.readonly) {
		// ignore
	} else if (this.committed) {
		// ignore
	} else if (this.rolledback) {
		throw new XAException(XAException.XA_HEURRB);
	} else {
		descriptor.commit(xid, onePhase);
	}
}
 
Example 7
Source File: XATestUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Return a string for the error code of the XAException.
*/
public static String errorCode(XAException e)
{
    String error;
    switch(e.errorCode)
    {
    case XAException.XA_HEURCOM : error = "XA_HEURCOM "; break;
    case XAException.XA_HEURHAZ : error = "XA_HEURHAZ"; break;
    case XAException.XA_HEURMIX : error = "XA_HEURMIX"; break;
    case XAException.XA_HEURRB : error = "XA_HEURRB "; break;
    case XAException.XA_NOMIGRATE : error = "XA_NOMIGRATE "; break;
    case XAException.XA_RBCOMMFAIL : error = "XA_RBCOMMFAIL "; break;
    case XAException.XA_RBDEADLOCK : error = "XA_RBDEADLOCK "; break;
    case XAException.XA_RBINTEGRITY : error = "XA_RBINTEGRITY "; break;
    case XAException.XA_RBOTHER : error = "XA_RBOTHER "; break;
    case XAException.XA_RBPROTO : error = "XA_RBPROTO "; break;
    case XAException.XA_RBROLLBACK : error = "XA_RBROLLBACK "; break;
    case XAException.XA_RBTIMEOUT : error = "XA_RBTIMEOUT "; break;
    case XAException.XA_RBTRANSIENT : error = "XA_RBTRANSIENT "; break;
    case XAException.XA_RDONLY : error = "XA_RDONLY "; break;
    case XAException.XA_RETRY : error = "XA_RETRY "; break;
    case XAException.XAER_ASYNC : error = "XAER_ASYNC "; break;
    case XAException.XAER_DUPID : error = "XAER_DUPID "; break;
    case XAException.XAER_INVAL : error = "XAER_INVAL "; break;
    case XAException.XAER_NOTA : error = "XAER_NOTA "; break;
    case XAException.XAER_OUTSIDE : error = "XAER_OUTSIDE "; break;
    case XAException.XAER_PROTO : error = "XAER_PROTO "; break;
    case XAException.XAER_RMERR : error = "XAER_RMERR "; break;
    case XAException.XAER_RMFAIL : error = "XAER_RMFAIL "; break;
    default: error = Integer.toString(e.errorCode); break;
    }        
    return error;
}
 
Example 8
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void invokeCompensableCommitIfLocalTransaction(CompensableTransaction compensable)
		throws HeuristicRollbackException, SystemException {

	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();
	Transaction transaction = compensable.getTransaction();
	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();

	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);
		transactionCoordinator.commit(transactionXid, true);
	} catch (XAException xaex) {
		switch (xaex.errorCode) {
		case XAException.XA_HEURCOM:
			transactionCoordinator.forgetQuietly(transactionXid);
			break;
		case XAException.XA_HEURRB:
			transactionCoordinator.forgetQuietly(transactionXid);
			HeuristicRollbackException hrex = new HeuristicRollbackException();
			hrex.initCause(xaex);
			throw hrex;
		default:
			transactionCoordinator.forgetQuietly(transactionXid); // TODO
			SystemException sysEx = new SystemException(xaex.errorCode);
			sysEx.initCause(xaex);
			throw sysEx;
		}
	}
}
 
Example 9
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void invokeTransactionCommitIfLocalTransaction(CompensableTransaction compensable) throws RollbackException,
		HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {

	Transaction transaction = compensable.getTransaction();
	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();
	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();

	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);
		transactionCoordinator.commit(transactionXid, true);
	} catch (XAException xaEx) {
		switch (xaEx.errorCode) {
		case XAException.XA_HEURCOM:
			transactionCoordinator.forgetQuietly(transactionXid);
			break;
		case XAException.XA_HEURRB:
			transactionCoordinator.forgetQuietly(transactionXid);
			HeuristicRollbackException hrex = new HeuristicRollbackException();
			hrex.initCause(xaEx);
			throw hrex;
		case XAException.XA_HEURMIX:
			transactionCoordinator.forgetQuietly(transactionXid);
			HeuristicMixedException hmex = new HeuristicMixedException();
			hmex.initCause(xaEx);
			throw hmex;
		case XAException.XAER_RMERR:
		default:
			transactionCoordinator.forgetQuietly(transactionXid); // TODO
			SystemException sysEx = new SystemException(xaEx.errorCode);
			sysEx.initCause(xaEx);
			throw sysEx;
		}
	}

}
 
Example 10
Source File: ServerSessionImpl.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void xaCommit(final Xid xid, final boolean onePhase) throws Exception {
   this.pendingTX = null;

   if (tx != null && tx.getXid().equals(xid)) {
      final String msg = "Cannot commit, session is currently doing work in transaction " + tx.getXid();

      throw new ActiveMQXAException(XAException.XAER_PROTO, msg);
   } else {
      Transaction theTx = resourceManager.removeTransaction(xid);

      if (logger.isTraceEnabled()) {
         logger.trace("XAcommit into " + theTx + ", xid=" + xid);
      }

      if (theTx == null) {
         // checked heuristic committed transactions
         if (resourceManager.getHeuristicCommittedTransactions().contains(xid)) {
            throw new ActiveMQXAException(XAException.XA_HEURCOM, "transaction has been heuristically committed: " + xid);
         } else if (resourceManager.getHeuristicRolledbackTransactions().contains(xid)) {
            // checked heuristic rolled back transactions
            throw new ActiveMQXAException(XAException.XA_HEURRB, "transaction has been heuristically rolled back: " + xid);
         } else {
            if (logger.isTraceEnabled()) {
               logger.trace("XAcommit into " + theTx + ", xid=" + xid + " cannot find it");
            }

            throw new ActiveMQXAException(XAException.XAER_NOTA, "Cannot find xid in resource manager: " + xid);
         }
      } else {
         if (theTx.getState() == Transaction.State.SUSPENDED) {
            // Put it back
            resourceManager.putTransaction(xid, theTx);

            throw new ActiveMQXAException(XAException.XAER_PROTO, "Cannot commit transaction, it is suspended " + xid);
         } else {
            theTx.commit(onePhase);
         }
      }
   }
}
 
Example 11
Source File: ServerSessionImpl.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void xaRollback(final Xid xid) throws Exception {
   this.pendingTX = null;

   if (tx != null && tx.getXid().equals(xid)) {
      final String msg = "Cannot roll back, session is currently doing work in a transaction " + tx.getXid();

      throw new ActiveMQXAException(XAException.XAER_PROTO, msg);
   } else {
      Transaction theTx = resourceManager.removeTransaction(xid);
      if (logger.isTraceEnabled()) {
         logger.trace("xarollback into " + theTx);
      }

      if (theTx == null) {
         // checked heuristic committed transactions
         if (resourceManager.getHeuristicCommittedTransactions().contains(xid)) {
            throw new ActiveMQXAException(XAException.XA_HEURCOM, "transaction has ben heuristically committed: " + xid);
         } else if (resourceManager.getHeuristicRolledbackTransactions().contains(xid)) {
            // checked heuristic rolled back transactions
            throw new ActiveMQXAException(XAException.XA_HEURRB, "transaction has ben heuristically rolled back: " + xid);
         } else {
            if (logger.isTraceEnabled()) {
               logger.trace("xarollback into " + theTx + ", xid=" + xid + " forcing a rollback regular");
            }

            try {
               // jbpapp-8845
               // This could have happened because the TX timed out,
               // at this point we would be better on rolling back this session as a way to prevent consumers from holding their messages
               this.rollback(false);
            } catch (Exception e) {
               ActiveMQServerLogger.LOGGER.unableToRollbackOnTxTimedOut(e);
            }

            throw new ActiveMQXAException(XAException.XAER_NOTA, "Cannot find xid in resource manager: " + xid);
         }
      } else {
         if (theTx.getState() == Transaction.State.SUSPENDED) {
            if (logger.isTraceEnabled()) {
               logger.trace("xarollback into " + theTx + " sending tx back as it was suspended");
            }

            // Put it back
            resourceManager.putTransaction(xid, tx);

            throw new ActiveMQXAException(XAException.XAER_PROTO, "Cannot rollback transaction, it is suspended " + xid);
         } else {
            doRollback(false, false, theTx);
         }
      }
   }
}
 
Example 12
Source File: xaHelper.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void handleException(Throwable t) throws SQLException
{
	if (t instanceof SQLException)
	{
		// let ij handle it
		throw (SQLException)t;
	}
	if (t instanceof XAException)
	{
		int errorCode = ((XAException)t).errorCode;
		String error = LocalizedResource.getMessage("IJ_IlleValu");

		// XA_RBBASE 100
		// XA_RBROLLBACK 100
		// XA_RBCOMMFAIL 101
		// XA_RBDEADLOCK 102
		// XA_RBINTEGRITY 103
		// XA_RBOTHER 104
		// XA_RBPROTO 105
		// XA_RBTIMEOUT 106
		// XA_RBTRANSIENT 107
		// XA_RBEND 107
		//
		// XA_RDONLY 3
		// XA_RETRY 4
		// XA_HEURMIX 5
		// XA_HEURRB 6
		// XA_HEURCOM 7
		// XA_HEURHAZ 8
		// XA_NOMIGRATE 9
		//
		// XAER_ASYNC -2
		// XAER_RMERR -3
		// XAER_NOTA -4
		// XAER_INVAL -5
		// XAER_PROTO -6
		// XAER_RMFAIL -7
		// XAER_DUPID -8
		// XAER_OUTSIDE -9

		switch(errorCode)
		{
		case XAException.XA_HEURCOM : error = "XA_HEURCOM "; break;
		case XAException.XA_HEURHAZ : error = "XA_HEURHAZ"; break;
		case XAException.XA_HEURMIX : error = "XA_HEURMIX"; break;
		case XAException.XA_HEURRB : error = "XA_HEURRB "; break;
		case XAException.XA_NOMIGRATE : error = "XA_NOMIGRATE "; break;
			// case XAException.XA_RBBASE : error = "XA_RBBASE "; break;
		case XAException.XA_RBCOMMFAIL : error = "XA_RBCOMMFAIL "; break;
		case XAException.XA_RBDEADLOCK : error = "XA_RBDEADLOCK "; break;
			// case XAException.XA_RBEND : error = "XA_RBEND "; break;
		case XAException.XA_RBINTEGRITY : error = "XA_RBINTEGRITY "; break;
		case XAException.XA_RBOTHER : error = "XA_RBOTHER "; break;
		case XAException.XA_RBPROTO : error = "XA_RBPROTO "; break;
		case XAException.XA_RBROLLBACK : error = "XA_RBROLLBACK "; break;
		case XAException.XA_RBTIMEOUT : error = "XA_RBTIMEOUT "; break;
		case XAException.XA_RBTRANSIENT : error = "XA_RBTRANSIENT "; break;
		case XAException.XA_RDONLY : error = "XA_RDONLY "; break;
		case XAException.XA_RETRY : error = "XA_RETRY "; break;
		case XAException.XAER_ASYNC : error = "XAER_ASYNC "; break;
		case XAException.XAER_DUPID : error = "XAER_DUPID "; break;
		case XAException.XAER_INVAL : error = "XAER_INVAL "; break;
		case XAException.XAER_NOTA : error = "XAER_NOTA "; break;
		case XAException.XAER_OUTSIDE : error = "XAER_OUTSIDE "; break;
		case XAException.XAER_PROTO : error = "XAER_PROTO "; break;
		case XAException.XAER_RMERR : error = "XAER_RMERR "; break;
		case XAException.XAER_RMFAIL : error = "XAER_RMFAIL "; break;
		}
		//t.printStackTrace(System.out);
		throw new ijException(error);

	}
	else // StandardException or run time exception, log it first
	{
		String info = LocalizedResource.getMessage("IJ_01SeeLog", t.toString(), t.getMessage());
		//		t.printStackTrace(System.out);
		throw new ijException(info);
	}
}
 
Example 13
Source File: xaHelper.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
private void handleException(Throwable t) throws SQLException
{
	if (t instanceof SQLException)
	{
		// let ij handle it
		throw (SQLException)t;
	}
	if (t instanceof XAException)
	{
		int errorCode = ((XAException)t).errorCode;
		String error = LocalizedResource.getMessage("IJ_IlleValu");

		// XA_RBBASE 100
		// XA_RBROLLBACK 100
		// XA_RBCOMMFAIL 101
		// XA_RBDEADLOCK 102
		// XA_RBINTEGRITY 103
		// XA_RBOTHER 104
		// XA_RBPROTO 105
		// XA_RBTIMEOUT 106
		// XA_RBTRANSIENT 107
		// XA_RBEND 107
		//
		// XA_RDONLY 3
		// XA_RETRY 4
		// XA_HEURMIX 5
		// XA_HEURRB 6
		// XA_HEURCOM 7
		// XA_HEURHAZ 8
		// XA_NOMIGRATE 9
		//
		// XAER_ASYNC -2
		// XAER_RMERR -3
		// XAER_NOTA -4
		// XAER_INVAL -5
		// XAER_PROTO -6
		// XAER_RMFAIL -7
		// XAER_DUPID -8
		// XAER_OUTSIDE -9

		switch(errorCode)
		{
		case XAException.XA_HEURCOM : error = "XA_HEURCOM "; break;
		case XAException.XA_HEURHAZ : error = "XA_HEURHAZ"; break;
		case XAException.XA_HEURMIX : error = "XA_HEURMIX"; break;
		case XAException.XA_HEURRB : error = "XA_HEURRB "; break;
		case XAException.XA_NOMIGRATE : error = "XA_NOMIGRATE "; break;
			// case XAException.XA_RBBASE : error = "XA_RBBASE "; break;
		case XAException.XA_RBCOMMFAIL : error = "XA_RBCOMMFAIL "; break;
		case XAException.XA_RBDEADLOCK : error = "XA_RBDEADLOCK "; break;
			// case XAException.XA_RBEND : error = "XA_RBEND "; break;
		case XAException.XA_RBINTEGRITY : error = "XA_RBINTEGRITY "; break;
		case XAException.XA_RBOTHER : error = "XA_RBOTHER "; break;
		case XAException.XA_RBPROTO : error = "XA_RBPROTO "; break;
		case XAException.XA_RBROLLBACK : error = "XA_RBROLLBACK "; break;
		case XAException.XA_RBTIMEOUT : error = "XA_RBTIMEOUT "; break;
		case XAException.XA_RBTRANSIENT : error = "XA_RBTRANSIENT "; break;
		case XAException.XA_RDONLY : error = "XA_RDONLY "; break;
		case XAException.XA_RETRY : error = "XA_RETRY "; break;
		case XAException.XAER_ASYNC : error = "XAER_ASYNC "; break;
		case XAException.XAER_DUPID : error = "XAER_DUPID "; break;
		case XAException.XAER_INVAL : error = "XAER_INVAL "; break;
		case XAException.XAER_NOTA : error = "XAER_NOTA "; break;
		case XAException.XAER_OUTSIDE : error = "XAER_OUTSIDE "; break;
		case XAException.XAER_PROTO : error = "XAER_PROTO "; break;
		case XAException.XAER_RMERR : error = "XAER_RMERR "; break;
		case XAException.XAER_RMFAIL : error = "XAER_RMFAIL "; break;
		}
		//t.printStackTrace(System.out);
		throw new ijException(error);

	}
	else // StandardException or run time exception, log it first
	{
		String info = LocalizedResource.getMessage("IJ_01SeeLog", t.toString(), t.getMessage());
		//		t.printStackTrace(System.out);
		throw new ijException(info);
	}
}
 
Example 14
Source File: XATerminatorOptd.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void fireOnePhaseCommit(Xid xid) throws XAException {
	if (archive.isCommitted() && archive.isRolledback()) {
		throw new XAException(XAException.XA_HEURMIX);
	} else if (archive.isCommitted()) {
		return;
	} else if (archive.isReadonly()) {
		throw new XAException(XAException.XA_RDONLY); // XAException.XAER_NOTA
	} else if (archive.isRolledback()) {
		throw new XAException(XAException.XA_HEURRB);
	}

	TransactionLogger transactionLogger = this.beanFactory.getTransactionLogger();

	boolean updateRequired = true;
	try {
		archive.commit(archive.getXid(), true);
		archive.setCommitted(true);
		archive.setCompleted(true);

		logger.info("{}> commit: xares= {}, branch= {}, opc= {}",
				ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()), archive,
				ByteUtils.byteArrayToString(archive.getXid().getBranchQualifier()), false);
	} catch (XAException xaex) {
		switch (xaex.errorCode) {
		case XAException.XA_HEURCOM:
			archive.setHeuristic(true);
			archive.setCommitted(true);
			archive.setCompleted(true);
			break;
		case XAException.XA_HEURMIX:
			archive.setHeuristic(true);
			archive.setCommitted(true);
			archive.setRolledback(true);
			archive.setCompleted(true);
			throw xaex;
		case XAException.XA_HEURRB:
			archive.setHeuristic(true);
			archive.setRolledback(true);
			archive.setCompleted(true);
			throw xaex;
		case XAException.XA_HEURHAZ:
			archive.setHeuristic(true);
			throw xaex;
		case XAException.XAER_RMFAIL:
			logger.warn("An error occurred in one phase commit: {}",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			updateRequired = false;
			throw new XAException(XAException.XA_HEURHAZ);
		case XAException.XAER_NOTA:
		case XAException.XAER_INVAL:
		case XAException.XAER_PROTO:
			logger.warn("An error occurred in one phase commit: {}",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			updateRequired = false;
			throw new XAException(XAException.XAER_RMERR);
		case XAException.XAER_RMERR:
		case XAException.XA_RBCOMMFAIL:
		case XAException.XA_RBDEADLOCK:
		case XAException.XA_RBINTEGRITY:
		case XAException.XA_RBOTHER:
		case XAException.XA_RBPROTO:
		case XAException.XA_RBROLLBACK:
		case XAException.XA_RBTIMEOUT:
		case XAException.XA_RBTRANSIENT:
		default:
			logger.warn("An error occurred in one phase commit: {}, transaction has been rolled back!",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()));
			archive.setRolledback(true);
			archive.setCompleted(true);
			throw new XAException(XAException.XA_HEURRB);
		}
	} catch (RuntimeException rex) {
		logger.error("{}> Error occurred while committing xa-resource: xares= {}, branch= {}",
				ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()), archive,
				ByteUtils.byteArrayToString(archive.getXid().getBranchQualifier()), rex);
		updateRequired = false;
		throw new XAException(XAException.XA_HEURHAZ);
	} finally {
		if (updateRequired) {
			transactionLogger.updateParticipant(archive);
		}
	}
}
 
Example 15
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void fireOnePhaseCommit(Xid xid) throws XAException {

		if (this.resources.size() == 0) {
			throw new XAException(XAException.XA_RDONLY);
		} else if (this.resources.size() > 1) {
			this.rollback(xid);
			throw new XAException(XAException.XA_HEURRB);
		}

		TransactionLogger transactionLogger = this.beanFactory.getTransactionLogger();

		XAResourceArchive archive = this.resources.get(0);

		if (archive.isCommitted() && archive.isRolledback()) {
			throw new XAException(XAException.XA_HEURMIX);
		} else if (archive.isCommitted()) {
			return;
		} else if (archive.isReadonly()) {
			throw new XAException(XAException.XA_RDONLY);
		} else if (archive.isRolledback()) {
			throw new XAException(XAException.XA_HEURRB);
		}

		boolean updateRequired = true;
		try {
			this.invokeOnePhaseCommit(archive);

			archive.setCommitted(true);
			archive.setCompleted(true);

			logger.info("{}> commit: xares= {}, branch= {}, opc= {}",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()), archive,
					ByteUtils.byteArrayToString(archive.getXid().getBranchQualifier()), true);
		} catch (XAException xaex) {
			logger.error("{}> Error occurred while committing xa-resource: xares= {}, branch= {}, code= {}",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()), archive,
					ByteUtils.byteArrayToString(archive.getXid().getBranchQualifier()), xaex.errorCode, xaex);

			switch (xaex.errorCode) {
			case XAException.XA_HEURCOM:
				archive.setHeuristic(true);
				archive.setCommitted(true);
				archive.setCompleted(true);
				break;
			case XAException.XA_HEURHAZ:
				archive.setHeuristic(true);
				throw xaex;
			case XAException.XA_HEURMIX:
				archive.setHeuristic(true);
				archive.setCommitted(true);
				archive.setRolledback(true);
				archive.setCompleted(true);
				throw xaex;
			case XAException.XA_HEURRB:
				archive.setHeuristic(true);
				archive.setRolledback(true);
				archive.setCompleted(true);
				throw xaex;
			case XAException.XAER_RMFAIL:
				updateRequired = false;
				throw new XAException(XAException.XA_HEURHAZ);
			case XAException.XAER_RMERR:
			default:
				updateRequired = false;
				throw new XAException(XAException.XAER_RMERR);
			}
		} catch (RuntimeException rex) {
			logger.error("{}> Error occurred while committing xa-resource: xares= {}, branch= {}",
					ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()), archive,
					ByteUtils.byteArrayToString(archive.getXid().getBranchQualifier()), rex);
			updateRequired = false;
			throw new XAException(XAException.XA_HEURHAZ);
		} finally {
			if (updateRequired) {
				transactionLogger.updateParticipant(archive);
			}
		}
	}
 
Example 16
Source File: CompensableCoordinator.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void commit(Xid xid, boolean onePhase) throws XAException {
	this.checkParticipantReadyIfNecessary();

	if (xid == null) {
		throw new XAException(XAException.XAER_INVAL);
	} else if (onePhase == false) {
		throw new XAException(XAException.XAER_RMERR);
	}

	XidFactory xidFactory = this.beanFactory.getCompensableXidFactory();
	TransactionLock compensableLock = this.beanFactory.getCompensableLock();

	TransactionXid globalXid = xidFactory.createGlobalXid(xid.getGlobalTransactionId());

	CompensableTransaction transaction = null;
	boolean success = false;
	boolean locked = false;
	try {
		if ((locked = compensableLock.lockTransaction(globalXid, this.endpoint)) == false) {
			throw new XAException(XAException.XAER_RMERR);
		} // end-if ((locked = compensableLock.lockTransaction(globalXid, this.endpoint)) == false)

		transaction = this.invokeCommit(globalXid, onePhase);

		success = true;
	} catch (XAException xaex) {
		logger.error("Error occurred while committing transaction: {}." //
				, ByteUtils.byteArrayToString(xid.getGlobalTransactionId()), xaex);

		switch (xaex.errorCode) {
		case XAException.XA_HEURRB:
		case XAException.XA_HEURMIX:
		case XAException.XA_HEURCOM:
			success = true;
			break;
		}
		throw xaex; // throw XAException
	} catch (RuntimeException rex) {
		logger.error("Error occurred while committing transaction: {}." //
				, ByteUtils.byteArrayToString(xid.getGlobalTransactionId()), rex);

		throw new XAException(XAException.XAER_RMERR); // should never happen
	} finally {
		if (locked) {
			compensableLock.unlockTransaction(globalXid, this.endpoint);
		} // end-if (locked)
		if (success) {
			transaction.forgetQuietly(); // forget transaction
		} // end-if (success)
	}
}
 
Example 17
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void invokeTwoPhaseCommit(XAResourceArchive archive) throws XAException {
	try {
		archive.commit(archive.getXid(), false);
	} catch (XAException xaex) {
		// * @exception XAException An error has occurred. Possible XAExceptions
		// * are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR,
		// * XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
		// * <P>If the resource manager did not commit the transaction and the
		// * parameter onePhase is set to true, the resource manager may throw
		// * one of the XA_RB* exceptions. Upon return, the resource manager has
		// * rolled back the branch's work and has released all held resources.
		switch (xaex.errorCode) {
		case XAException.XA_HEURHAZ:
			// OSI-TP: The condition that arises when, as a result of communication failure with a
			// subordinate, the bound data of the subordinate's subtree are in an unknown state.

			// XA: Due to some failure, the work done on behalf of the specified
			// transaction branch may have been heuristically completed.
		case XAException.XA_HEURMIX:
			// Due to a heuristic decision, the work done on behalf of the specified
			// transaction branch was partially committed and partially rolled back.
		case XAException.XA_HEURCOM:
			// Due to a heuristic decision, the work done on behalf of
			// the specified transaction branch was committed.
		case XAException.XA_HEURRB:
			// Due to a heuristic decision, the work done on behalf of
			// the specified transaction branch was rolled back.
			throw xaex;
		case XAException.XAER_NOTA:
			// The specified XID is not known by the resource manager.
			throw new XAException(XAException.XA_RDONLY); // read-only
		case XAException.XAER_RMFAIL:
			// An error occurred that makes the resource manager unavailable.
			throw xaex;
		case XAException.XAER_INVAL:
			// Invalid arguments were specified.
		case XAException.XAER_PROTO:
			// The routine was invoked in an improper context.
			XAException error = new XAException(XAException.XAER_RMERR);
			error.initCause(xaex);
			throw error;
		case XAException.XAER_RMERR:
			// An error occurred in committing the work performed on behalf of the transaction
			// branch and the branch’s work has been rolled back. Note that returning this error
			// signals a catastrophic event to a transaction manager since other resource
			// managers may successfully commit their work on behalf of this branch. This error
			// should be returned only when a resource manager concludes that it can never
			// commit the branch and that it cannot hold the branch’s resources in a prepared
			// state. Otherwise, [XA_RETRY] should be returned.
			throw xaex; // TODO XA_RETRY is not defined by the JTA specification
		default:// XA_RB*
			XAException xarb = new XAException(XAException.XA_HEURRB);
			xarb.initCause(xaex);
			throw xarb;
		}
	}
}
 
Example 18
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void invokeRollback(XAResourceArchive archive) throws XAException {
	try {
		archive.rollback(archive.getXid());
	} catch (XAException xaex) {
		// * @exception XAException An error has occurred. Possible XAExceptions are
		// * XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR, XAER_RMFAIL,
		// * XAER_NOTA, XAER_INVAL, or XAER_PROTO.
		// * <p>If the transaction branch is already marked rollback-only the
		// * resource manager may throw one of the XA_RB* exceptions. Upon return,
		// * the resource manager has rolled back the branch's work and has released
		// * all held resources.
		switch (xaex.errorCode) {
		case XAException.XA_HEURHAZ:
			// Due to some failure, the work done on behalf of the specified transaction branch
			// may have been heuristically completed. A resource manager may return this
			// value only if it has successfully prepared xid.
		case XAException.XA_HEURMIX:
			// Due to a heuristic decision, the work done on behalf of the specified transaction
			// branch was partially committed and partially rolled back. A resource manager
			// may return this value only if it has successfully prepared xid.
		case XAException.XA_HEURCOM:
			// Due to a heuristic decision, the work done on behalf of the specified transaction
			// branch was committed. A resource manager may return this value only if it has
			// successfully prepared xid.
		case XAException.XA_HEURRB:
			// Due to a heuristic decision, the work done on behalf of the specified transaction
			// branch was rolled back. A resource manager may return this value only if it has
			// successfully prepared xid.
			throw xaex;
		case XAException.XAER_RMFAIL:
			// An error occurred that makes the resource manager unavailable.
			XAException xrhaz = new XAException(XAException.XA_HEURHAZ);
			xrhaz.initCause(xaex);
			throw xrhaz;
		case XAException.XAER_NOTA:
			// The specified XID is not known by the resource manager.
			if (archive.isReadonly()) {
				throw new XAException(XAException.XA_RDONLY);
			} else if (archive.getVote() == XAResourceArchive.DEFAULT_VOTE) {
				break; // rolled back
			} else if (archive.getVote() == XAResource.XA_RDONLY) {
				throw new XAException(XAException.XA_RDONLY);
			} else if (archive.getVote() == XAResource.XA_OK) {
				throw new XAException(XAException.XAER_RMERR);
			} else {
				throw new XAException(XAException.XAER_RMERR);
			}
		case XAException.XAER_PROTO:
			// The routine was invoked in an improper context.
		case XAException.XAER_INVAL:
			// Invalid arguments were specified.
			throw new XAException(XAException.XAER_RMERR);
		case XAException.XAER_RMERR:
			// An error occurred in rolling back the transaction branch. The resource manager is
			// free to forget about the branch when returning this error so long as all accessing
			// threads of control have been notified of the branch’s state.
		default: // XA_RB*
			// The resource manager has rolled back the transaction branch’s work and has
			// released all held resources. These values are typically returned when the
			// branch was already marked rollback-only.
			XAException xarb = new XAException(XAException.XA_HEURRB);
			xarb.initCause(xaex);
			throw xarb;
		}
	}
}
 
Example 19
Source File: XASupport.java    From jTDS with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Construct and throw an <code>XAException</code> with an explanatory message and the XA error code set.
 *
 * @param errorCode the XA Error code
 * @exception javax.transaction.xa.XAException
 *             the constructed exception
 */
public static void raiseXAException(int errorCode)
        throws XAException {
    String err = "xaerunknown";
    switch (errorCode) {
        case XAException.XA_RBROLLBACK:
            err = "xarbrollback";
            break;
        case XAException.XA_RBCOMMFAIL:
            err = "xarbcommfail";
            break;
        case XAException.XA_RBDEADLOCK:
            err = "xarbdeadlock";
            break;
        case XAException.XA_RBINTEGRITY:
            err = "xarbintegrity";
            break;
        case XAException.XA_RBOTHER:
            err = "xarbother";
            break;
        case XAException.XA_RBPROTO:
            err = "xarbproto";
            break;
        case XAException.XA_RBTIMEOUT:
            err = "xarbtimeout";
            break;
        case XAException.XA_RBTRANSIENT:
            err = "xarbtransient";
            break;
        case XAException.XA_NOMIGRATE:
            err = "xanomigrate";
            break;
        case XAException.XA_HEURHAZ:
            err = "xaheurhaz";
            break;
        case XAException.XA_HEURCOM:
            err = "xaheurcom";
            break;
        case XAException.XA_HEURRB:
            err = "xaheurrb";
            break;
        case XAException.XA_HEURMIX:
            err = "xaheurmix";
            break;
        case XAException.XA_RETRY:
            err = "xaretry";
            break;
        case XAException.XA_RDONLY:
            err = "xardonly";
            break;
        case XAException.XAER_ASYNC:
            err = "xaerasync";
            break;
        case XAException.XAER_NOTA:
            err = "xaernota";
            break;
        case XAException.XAER_INVAL:
            err = "xaerinval";
            break;
        case XAException.XAER_PROTO:
            err = "xaerproto";
            break;
        case XAException.XAER_RMERR:
            err = "xaerrmerr";
            break;
        case XAException.XAER_RMFAIL:
            err = "xaerrmfail";
            break;
        case XAException.XAER_DUPID:
            err = "xaerdupid";
            break;
        case XAException.XAER_OUTSIDE:
            err = "xaeroutside";
            break;
    }
    XAException e = new XAException(Messages.get("error.xaexception." + err));
    e.errorCode = errorCode;
    Logger.println("XAException: " + e.getMessage());
    throw e;
}
 
Example 20
Source File: xaHelper.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void handleException(Throwable t) throws SQLException
{
	if (t instanceof SQLException)
	{
		// let ij handle it
		throw (SQLException)t;
	}
	if (t instanceof XAException)
	{
		int errorCode = ((XAException)t).errorCode;
		String error = LocalizedResource.getMessage("IJ_IlleValu");

		// XA_RBBASE 100
		// XA_RBROLLBACK 100
		// XA_RBCOMMFAIL 101
		// XA_RBDEADLOCK 102
		// XA_RBINTEGRITY 103
		// XA_RBOTHER 104
		// XA_RBPROTO 105
		// XA_RBTIMEOUT 106
		// XA_RBTRANSIENT 107
		// XA_RBEND 107
		//
		// XA_RDONLY 3
		// XA_RETRY 4
		// XA_HEURMIX 5
		// XA_HEURRB 6
		// XA_HEURCOM 7
		// XA_HEURHAZ 8
		// XA_NOMIGRATE 9
		//
		// XAER_ASYNC -2
		// XAER_RMERR -3
		// XAER_NOTA -4
		// XAER_INVAL -5
		// XAER_PROTO -6
		// XAER_RMFAIL -7
		// XAER_DUPID -8
		// XAER_OUTSIDE -9

		switch(errorCode)
		{
		case XAException.XA_HEURCOM : error = "XA_HEURCOM "; break;
		case XAException.XA_HEURHAZ : error = "XA_HEURHAZ"; break;
		case XAException.XA_HEURMIX : error = "XA_HEURMIX"; break;
		case XAException.XA_HEURRB : error = "XA_HEURRB "; break;
		case XAException.XA_NOMIGRATE : error = "XA_NOMIGRATE "; break;
			// case XAException.XA_RBBASE : error = "XA_RBBASE "; break;
		case XAException.XA_RBCOMMFAIL : error = "XA_RBCOMMFAIL "; break;
		case XAException.XA_RBDEADLOCK : error = "XA_RBDEADLOCK "; break;
			// case XAException.XA_RBEND : error = "XA_RBEND "; break;
		case XAException.XA_RBINTEGRITY : error = "XA_RBINTEGRITY "; break;
		case XAException.XA_RBOTHER : error = "XA_RBOTHER "; break;
		case XAException.XA_RBPROTO : error = "XA_RBPROTO "; break;
		case XAException.XA_RBROLLBACK : error = "XA_RBROLLBACK "; break;
		case XAException.XA_RBTIMEOUT : error = "XA_RBTIMEOUT "; break;
		case XAException.XA_RBTRANSIENT : error = "XA_RBTRANSIENT "; break;
		case XAException.XA_RDONLY : error = "XA_RDONLY "; break;
		case XAException.XA_RETRY : error = "XA_RETRY "; break;
		case XAException.XAER_ASYNC : error = "XAER_ASYNC "; break;
		case XAException.XAER_DUPID : error = "XAER_DUPID "; break;
		case XAException.XAER_INVAL : error = "XAER_INVAL "; break;
		case XAException.XAER_NOTA : error = "XAER_NOTA "; break;
		case XAException.XAER_OUTSIDE : error = "XAER_OUTSIDE "; break;
		case XAException.XAER_PROTO : error = "XAER_PROTO "; break;
		case XAException.XAER_RMERR : error = "XAER_RMERR "; break;
		case XAException.XAER_RMFAIL : error = "XAER_RMFAIL "; break;
		}
		//t.printStackTrace(System.out);
		throw new ijException(error);

	}
	else // StandardException or run time exception, log it first
	{
		String info = LocalizedResource.getMessage("IJ_01SeeLog", t.toString(), t.getMessage());
		//		t.printStackTrace(System.out);
		throw new ijException(info);
	}
}