Java Code Examples for javax.transaction.xa.XAResource#TMNOFLAGS

The following examples show how to use javax.transaction.xa.XAResource#TMNOFLAGS . 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: EhcacheXAResource.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@Override
public Xid[] recover(int flags) throws XAException {
  if (flags != XAResource.TMNOFLAGS && flags != XAResource.TMSTARTRSCAN && flags != XAResource.TMENDRSCAN && flags != (XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN)) {
    throw new EhcacheXAException("Recover flags not supported : " + xaResourceFlagsToString(flags), XAException.XAER_INVAL);
  }

  if ((flags & XAResource.TMSTARTRSCAN) == XAResource.TMSTARTRSCAN) {
    List<Xid> xids = new ArrayList<>();
    Set<TransactionId> transactionIds = journal.recover().keySet();
    for (TransactionId transactionId : transactionIds) {
      // filter-out in-flight tx
      if (!transactionContextFactory.contains(transactionId)) {
        xids.add(transactionId.getSerializableXid());
      }
    }
    return xids.toArray(new Xid[xids.size()]);
  }
  return new Xid[0];
}
 
Example 2
Source File: NetXAConnectionRequest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected void writeXaRollback(NetConnection conn, Xid xid) throws SqlException {
    int xaFlags = XAResource.TMNOFLAGS;

    // create DSS command with no reply.
    createCommand();

    // save the length bytes for later update
    markLengthBytes(CodePoint.SYNCCTL);

    // SYNCTYPE
    writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_ROLLBACK);

    if (xid.getFormatId() != -1) {
        writeXID(CodePoint.XID, xid);
    } else
    // write the null XID for local transaction on XA connection
    {
        writeNullXID(CodePoint.XID);
    }

    writeXAFlags(CodePoint.XAFLAGS, xaFlags);
    updateLengthBytes();
}
 
Example 3
Source File: TxLogManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void start(Xid xid, int flags) throws XAException
{
   log.tracef("start(%s, %d)", xid, flags);

   if (flags == XAResource.TMNOFLAGS)
   {
      addTxState(TX_XA_START_TMNOFLAGS);
   }
   else if (flags == XAResource.TMJOIN)
   {
      addTxState(TX_XA_START_TMJOIN);
   }
   else if (flags == XAResource.TMRESUME)
   {
      addTxState(TX_XA_START_TMRESUME);
   }
   else
   {
      addTxState(TX_XA_START_UNKNOWN);
   }
}
 
Example 4
Source File: ClientSessionImpl.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private String convertTXFlag(final int flags) {
   if (flags == XAResource.TMSUSPEND) {
      return "SESS_XA_SUSPEND";
   } else if (flags == XAResource.TMSUCCESS) {
      return "TMSUCCESS";
   } else if (flags == XAResource.TMFAIL) {
      return "TMFAIL";
   } else if (flags == XAResource.TMJOIN) {
      return "TMJOIN";
   } else if (flags == XAResource.TMRESUME) {
      return "TMRESUME";
   } else if (flags == XAResource.TMNOFLAGS) {
      // Don't need to flush since the previous end will have done this
      return "TMNOFLAGS";
   } else {
      return "XAER_INVAL(" + flags + ")";
   }
}
 
Example 5
Source File: ActiveMQSessionContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void xaStart(Xid xid, int flags) throws XAException, ActiveMQException {
   Packet packet;
   if (flags == XAResource.TMJOIN) {
      packet = new SessionXAJoinMessage(xid);
   } else if (flags == XAResource.TMRESUME) {
      packet = new SessionXAResumeMessage(xid);
   } else if (flags == XAResource.TMNOFLAGS) {
      // Don't need to flush since the previous end will have done this
      packet = new SessionXAStartMessage(xid);
   } else {
      throw new XAException(XAException.XAER_INVAL);
   }

   SessionXAResponseMessage response = (SessionXAResponseMessage) sessionChannel.sendBlocking(packet, PacketImpl.SESS_XA_RESP);

   if (response.isError()) {
      ActiveMQClientLogger.LOGGER.errorCallingStart(response.getMessage(), response.getResponseCode());
      throw new XAException(response.getResponseCode());
   }
}
 
Example 6
Source File: NetXAConnectionRequest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected void writeXaPrepare(NetConnection conn) throws SqlException {
    NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    Xid xid = callInfo.xid_;
    // don't forget that xars.prepare() does not have flags, assume TMNOFLAGS
    int xaFlags = XAResource.TMNOFLAGS;

    createCommand();

    // save the length bytes for later update
    markLengthBytes(CodePoint.SYNCCTL);

    // SYNCTYPE
    writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_PREPARE);

    if (xid.getFormatId() != -1) {
        writeXID(CodePoint.XID, xid);
    } else
    // write the null XID for local transaction on XA connection
    {
        writeNullXID(CodePoint.XID);
    }

    writeXAFlags(CodePoint.XAFLAGS, xaFlags);
    updateLengthBytes();
}
 
Example 7
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public NetXAResource(XAConnection xaconn, int rmId,
                     String userId, String password,
                     com.pivotal.gemfirexd.internal.client.net.NetXAConnection conn) {
    xaconn_ = xaconn;
    rmId_ = rmId;
    conn_ = conn.getNetConnection();
    netXAConn_ = conn;
    rmIdx_ = userId;
    rmIdy_ = password;
    port_ = conn_.netAgent_.getPort();
    ipaddr_ = conn_.netAgent_.socket_.getLocalAddress().getHostAddress();
    conn.setNetXAResource(this);

    // link the primary connection to the first XACallInfo element
    conn_.currXACallInfoOffset_ = 0;

    // construct the NetXACallInfo object for the array.
    for (int i = 0; i < INITIAL_CALLINFO_ELEMENTS; ++i) {
        callInfoArray_[i] = new NetXACallInfo(null, XAResource.TMNOFLAGS, this,
                null);
    }

    // initialize the first XACallInfo element with the information from the
    //  primary connection
    callInfoArray_[0].actualConn_ = conn;
    callInfoArray_[0].currConnection_ = true;
    callInfoArray_[0].freeEntry_ = false;
    // ~~~ save conn_ connection variables in callInfoArray_[0]
    callInfoArray_[0].saveConnectionVariables();

    // add this new XAResource to the list of other XAResources for the Same RM
    initForReuse();
}
 
Example 8
Source File: EhcacheXAResource.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Xid xid, int flag) throws XAException {
  if (flag != XAResource.TMNOFLAGS && flag != XAResource.TMJOIN) {
    throw new EhcacheXAException("Start flag not supported : " + xaResourceFlagsToString(flag), XAException.XAER_INVAL);
  }
  if (currentXid != null) {
    throw new EhcacheXAException("Already started on : " + xid, XAException.XAER_PROTO);
  }

  TransactionId transactionId = new TransactionId(xid);
  XATransactionContext<K, V> transactionContext = transactionContextFactory.get(transactionId);
  if (flag == XAResource.TMNOFLAGS) {
    if (transactionContext == null) {
      transactionContext = transactionContextFactory.createTransactionContext(transactionId, underlyingStore, journal, transactionTimeoutInSeconds);
    } else {
      throw new EhcacheXAException("Cannot start in parallel on two XIDs : starting " + xid, XAException.XAER_RMERR);
    }
  } else {
    if (transactionContext == null) {
      throw new EhcacheXAException("Cannot join unknown XID : " + xid, XAException.XAER_NOTA);
    }
  }

  if (transactionContext.hasTimedOut()) {
    transactionContextFactory.destroy(transactionId);
    throw new EhcacheXAException("Transaction timeout for XID : " + xid, XAException.XA_RBTIMEOUT);
  }
  currentXid = xid;
}
 
Example 9
Source File: FBManagedConnection.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Associates a JDBC connection with a global transaction. We assume that
 * end will be called followed by prepare, commit, or rollback. If start is
 * called after end but before commit or rollback, there is no way to
 * distinguish work done by different transactions on the same connection).
 * If start is called more than once before end, either it's a duplicate
 * transaction ID or illegal transaction ID (since you can't have two
 * transactions associated with one DB connection).
 *
 * @param id
 *         A global transaction identifier to be associated with the resource
 * @param flags
 *         One of TMNOFLAGS, TMJOIN, or TMRESUME
 * @throws XAException
 *         Occurs when the state was not correct (start called twice), the transaction ID is wrong, or the instance
 *         has already been closed.
 */
private void start(Xid id, int flags) throws XAException {
    if (flags != XAResource.TMNOFLAGS && flags != XAResource.TMJOIN && flags != XAResource.TMRESUME) {
        throw new FBXAException("flag not allowed in this context: " + flags + ", valid flags are TMNOFLAGS, TMJOIN, TMRESUME", XAException.XAER_PROTO);
    }
    if (flags == XAResource.TMJOIN) {
        throw new FBXAException("Joining two transactions is not supported", XAException.XAER_RMFAIL);
    }

    try {
        // reset the transaction parameters for the managed scenario
        setTransactionIsolation(mcf.getDefaultTransactionIsolation());

        internalStart(id, flags);

        mcf.notifyStart(this, id);

        inDistributedTransaction = true;

        // This will reset the managed environment of the associated connections and set the transaction coordinator to managed
        // TODO This is a bit of a hack; need to find a better way
        setManagedEnvironment(isManagedEnvironment());

    } catch (SQLException e) {
        throw new FBXAException(XAException.XAER_RMERR, e);
    }
}
 
Example 10
Source File: NetXAResource.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public NetXAResource(XAConnection xaconn, int rmId,
                     String userId, String password,
                     com.splicemachine.db.client.net.NetXAConnection conn) {
    xaconn_ = xaconn;
    rmId_ = rmId;
    conn_ = conn.getNetConnection();
    netXAConn_ = conn;
    rmIdx_ = userId;
    rmIdy_ = password;
    port_ = conn_.netAgent_.getPort();
    ipaddr_ = conn_.netAgent_.socket_.getLocalAddress().getHostAddress();
    conn.setNetXAResource(this);

    // link the primary connection to the first XACallInfo element
    conn_.currXACallInfoOffset_ = 0;

    // construct the NetXACallInfo object for the array.
    for (int i = 0; i < INITIAL_CALLINFO_ELEMENTS; ++i) {
        callInfoArray_[i] = new NetXACallInfo(null, XAResource.TMNOFLAGS, this,
                null);
    }

    // initialize the first XACallInfo element with the information from the
    //  primary connection
    callInfoArray_[0].actualConn_ = conn;
    callInfoArray_[0].currConnection_ = true;
    callInfoArray_[0].freeEntry_ = false;
    // ~~~ save conn_ connection variables in callInfoArray_[0]
    callInfoArray_[0].saveConnectionVariables();
}
 
Example 11
Source File: LocalXAResourceImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void start(Xid xid, int flags) throws XAException
{
   if (trace)
      log.tracef("start(%s, %s)", xid, flags);  
   
   if (currentXid != null && flags == XAResource.TMNOFLAGS)
   {
      throw new LocalXAException(bundle.tryingStartNewTxWhenOldNotComplete(
            currentXid, xid, flags), XAException.XAER_PROTO);
   }
   
   if (currentXid == null && flags != XAResource.TMNOFLAGS)
   {
      throw new LocalXAException(bundle.tryingStartNewTxWithWrongFlags(xid, flags), XAException.XAER_PROTO);
   }

   if (currentXid == null)
   {
      try
      {
         cl.getManagedConnection().getLocalTransaction().begin();
      }
      catch (ResourceException re)
      {
         throw new LocalXAException(bundle.errorTryingStartLocalTx(), XAException.XAER_RMERR, re);
      }
      catch (Throwable t)
      {
         throw new LocalXAException(bundle.throwableTryingStartLocalTx(), XAException.XAER_RMERR, t);
      }

      currentXid = xid;
   }
}
 
Example 12
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public NetXAResource(XAConnection xaconn, int rmId,
                     String userId, String password,
                     com.pivotal.gemfirexd.internal.client.net.NetXAConnection conn) {
    xaconn_ = xaconn;
    rmId_ = rmId;
    conn_ = conn.getNetConnection();
    netXAConn_ = conn;
    rmIdx_ = userId;
    rmIdy_ = password;
    port_ = conn_.netAgent_.getPort();
    ipaddr_ = conn_.netAgent_.socket_.getLocalAddress().getHostAddress();
    conn.setNetXAResource(this);

    // link the primary connection to the first XACallInfo element
    conn_.currXACallInfoOffset_ = 0;

    // construct the NetXACallInfo object for the array.
    for (int i = 0; i < INITIAL_CALLINFO_ELEMENTS; ++i) {
        callInfoArray_[i] = new NetXACallInfo(null, XAResource.TMNOFLAGS, this,
                null);
    }

    // initialize the first XACallInfo element with the information from the
    //  primary connection
    callInfoArray_[0].actualConn_ = conn;
    callInfoArray_[0].currConnection_ = true;
    callInfoArray_[0].freeEntry_ = false;
    // ~~~ save conn_ connection variables in callInfoArray_[0]
    callInfoArray_[0].saveConnectionVariables();

    // add this new XAResource to the list of other XAResources for the Same RM
    initForReuse();
}
 
Example 13
Source File: NetXAConnectionRequest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public void writeXaStartUnitOfWork(NetConnection conn) throws SqlException {
    NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    Xid xid = callInfo.xid_;
    int xaFlags = callInfo.xaFlags_;
    long xaTimeout = callInfo.xaTimeoutMillis_;

    // create DSS command with reply.
    createCommand();

    // save the length bytes for later update
    markLengthBytes(CodePoint.SYNCCTL);

    // SYNCTYPE
    writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_NEW_UOW);

    if (xid.getFormatId() != -1) {
        writeXID(CodePoint.XID, xid);
    } else
    // write the null XID for local transaction on XA connection
    {
        writeNullXID(CodePoint.XID);
    }

    writeXAFlags(CodePoint.XAFLAGS, xaFlags);

    // Check whether the timeout value was specified.
    // Value less than 0 means no timeout is specified.
    // DERBY-4232: The DRDA spec says that SYNCCTL should only have a
    // timeout property if TMNOFLAGS is specified.
    if (xaTimeout >= 0 && xaFlags == XAResource.TMNOFLAGS) {
        writeXATimeout(CodePoint.TIMEOUT, xaTimeout);
    }

    updateLengthBytes();
}
 
Example 14
Source File: NetXACallInfo.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public NetXACallInfo() {
    xid_ = null;
    xaFlags_ = XAResource.TMNOFLAGS;
    xaTimeoutMillis_ = -1;
    xaInProgress_ = false;
    currConnection_ = false;
    freeEntry_ = true;
    convReleased_ = false;
    actualConn_ = null;
    readOnlyTransaction_ = true;
    xaResource_ = null;
    xaRetVal_ = 0;
    xaWasSuspended = false;
}
 
Example 15
Source File: AbstractLuceneIndexerAndSearcherFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void start(Xid xid, int flag) throws XAException
{
    Map<StoreRef, LuceneIndexer> active = activeIndexersInGlobalTx.get(xid);
    Map<StoreRef, LuceneIndexer> suspended = suspendedIndexersInGlobalTx.get(xid);
    if (flag == XAResource.TMJOIN)
    {
        // must be active
        if ((active != null) && (suspended == null))
        {
            return;
        }
        else
        {
            throw new XAException("Trying to rejoin transaction in an invalid state");
        }

    }
    else if (flag == XAResource.TMRESUME)
    {
        // must be suspended
        if ((active == null) && (suspended != null))
        {
            suspendedIndexersInGlobalTx.remove(xid);
            activeIndexersInGlobalTx.put(xid, suspended);
            return;
        }
        else
        {
            throw new XAException("Trying to rejoin transaction in an invalid state");
        }

    }
    else if (flag == XAResource.TMNOFLAGS)
    {
        if ((active == null) && (suspended == null))
        {
            return;
        }
        else
        {
            throw new XAException("Trying to start an existing or suspended transaction");
        }
    }
    else
    {
        throw new XAException("Unkown flags for start " + flag);
    }

}
 
Example 16
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 17
Source File: XASupport.java    From jTDS with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Invoke the xa_prepare routine on the SQL Server.
 *
 * @param connection JDBC Connection enlisted in the transaction.
 * @param xaConId    The connection ID allocated by the server.
 * @param xid        The XA Transaction ID object.
 * @return prepare status (XA_OK or XA_RDONLY) as an <code>int</code>.
 * @exception javax.transaction.xa.XAException
 *             if an error condition occurs
 */
public static int xa_prepare(Connection connection, int xaConId, Xid xid)
        throws XAException {

    JtdsConnection con = (JtdsConnection)connection;
    if (con.isXaEmulation()) {
        //
        // Emulate xa_prepare method
        // In emulation mode this is essentially a noop as we
        // are not able to offer true two phase commit.
        //
        JtdsXid lxid = new JtdsXid(xid);
        if (con.getXaState() != XA_END) {
            // Connection not ended
            raiseXAException(XAException.XAER_PROTO);
        }
        JtdsXid tran = (JtdsXid)con.getXid();
        if (tran == null || !tran.equals(lxid)) {
            raiseXAException(XAException.XAER_NOTA);
        }
        con.setXaState(XA_PREPARE);
        Logger.println("xa_prepare: Warning: Two phase commit not available in XA emulation mode.");
        return XAResource.XA_OK;
    }
    //
    // Execute xa_prepare via MSDTC
    //
    int args[] = new int[5];
    args[1] = XA_PREPARE;
    args[2] = xaConId;
    args[3] = XA_RMID;
    args[4] = XAResource.TMNOFLAGS;
    try {
        ((JtdsConnection) connection).sendXaPacket(args, toBytesXid(xid));
    } catch (SQLException e) {
        raiseXAException(e);
    }
    if (args[0] != XAResource.XA_OK && args[0] != XAResource.XA_RDONLY) {
        raiseXAException(args[0]);
    }
    return args[0];
}
 
Example 18
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 19
Source File: TransactionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Boolean enlistResource(XAResourceArchive archive, int flag) throws SystemException {
	try {
		Xid branchXid = archive.getXid();
		logger.info("{}> enlist: xares= {}, branch= {}, flags: {}",
				ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), archive,
				ByteUtils.byteArrayToString(branchXid.getBranchQualifier()), flag);

		switch (flag) {
		case XAResource.TMNOFLAGS:
			long expired = this.transactionContext.getExpiredTime();
			long current = System.currentTimeMillis();
			long remains = expired - current;
			int timeout = (int) (remains / 1000L);
			archive.setTransactionTimeout(timeout);
			archive.start(branchXid, flag);
			return true;
		case XAResource.TMJOIN:
			archive.start(branchXid, flag);
			archive.setDelisted(false);
			return false;
		case XAResource.TMRESUME:
			archive.start(branchXid, flag);
			archive.setDelisted(false);
			archive.setSuspended(false);
			return false;
		default:
			return null;
		}
	} catch (XAException xae) {
		logger.error("XATerminatorImpl.enlistResource(XAResourceArchive, int)", xae);

		// Possible exceptions are XA_RB*, XAER_RMERR, XAER_RMFAIL,
		// XAER_DUPID, XAER_OUTSIDE, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
		switch (xae.errorCode) {
		case XAException.XAER_DUPID:
			// * If neither TMJOIN nor TMRESUME is specified and the transaction
			// * specified by xid has previously been seen by the resource manager,
			// * the resource manager throws the XAException exception with XAER_DUPID error code.
			return null;
		case XAException.XAER_OUTSIDE:
			// The resource manager is doing work outside any global transaction
			// on behalf of the application.
		case XAException.XAER_NOTA:
			// Either TMRESUME or TMJOIN was set inflags, and 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 null;
		case XAException.XAER_RMFAIL:
			// An error occurred that makes the resource manager unavailable
		case XAException.XAER_RMERR:
			// An error occurred in associating the transaction branch with the thread of control
			return null;
		default /* XA_RB **/ :
			// When a RollbackException is received, DBCP treats the state as STATUS_ROLLEDBACK,
			// but the actual state is still STATUS_MARKED_ROLLBACK.
			return null; // throw new RollbackException();
		}
	} catch (RuntimeException ex) {
		logger.error("XATerminatorImpl.enlistResource(XAResourceArchive, int)", ex);
		throw new SystemException();
	}

}
 
Example 20
Source File: XASupport.java    From jTDS with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Invoke the xa_recover routine on the SQL Server.
 * <p/>
 * This version of xa_recover will return all XIDs on the first call.
 *
 * @param connection JDBC Connection enlisted in the transaction
 * @param xaConId    the connection ID allocated by the server
 * @param flags      XA Flags for start command
 * @return transactions to recover as a <code>Xid[]</code>
 * @exception javax.transaction.xa.XAException
 *             if an error condition occurs
 */
public static Xid[] xa_recover(Connection connection, int xaConId, int flags)
        throws XAException {

    JtdsConnection con = (JtdsConnection)connection;
    if (con.isXaEmulation()) {
        //
        // Emulate xa_recover method
        //
        // There is no state available all uncommited transactions
        // will have been rolled back by the server.
        if (flags != XAResource.TMSTARTRSCAN &&
            flags != XAResource.TMENDRSCAN &&
            flags != ( XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN ) &&
            flags != XAResource.TMNOFLAGS) {
            raiseXAException(XAException.XAER_INVAL);
        }
        return new JtdsXid[0];
    }
    //
    // Execute xa_recover via MSDTC
    //
    int args[] = new int[5];
    args[1] = XA_RECOVER;
    args[2] = xaConId;
    args[3] = XA_RMID;
    args[4] = XAResource.TMNOFLAGS;
    Xid[] list = null;

    if (flags != XAResource.TMSTARTRSCAN) {
        return new JtdsXid[0];
    }

    try {
        byte[][] buffer = ((JtdsConnection) connection).sendXaPacket(args, null);
        if (args[0] >= 0) {
            int n = buffer.length;
            list = new JtdsXid[n];
            for (int i = 0; i < n; i++) {
                list[i] = new JtdsXid(buffer[i], 0);
            }
        }
    } catch (SQLException e) {
        raiseXAException(e);
    }
    if (args[0] < 0) {
        raiseXAException(args[0]);
    }
    if (list == null) {
        list = new JtdsXid[0];
    }
    return list;
}