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

The following examples show how to use javax.transaction.xa.XAException#XAER_RMERR . 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: XATransactionState.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * This function is called from the timer task when the transaction
 * times out.
 *
 * @see CancelXATransactionTask
 */
private synchronized void cancel() throws XAException {
    // Check isFinished just to be sure that
    // the cancellation task was not started
    // just before the xa_commit/rollback
    // obtained this object's monitor.
    if (!isFinished) {
        // Check whether the transaction is associated
        // with any EmbedXAResource instance.
        if (associationState == XATransactionState.T1_ASSOCIATED) {
            conn.cancelRunningStatement();
            EmbedXAResource assocRes = associatedResource;
            end(assocRes, XAResource.TMFAIL, true);
        }

        // Rollback the global transaction
        try {
            conn.xa_rollback();
        } catch (SQLException sqle) {
            XAException ex = new XAException(XAException.XAER_RMERR);
            ex.initCause(sqle);
            throw ex;
        }

        // Do the cleanup on the resource
        creatingResource.returnConnectionToResource(this, xid);
    }
}
 
Example 2
Source File: XATransactionState.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This function is called from the timer task when the transaction
 * times out.
 *
 * @see CancelXATransactionTask
 */
synchronized void cancel(String messageId) throws XAException {
    // Check performTimeoutRollback just to be sure that
    // the cancellation task was not started
    // just before the xa_commit/rollback
    // obtained this object's monitor.
    if (performTimeoutRollback) {

        // Log the message about the transaction cancelled
        if (messageId != null)
            Monitor.logTextMessage(messageId, xid.toString());

        // Check whether the transaction is associated
        // with any EmbedXAResource instance.
        if (associationState == XATransactionState.T1_ASSOCIATED) {
            conn.cancelRunningStatement();
            EmbedXAResource assocRes = associatedResource;
            end(assocRes, XAResource.TMFAIL, true);
        }

        // Rollback the global transaction
        try {
            conn.xa_rollback();
        } catch (SQLException sqle) {
            XAException ex = new XAException(XAException.XAER_RMERR);
            ex.initCause(sqle);
            throw ex;
        }

        // Do the cleanup on the resource
        creatingResource.returnConnectionToResource(this, xid);
    }
}
 
Example 3
Source File: EhcacheXAResource.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Override
public int prepare(Xid xid) throws XAException {
  if (currentXid != null) {
    throw new EhcacheXAException("Cannot prepare a non-ended start on : " + xid, XAException.XAER_PROTO);
  }
  TransactionId transactionId = new TransactionId(xid);
  XATransactionContext<K, V> transactionContext = transactionContextFactory.get(transactionId);
  if (transactionContext == null) {
    throw new EhcacheXAException("Cannot prepare unknown XID : " + xid, XAException.XAER_NOTA);
  }

  boolean destroyContext = false;
  try {
    destroyContext = transactionContext.prepare() == 0;
    return destroyContext ? XA_RDONLY : XA_OK;
  } catch (XATransactionContext.TransactionTimeoutException tte) {
    destroyContext = true;
    throw new EhcacheXAException("Transaction timed out", XAException.XA_RBTIMEOUT);
  } catch (IllegalStateException ise) {
    throw new EhcacheXAException("Cannot prepare XID : " + xid, XAException.XAER_PROTO, ise);
  } catch (StoreAccessException cae) {
    throw new EhcacheXAException("Cannot prepare XID : " + xid, XAException.XAER_RMERR, cae);
  } finally {
    if (destroyContext) {
      transactionContextFactory.destroy(transactionId);
    }
  }
}
 
Example 4
Source File: EhcacheXAResource.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Override
public void commit(Xid xid, boolean onePhase) throws XAException {
  if (currentXid != null) {
    throw new EhcacheXAException("Cannot commit a non-ended start on : " + xid, XAException.XAER_PROTO);
  }
  TransactionId transactionId = new TransactionId(xid);
  XATransactionContext<K, V> transactionContext = transactionContextFactory.get(transactionId);

  try {
    if (onePhase) {
      if (transactionContext == null) {
        throw new EhcacheXAException("Cannot commit in one phase unknown XID : " + xid, XAException.XAER_NOTA);
      }
      try {
        transactionContext.commitInOnePhase();
      } catch (XATransactionContext.TransactionTimeoutException tte) {
        throw new EhcacheXAException("Transaction timed out", XAException.XA_RBTIMEOUT);
      }
    } else {
      XATransactionContext<K, V> commitContext = transactionContext;
      if (commitContext == null) {
        // recovery commit
        commitContext = new XATransactionContext<>(new TransactionId(new SerializableXid(xid)), underlyingStore, journal, null, 0L);
      }
      commitContext.commit(transactionContext == null);
    }
  } catch (IllegalArgumentException iae) {
    throw new EhcacheXAException("Cannot commit unknown XID : " + xid, XAException.XAER_NOTA);
  } catch (IllegalStateException ise) {
    throw new EhcacheXAException("Cannot commit XID : " + xid, XAException.XAER_PROTO, ise);
  } catch (StoreAccessException cae) {
    throw new EhcacheXAException("Cannot commit XID : " + xid, XAException.XAER_RMERR, cae);
  } finally {
    if (transactionContext != null) {
      transactionContextFactory.destroy(transactionId);
    }
  }
}
 
Example 5
Source File: CompensableCoordinator.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void forget(Xid xid) throws XAException {
	this.checkParticipantReadyIfNecessary();

	if (xid == null) {
		throw new XAException(XAException.XAER_INVAL);
	}
	TransactionRepository compensableRepository = this.beanFactory.getCompensableRepository();
	XidFactory xidFactory = this.beanFactory.getCompensableXidFactory();
	TransactionXid globalXid = xidFactory.createGlobalXid(xid.getGlobalTransactionId());
	CompensableTransaction transaction = null;
	try {
		transaction = (CompensableTransaction) compensableRepository.getTransaction(globalXid);
	} catch (TransactionException tex) {
		throw new XAException(XAException.XAER_RMERR);
	}

	if (transaction == null) {
		throw new XAException(XAException.XAER_NOTA);
	}

	try {
		transaction.forget();
	} catch (SystemException ex) {
		logger.error("Error occurred while forgetting transaction: {}." //
				, ByteUtils.byteArrayToString(xid.getGlobalTransactionId()), ex);

		throw new XAException(XAException.XAER_RMERR);
	} catch (RuntimeException rex) {
		logger.error("Error occurred while forgetting transaction: {}." //
				, ByteUtils.byteArrayToString(xid.getGlobalTransactionId()), rex);

		throw new XAException(XAException.XAER_RMERR);
	}
}
 
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 4 votes vote down vote up
public boolean isSameRM(XAResource xares) throws XAException {
	throw new XAException(XAException.XAER_RMERR);
}
 
Example 8
Source File: LocalXAResource.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public synchronized void start(Xid xid, int flags) throws XAException {
	if (xid == null) {
		throw new XAException(XAException.XAER_INVAL);
	} else if (flags == XAResource.TMRESUME && this.suspendXid != null) {
		if (this.suspendXid.equals(xid)) {
			this.suspendXid = null;
			this.currentXid = xid;
			this.originalAutoCommit = this.suspendAutoCommit;
			this.suspendAutoCommit = true;
			return;
		} else {
			throw new XAException(XAException.XAER_PROTO);
		}
	} else if (flags == XAResource.TMJOIN) {
		if (this.currentXid == null) {
			throw new XAException(XAException.XAER_PROTO);
		}
	} else if (flags != XAResource.TMNOFLAGS) {
		throw new XAException(XAException.XAER_PROTO);
	} else if (this.currentXid != null) {
		throw new XAException(XAException.XAER_PROTO);
	} else {
		Connection connection = this.managedConnection.getPhysicalConnection();

		try {
			originalAutoCommit = connection.getAutoCommit();
		} catch (Exception ignored) {
			originalAutoCommit = true;
		}

		try {
			connection.setAutoCommit(false);
		} catch (Exception ex) {
			XAException xae = new XAException(XAException.XAER_RMERR);
			xae.initCause(ex);
			throw xae;
		}

		this.currentXid = xid;
	}
}
 
Example 9
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 10
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 11
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Inform the resource manager to roll back work done on behalf of a transaction branch
 *
 * @param xid A global transaction identifier
 *
 * @throws XAException An error has occurred
 */
public void rollback(Xid xid) throws XAException {
    NetAgent netAgent = conn_.netAgent_;
    int rc = XAResource.XA_OK;
    exceptionsOnXA = null;

    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceEntry(this, "rollback", xid);
    }
    if (conn_.isPhysicalConnClosed()) {
        connectionClosedFailure();
    }

    // update the XACallInfo
    NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
    callInfo.xid_ = xid;
    callInfo.xaResource_ = this;
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    try {
        netAgent.beginWriteChainOutsideUOW();
        netAgent.netConnectionRequest_.writeXaRollback(conn_, xid);
        netAgent.flowOutsideUOW();
        // read the reply to the rollback
        rc = netAgent.netConnectionReply_.readXaRollback(conn_);
        netAgent.endReadChain();
        if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
            callInfo.xaFunction_ = XAFUNC_END;
            rc = xaRetValErrorAccumSQL(callInfo, rc);
            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        }
    } catch (SqlException sqle) {
        rc = XAException.XAER_RMERR;
        exceptionsOnXA = com.pivotal.gemfirexd.internal.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if (rc != XAResource.XA_OK) {
        throwXAException(rc, false);
    }
 
}
 
Example 12
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 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 flag 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 raise the appropriate XAException.
 *
 * @throws XAException An error has occurred. Possible values are XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and
 *                     XAER_PROTO.
 */
public Xid[] recover(int flag) throws XAException {
    int rc = XAResource.XA_OK;
    NetAgent netAgent = conn_.netAgent_;

    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceEntry(this, "recover", flag);
    }
    exceptionsOnXA = null;
    if (conn_.isPhysicalConnClosed()) {
        connectionClosedFailure();
    }

    Xid[] xidList = null;
    int numXid = 0;

    NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
    callInfo.xaFlags_ = flag;
    callInfo.xaResource_ = this;
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    try {
        netAgent.beginWriteChainOutsideUOW();
        // sent the recover PROTOCOL
        netAgent.netConnectionRequest_.writeXaRecover(conn_, flag);
        netAgent.flowOutsideUOW();
        netAgent.netConnectionReply_.readXaRecover(conn_);
        if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
            callInfo.xaFunction_ = XAFUNC_RECOVER;
            rc = xaRetValErrorAccumSQL(callInfo, rc);
            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        }
        netAgent.endReadChain();
        if (conn_.indoubtTransactions_ != null) {
            numXid = conn_.indoubtTransactions_.size();
            xidList = new Xid[numXid];
            int i = 0;
            nextElement = 0;
            for (Enumeration e = conn_.indoubtTransactions_.keys();
                 e.hasMoreElements(); i++) {
                xidList[i] = (Xid) e.nextElement();
            }
        }
    } catch (SqlException sqle) {
        rc = XAException.XAER_RMERR;
        exceptionsOnXA = com.pivotal.gemfirexd.internal.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if (rc != XAResource.XA_OK) {
        throwXAException(rc, false);
    }

    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceExit(this, "recover", xidList);
    }
    return xidList;
}
 
Example 13
Source File: FBManagedConnection.java    From jaybird with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * The {@code internalCommit} method performs the requested commit and may throw an XAException to be interpreted
 * by the caller.
 *
 * @param xid
 *         a {@code Xid} value
 * @param onePhase
 *         a {@code true} if this is not a two-phase commit (not a distributed transaction)
 * @throws XAException
 *         if an error occurs
 */
void internalCommit(Xid xid, boolean onePhase) throws XAException {
    if (log.isTraceEnabled()) log.trace("Commit called: " + xid);
    FbTransaction committingTr = xidMap.get(xid);

    // check that prepare has NOT been called when onePhase = true
    if (onePhase && isPrepared(xid)) {
        throw new FBXAException("Cannot commit one-phase when transaction has been prepared", XAException.XAER_PROTO);
    }

    // check that prepare has been called when onePhase = false
    if (!onePhase && !isPrepared(xid)) {
        throw new FBXAException("Cannot commit two-phase when transaction has not been prepared", XAException.XAER_PROTO);
    }

    if (committingTr == null) {
        throw new FBXAException("Commit called with unknown transaction", XAException.XAER_NOTA);
    }

    try {
        if (committingTr == getGDSHelper().getCurrentTransaction()) {
            throw new FBXAException("Commit called with non-ended xid", XAException.XAER_PROTO);
        }

        committingTr.commit();
    } catch (SQLException ge) {
        if (gdsHelper != null) {
            try {
                committingTr.rollback();
            } catch (SQLException ge2) {
                log.debug("Exception rolling back failed tx: ", ge2);
            }
        } else {
            log.warn("Unable to rollback failed tx, connection closed or lost");
        }
        throw new FBXAException(ge.getMessage(), XAException.XAER_RMERR, ge);
    } finally {
        xidMap.remove(xid);
        preparedXid.remove(xid);
    }
}
 
Example 14
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Ends the work performed on behalf of a transaction branch. The resource manager dissociates the XA resource from
 * the transaction branch specified and let the transaction be completed.
 * <p/>
 * If TMSUSPEND is specified in flags, the transaction branch is temporarily suspended in incomplete state. The
 * transaction context is in suspened state and must be resumed via start with TMRESUME specified.
 * <p/>
 * If TMFAIL is specified, the portion of work has failed. The resource manager may mark the transaction as
 * rollback-only
 * <p/>
 * If TMSUCCESS is specified, the portion of work has completed successfully.
 *
 * @param xid   A global transaction identifier that is the same as what was used previously in the start method.
 * @param flags One of TMSUCCESS, TMFAIL, or TMSUSPEND
 *
 * @throws XAException An error has occurred. Possible XAException values are XAER_RMERR, XAER_RMFAILED, XAER_NOTA,
 *                     XAER_INVAL, XAER_PROTO, or XA_RB*.
 */

public void end(Xid xid, int flags) throws XAException {

    NetAgent netAgent = conn_.netAgent_;
    int rc = XAResource.XA_OK;
    exceptionsOnXA = null;
    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceEntry(this, "end", xid, flags);
    }
    if (conn_.isPhysicalConnClosed()) {
        connectionClosedFailure();
    }

    NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
    callInfo.setReadOnlyTransactionFlag(conn_.readOnlyTransaction_);
    callInfo.xaFlags_ = flags;
    callInfo.xid_ = xid;
    callInfo.xaResource_ = this;
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    try {
        netAgent.beginWriteChainOutsideUOW();
        netAgent.netConnectionRequest_.writeXaEndUnitOfWork(conn_);
        netAgent.flowOutsideUOW();
        rc = netAgent.netConnectionReply_.readXaEndUnitOfWork(conn_);
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending end
        if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
            callInfo.xaFunction_ = XAFUNC_END;
            rc = xaRetValErrorAccumSQL(callInfo, rc);
            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        }
        netAgent.endReadChain();
    } catch (SqlException sqle) {
        rc = XAException.XAER_RMERR;
        exceptionsOnXA = com.pivotal.gemfirexd.internal.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if (rc != XAResource.XA_OK) {
        // The corresponding XA connection association state
        // is changed by setXaStateForXAException inside the call
        // to throwXAException according the error code of the XAException
        // to be thrown.
        throwXAException(rc, false);
    }else {
    	conn_.setXAState(Connection.XA_T0_NOT_ASSOCIATED);
    } 
}
 
Example 15
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void commit(Xid xid, boolean onePhase) throws XAException {
    NetAgent netAgent = conn_.netAgent_;
    int rc = XAResource.XA_OK;
    
    exceptionsOnXA = null;
    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceEntry(this, "commit", xid, onePhase);
    }
    if (conn_.isPhysicalConnClosed()) {
        connectionClosedFailure();
    }

    // update the XACallInfo
    NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
    callInfo.xaFlags_ = (onePhase ? XAResource.TMONEPHASE :
            XAResource.TMNOFLAGS);
    callInfo.xid_ = xid;
    callInfo.xaResource_ = this;
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    try {
        netAgent.beginWriteChainOutsideUOW();
        netAgent.netConnectionRequest_.writeXaCommit(conn_, xid);
        netAgent.flowOutsideUOW();
        netAgent.netConnectionReply_.readXaCommit(conn_);
        if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
            callInfo.xaFunction_ = XAFUNC_COMMIT;
            rc = xaRetValErrorAccumSQL(callInfo, rc);
            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        }
        netAgent.endReadChain();
    } catch (SqlException sqle) {
        rc = XAException.XAER_RMERR;
        exceptionsOnXA = com.pivotal.gemfirexd.internal.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if (rc != XAResource.XA_OK) {
        throwXAException(rc, false);
    }
}
 
Example 16
Source File: TransactionCoordinator.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void end(Xid xid, int flags) throws XAException {
	throw new XAException(XAException.XAER_RMERR);
}
 
Example 17
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 18
Source File: TransactionCoordinator.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int getTransactionTimeout() throws XAException {
	throw new XAException(XAException.XAER_RMERR);
}
 
Example 19
Source File: RemoteResourceDescriptor.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_RMERR);
}
 
Example 20
Source File: NetXAResource.java    From spliceengine with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Get XAException.errorCode from SqlException
 * For disconnect exception, return XAER_RMFAIL
 * For other exceptions return XAER_RMERR
 * 
 * For server side SQLExceptions during 
 * XA operations the errorCode has already been determined
 * and wrapped in an XAException for return to the client.
 * see EmbedXAResource.wrapInXAException
 * 
 * @param sqle  SqlException to evaluate.
 * @return XAException.XAER_RMFAIL for disconnect exception,
 *         XAException.XAER_RMERR for other exceptions.
 */
private int getSqlExceptionXAErrorCode(SqlException sqle) {      
   int seErrorCode = sqle.getErrorCode();
   return (seErrorCode == 40000 ? XAException.XAER_RMFAIL : XAException.XAER_RMERR);
}