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

The following examples show how to use javax.transaction.xa.XAException#XAER_RMFAIL . 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: LocalXAResourceImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void commit(Xid xid, boolean onePhase) throws XAException
{
   if (!xid.equals(currentXid))
   {
      throw new LocalXAException(bundle.wrongXidInCommit(currentXid, xid), XAException.XAER_PROTO);
      
   }
   
   currentXid = null;

   try
   {
      cl.getManagedConnection().getLocalTransaction().commit();
   }
   catch (LocalResourceException lre)
   {
      connectionManager.returnManagedConnection(cl, true);
      throw new LocalXAException(bundle.couldNotCommitLocalTx(), XAException.XAER_RMFAIL, lre);
   }
   catch (ResourceException re)
   {
      connectionManager.returnManagedConnection(cl, true);
      throw new LocalXAException(bundle.couldNotCommitLocalTx(), XAException.XA_RBROLLBACK, re);
   }
}
 
Example 2
Source File: CompensableCleanupWork.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void cleanupByResource(String resourceId, List<Xid> xidList) throws RuntimeException {
	XAResourceDeserializer resourceDeserializer = this.beanFactory.getResourceDeserializer();
	if (StringUtils.isBlank(resourceId)) {
		throw new IllegalStateException();
	}

	Xid[] xidArray = new Xid[xidList.size()];
	xidList.toArray(xidArray);
	LocalXAResourceDescriptor descriptor = //
			(LocalXAResourceDescriptor) resourceDeserializer.deserialize(resourceId);
	RecoveredResource resource = (RecoveredResource) descriptor.getDelegate();
	try {
		resource.forget(xidArray);
	} catch (XAException xaex) {
		logger.error("Error occurred while forgetting resource: {}.", resourceId, xaex);

		switch (xaex.errorCode) {
		case XAException.XAER_NOTA:
			break;
		case XAException.XAER_RMERR:
		case XAException.XAER_RMFAIL:
			throw new IllegalStateException();
		}
	}

}
 
Example 3
Source File: LocalXAResourceImpl.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void commit(Xid xid, boolean onePhase) throws XAException
{
   if (!xid.equals(currentXid))
   {
      throw new LocalXAException(bundle.wrongXidInCommit(currentXid, xid), XAException.XAER_PROTO);
      
   }
   
   currentXid = null;

   try
   {
      cl.getManagedConnection().getLocalTransaction().commit();
   }
   catch (LocalResourceException lre)
   {
      connectionManager.returnConnectionListener(cl, true);
      throw new LocalXAException(bundle.couldNotCommitLocalTx(), XAException.XAER_RMFAIL, lre);
   }
   catch (ResourceException re)
   {
      connectionManager.returnConnectionListener(cl, true);
      throw new LocalXAException(bundle.couldNotCommitLocalTx(), XAException.XA_RBROLLBACK, re);
   }
}
 
Example 4
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void forget(Xid xid) throws XAException {
	for (int i = 0; i < this.resources.size(); i++) {
		XAResourceArchive archive = this.resources.get(i);
		Xid currentXid = archive.getXid();
		if (archive.isHeuristic() == false) {
			continue;
		}

		try {
			Xid branchXid = archive.getXid();
			archive.forget(branchXid);
		} catch (XAException xae) {
			// Possible exception values are XAER_RMERR, XAER_RMFAIL
			// , XAER_NOTA, XAER_INVAL, or XAER_PROTO.
			switch (xae.errorCode) {
			case XAException.XAER_RMERR:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
				break;
			case XAException.XAER_RMFAIL:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
				break;
			case XAException.XAER_NOTA:
			case XAException.XAER_INVAL:
			case XAException.XAER_PROTO:
				break;
			default:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
			}
		}

	} // end-for
}
 
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: 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 7
Source File: CompensableCoordinator.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkParticipantReady() throws XAException {
	try {
		this.lock.lock();
		if (this.ready == false) {
			throw new XAException(XAException.XAER_RMFAIL);
		}
	} finally {
		this.lock.unlock();
	}
}
 
Example 8
Source File: XATerminatorOptd.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void forget(Xid xid) throws XAException {
	if (this.archive == null) {
		return;
	}

	Xid currentXid = archive.getXid();
	if (archive.isHeuristic()) {
		try {
			Xid branchXid = archive.getXid();
			archive.forget(branchXid);
		} catch (XAException xae) {
			// Possible exception values are XAER_RMERR, XAER_RMFAIL
			// , XAER_NOTA, XAER_INVAL, or XAER_PROTO.
			switch (xae.errorCode) {
			case XAException.XAER_RMERR:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
				break;
			case XAException.XAER_RMFAIL:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
				break;
			case XAException.XAER_NOTA:
			case XAException.XAER_INVAL:
			case XAException.XAER_PROTO:
				break;
			default:
				logger.error("{}> forget: xares= {}, branch={}, error= {}",
						ByteUtils.byteArrayToString(currentXid.getGlobalTransactionId()), archive,
						ByteUtils.byteArrayToString(currentXid.getBranchQualifier()), xae.errorCode);
			}
		}
	} // end-if
}
 
Example 9
Source File: ClientSessionImpl.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public int getTransactionTimeout() throws XAException {
   checkXA();

   try {
      return sessionContext.recoverSessionTimeout();
   } catch (Throwable t) {
      // This could occur if the TM interrupts the thread
      XAException xaException = new XAException(XAException.XAER_RMFAIL);
      xaException.initCause(t);
      throw xaException;
   }
}
 
Example 10
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int getTransactionTimeout() throws XAException {
	throw new XAException(XAException.XAER_RMFAIL);
}
 
Example 11
Source File: XATerminatorOptd.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int getTransactionTimeout() throws XAException {
	throw new XAException(XAException.XAER_RMFAIL);
}
 
Example 12
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 13
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean setTransactionTimeout(int seconds) throws XAException {
	throw new XAException(XAException.XAER_RMFAIL);
}
 
Example 14
Source File: FBManagedConnection.java    From jaybird with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
     * Obtain a list of prepared transaction branches from a resource manager.
     * The transaction manager calls this method during recovery to obtain the
     * list of transaction branches that are currently in prepared or
     * heuristically completed states.
     *
     * @param flags
     *         One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS must be used when no other flags are set in flags.
     * @return The resource manager returns zero or more XIDs for the transaction branches that are currently in a
     * prepared or heuristically completed state. If an error occurs during the operation, the resource manager should
     * throw the appropriate XAException.
     * @throws XAException
     *         An error has occurred. Possible values are XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and XAER_PROTO.
     */
    private Xid[] recover(int flags) throws javax.transaction.xa.XAException {
        if (flags != XAResource.TMSTARTRSCAN && flags != XAResource.TMENDRSCAN && flags != XAResource.TMNOFLAGS
                && flags != (XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN)) {
            throw new FBXAException("flag not allowed in this context: " + flags + ", valid flags are TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS, TMSTARTRSCAN|TMENDRSCAN", XAException.XAER_PROTO);
        }

        try {
            // if (!((flags & XAResource.TMSTARTRSCAN) == 0))
//            if ((flags & XAResource.TMENDRSCAN) == 0 && (flags & XAResource.TMNOFLAGS) == 0)
//                return new Xid[0];

            List<FBXid> xids = new ArrayList<>();

            FbTransaction trHandle2 = database.startTransaction(tpb.getTransactionParameterBuffer());

            FbStatement stmtHandle2 = database.createStatement(trHandle2);

            GDSHelper gdsHelper2 = new GDSHelper(database);
            gdsHelper2.setCurrentTransaction(trHandle2);

            stmtHandle2.prepare(RECOVERY_QUERY);

            DataProvider dataProvider0 = new DataProvider(0);
            stmtHandle2.addStatementListener(dataProvider0);
            DataProvider dataProvider1 = new DataProvider(1);
            stmtHandle2.addStatementListener(dataProvider1);

            stmtHandle2.execute(RowValue.EMPTY_ROW_VALUE);
            stmtHandle2.fetchRows(10);

            FBField field0 = FBField.createField(stmtHandle2.getRowDescriptor().getFieldDescriptor(0), dataProvider0, gdsHelper2, false);
            FBField field1 = FBField.createField(stmtHandle2.getRowDescriptor().getFieldDescriptor(1), dataProvider1, gdsHelper2, false);

            int row = 0;
            while (row < dataProvider0.getRowCount()) {
                dataProvider0.setRow(row);
                dataProvider1.setRow(row);

                long inLimboTxId = field0.getLong();
                byte[] inLimboMessage = field1.getBytes();

                try {
                    FBXid xid = new FBXid(new ByteArrayInputStream(inLimboMessage), inLimboTxId);
                    xids.add(xid);
                } catch (FBIncorrectXidException ex) {
                    log.warn("ignoring XID stored with invalid format in RDB$TRANSACTIONS for RDB$TRANSACTION_ID=" + inLimboTxId);
                }

                row++;
            }

            stmtHandle2.close();
            trHandle2.commit();

            return xids.toArray(new FBXid[0]);
        } catch (SQLException | IOException e) {
            throw new FBXAException("can't perform query to fetch xids", XAException.XAER_RMFAIL, e);
        }
    }
 
Example 15
Source File: SpringCloudCoordinator.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	Class<?> clazz = method.getDeclaringClass();
	String methodName = method.getName();
	Class<?> returnType = method.getReturnType();
	if (Object.class.equals(clazz)) {
		return method.invoke(this, args);
	} else if (TransactionParticipant.class.equals(clazz)) {
		throw new XAException(XAException.XAER_RMFAIL);
	} else if (RemoteCoordinator.class.equals(clazz)) {
		if ("getIdentifier".equals(methodName)) {
			return this.identifier;
		} else if ("getApplication".equals(methodName)) {
			int firstIndex = this.identifier.indexOf(":");
			int lastIndex = this.identifier.lastIndexOf(":");
			return firstIndex <= 0 || lastIndex <= 0 || firstIndex > lastIndex //
					? null : this.identifier.subSequence(firstIndex + 1, lastIndex);
		} else if ("getRemoteAddr".equals(methodName) && RemoteAddr.class.equals(returnType)) {
			return this.identifier == null ? null : CommonUtils.getRemoteAddr(this.identifier);
		} else if ("getRemoteNode".equals(methodName) && RemoteNode.class.equals(returnType)) {
			return this.identifier == null ? null : CommonUtils.getRemoteNode(this.identifier);
		} else {
			throw new XAException(XAException.XAER_RMFAIL);
		}
	} else if (XAResource.class.equals(clazz)) {
		if ("start".equals(methodName)) {
			return null; // return immediately
		} else if ("prepare".equals(methodName)) {
			return this.invokeHttpPostRequest(proxy, method, args);
		} else if ("commit".equals(methodName)) {
			return this.invokeHttpPostRequest(proxy, method, args);
		} else if ("rollback".equals(methodName)) {
			return this.invokeHttpPostRequest(proxy, method, args);
		} else if ("recover".equals(methodName)) {
			return this.invokeTransactionRecover(proxy, method, args);
		} else if ("forget".equals(methodName)) {
			return this.invokeHttpPostRequest(proxy, method, args);
		} else {
			throw new XAException(XAException.XAER_RMFAIL);
		}
	} else {
		throw new IllegalAccessException();
	}
}
 
Example 16
Source File: LocalXAResource.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void createTransactionLogIfNecessary(Xid xid) throws XAException {
	byte[] globalTransactionId = xid.getGlobalTransactionId();
	byte[] branchQualifier = xid.getBranchQualifier();

	String gxid = ByteUtils.byteArrayToString(globalTransactionId);
	String bxid = null;
	if (branchQualifier == null || branchQualifier.length == 0) {
		bxid = gxid;
	} else {
		bxid = ByteUtils.byteArrayToString(branchQualifier);
	}

	String identifier = this.getIdentifier(globalTransactionId, branchQualifier);

	Connection connection = this.managedConnection.getPhysicalConnection();

	PreparedStatement stmt = null;
	try {
		stmt = connection.prepareStatement("insert into bytejta(xid, gxid, bxid, ctime) values(?, ?, ?, ?)");
		stmt.setString(1, identifier);
		stmt.setString(2, gxid);
		stmt.setString(3, bxid);
		stmt.setLong(4, System.currentTimeMillis());
		int value = stmt.executeUpdate();
		if (value == 0) {
			throw new IllegalStateException("The operation failed and the data was not written to the database!");
		}
	} catch (SQLException ex) {
		boolean tableExists = false;
		try {
			tableExists = this.isTableExists(connection);
		} catch (Exception sqlEx) {
			logger.error("Error occurred while ending local-xa-resource: {}", ex.getMessage());
			throw new XAException(XAException.XAER_RMFAIL);
		}

		if (tableExists) {
			logger.error("Error occurred while ending local-xa-resource: {}", ex.getMessage());
			throw new XAException(XAException.XAER_RMERR);
		} else {
			logger.debug("Error occurred while ending local-xa-resource: {}", ex.getMessage());
		}
	} catch (RuntimeException rex) {
		logger.error("Error occurred while ending local-xa-resource: {}", rex.getMessage());
		throw new XAException(XAException.XAER_RMERR);
	} finally {
		this.closeQuietly(stmt);
	}
}
 
Example 17
Source File: TransactionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean delistResource(XAResourceArchive archive, int flag) throws SystemException {
	try {
		Xid branchXid = archive.getXid();

		logger.info("{}> delist: xares= {}, branch= {}, flags= {}",
				ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), archive,
				ByteUtils.byteArrayToString(branchXid.getBranchQualifier()), flag);

		switch (flag) {
		case XAResource.TMSUSPEND:
			archive.end(branchXid, flag);
			archive.setDelisted(true);
			archive.setSuspended(true);
			return true;
		case XAResource.TMFAIL:
			this.setRollbackOnlyQuietly();
		case XAResource.TMSUCCESS:
			archive.end(branchXid, flag);
			archive.setDelisted(true);
			return true;
		default:
			return false;
		}
	} catch (XAException xae) {
		logger.error("XATerminatorImpl.delistResource(XAResourceArchive, int)", xae);

		// Possible XAException values are XAER_RMERR, XAER_RMFAIL,
		// XAER_NOTA, XAER_INVAL, XAER_PROTO, or XA_RB*.
		switch (xae.errorCode) {
		case XAException.XAER_NOTA:
			// The specified XID is not known by the resource manager.
		case XAException.XAER_INVAL:
			// Invalid arguments were specified.
		case XAException.XAER_PROTO:
			// The routine was invoked in an improper context.
			return false;
		case XAException.XAER_RMFAIL:
			// An error occurred that makes the resource manager unavailable.
		case XAException.XAER_RMERR:
			// An error occurred in dissociating the transaction branch from the thread of control.
			return false; // throw new SystemException();
		default /* XA_RB* */ :
			return false; // throw new RollbackRequiredException();
		}
	} catch (RuntimeException ex) {
		logger.error("XATerminatorImpl.delistResource(XAResourceArchive, int)", ex);
		throw new SystemException();
	}
}
 
Example 18
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 19
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void start(Xid xid, int flags) throws XAException {
	throw new XAException(XAException.XAER_RMFAIL);
}
 
Example 20
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);
		}
	}
}