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

The following examples show how to use javax.transaction.xa.XAResource#XA_OK . 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: NetXAConnection.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public void readCommit() throws SqlException {
    int xaState = netCon.getXAState();
    NetXACallInfo callInfo = netCon.xares_.callInfoArray_
            [netCon.currXACallInfoOffset_];
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    if (xaState == netCon.XA_T0_NOT_ASSOCIATED) {
        readLocalXACommit_();
        //TODO: Remove
        //setXAState(XA_LOCAL);
    }
    if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
        callInfo.xaFunction_ = NetXAResource.XAFUNC_COMMIT;
        netCon.xares_.xaRetValErrorAccumSQL(callInfo, 0);
        callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        throw netCon.xares_.exceptionsOnXA;
    }        
}
 
Example 2
Source File: LocalXAConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * This method does nothing since the LocalXAConnection does not support two-phase-commit. This method will
 * return XAResource.XA_RDONLY if the connection isReadOnly(). This assumes that the physical connection is
 * wrapped with a proxy that prevents an application from changing the read-only flag while enrolled in a
 * transaction.
 *
 * @param xid
 *            the id of the transaction branch for this connection
 * @return XAResource.XA_RDONLY if the connection.isReadOnly(); XAResource.XA_OK otherwise
 */
@Override
public synchronized int prepare(final Xid xid) {
    // if the connection is read-only, then the resource is read-only
    // NOTE: this assumes that the outer proxy throws an exception when application code
    // attempts to set this in a transaction
    try {
        if (connection.isReadOnly()) {
            // update the auto commit flag
            connection.setAutoCommit(originalAutoCommit);

            // tell the transaction manager we are read only
            return XAResource.XA_RDONLY;
        }
    } catch (final SQLException ignored) {
        // no big deal
    }

    // this is a local (one phase) only connection, so we can't prepare
    return XAResource.XA_OK;
}
 
Example 3
Source File: NetXAResource.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
protected int xaRetValErrorAccumSQL(NetXACallInfo callInfo, int currentRC) {

        // xaRetVal_ is set by the server to be one of the
        // standard constants from XAException.
        int rc = callInfo.xaRetVal_;

        if (rc != XAResource.XA_OK) { // error was detected
            // create an SqlException to report this error within
            SqlException accumSql = new SqlException(conn_.netAgent_.logWriter_,
                new ClientMessageId(SQLState.NET_XARETVAL_ERROR),
                getXAFuncStr(callInfo.xaFunction_),
                getXAExceptionText(rc),
                com.splicemachine.db.client.am.SqlCode.queuedXAError);
            exceptionsOnXA = com.splicemachine.db.client.am.Utils.accumulateSQLException
                    (accumSql, exceptionsOnXA);

            if (currentRC != XAResource.XA_OK) { // the rc passed into this function had an error also, prioritize error
                if (currentRC < 0) { // rc passed in was a major error use it instead of current error
                    return currentRC;
                }
            }
        }
        return rc;
    }
 
Example 4
Source File: LocalXAResource.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public int prepare(final Xid xid) {
    checkLock();

    try {
        if (connection.isReadOnly()) {
            connection.setAutoCommit(originalAutoCommit);
            return XAResource.XA_RDONLY;
        }
    } catch (final SQLException ignored) {
        // no-op
    }

    return XAResource.XA_OK;
}
 
Example 5
Source File: LocalXAResourceImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int prepare(Xid xid) throws XAException
{
   if (!warned)
   {
      log.prepareCalledOnLocaltx();  
   }
   warned = true;
   
   return XAResource.XA_OK;
}
 
Example 6
Source File: FBManagedConnection.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
int internalPrepare(Xid xid) throws FBXAException {
    if (log.isTraceEnabled()) log.trace("prepare called: " + xid);
    FbTransaction committingTr = xidMap.get(xid);
    if (committingTr == null) {
        throw new FBXAException("Prepare called with unknown transaction", XAException.XAER_NOTA);
    }
    try {
        if (committingTr == getGDSHelper().getCurrentTransaction()) {
            throw new FBXAException("Prepare called with non-ended xid", XAException.XAER_PROTO);
        }

        FBXid fbxid;
        if (xid instanceof FBXid) {
            fbxid = (FBXid) xid;
        } else {
            fbxid = new FBXid(xid);
        }
        byte[] message = fbxid.toBytes();

        committingTr.prepare(message);
    } catch (SQLException ge) {
        try {
            if (gdsHelper != null) {
                committingTr.rollback();
            } else {
                log.warn("Unable to rollback failed tx, connection closed or lost");
            }
        } catch (SQLException ge2) {
            log.debug("Exception rolling back failed tx: ", ge2);
        } finally {
            xidMap.remove(xid);
        }

        log.warn("error in prepare", ge);
        throw new FBXAException(XAException.XAER_RMERR, ge);
    }

    preparedXid.add(xid);
    return XAResource.XA_OK;
}
 
Example 7
Source File: XASupport.java    From jTDS with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Invoke the xa_end 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
 * @param flags      XA Flags for start command
 * @exception javax.transaction.xa.XAException
 *             if an error condition occurs
 */
public static void xa_end(Connection connection, int xaConId, Xid xid, int flags)
        throws XAException {

    JtdsConnection con = (JtdsConnection)connection;
    if (con.isXaEmulation()) {
        //
        // Emulate xa_end method
        //
        JtdsXid lxid = new JtdsXid(xid);
        if (con.getXaState() != XA_START) {
            // Connection not started
            raiseXAException(XAException.XAER_PROTO);
        }
        JtdsXid tran = (JtdsXid)con.getXid();
        if (tran == null || !tran.equals(lxid)) {
            raiseXAException(XAException.XAER_NOTA);
        }
        if (flags != XAResource.TMSUCCESS &&
            flags != XAResource.TMFAIL) {
            // TMSUSPEND and TMMIGRATE cannot be supported
            raiseXAException(XAException.XAER_INVAL);
        }
        con.setXaState(XA_END);
        return;
    }
    //
    // Execute xa_end via MSDTC
    //
    int args[] = new int[5];
    args[1] = XA_END;
    args[2] = xaConId;
    args[3] = XA_RMID;
    args[4] = flags;
    try {
        ((JtdsConnection) connection).sendXaPacket(args, toBytesXid(xid));
        ((JtdsConnection) connection).enlistConnection(null);
    } catch (SQLException e) {
        raiseXAException(e);
    }
    if (args[0] != XAResource.XA_OK) {
        raiseXAException(args[0]);
    }
}
 
Example 8
Source File: ClientTransactionContext.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public int prepare(Xid xid) throws XAException
{
    // todo: rezaem: we should relay this to the other side
    return XAResource.XA_OK;
}
 
Example 9
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Tell the resource manager to forget about a heuristically (MANUALLY) completed transaction branch.
 *
 * @param xid A global transaction identifier
 *
 * @throws XAException An error has occurred. Possible exception values are XAER_RMERR, XAER_RMFAIL, XAER_NOTA,
 *                     XAER_INVAL, or XAER_PROTO.
 */

public void forget(Xid xid) throws XAException {
    NetAgent netAgent = conn_.netAgent_;
    int rc = XAResource.XA_OK;
    exceptionsOnXA = null;

    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceEntry(this, "forget", xid);
    }
    if (conn_.isPhysicalConnClosed()) {
        connectionClosedFailure();
    }
    NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
    callInfo.xid_ = xid;
    callInfo.xaResource_ = this;
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    try {
        // flow the required PROTOCOL to the server
        netAgent.beginWriteChainOutsideUOW();

        // sent the commit PROTOCOL
        netAgent.netConnectionRequest_.writeXaForget(netAgent.netConnection_, xid);

        netAgent.flowOutsideUOW();

        // read the reply to the commit
        netAgent.netConnectionReply_.readXaForget(netAgent.netConnection_);

        netAgent.endReadChain();
        if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
            callInfo.xaFunction_ = XAFUNC_FORGET;
            rc = xaRetValErrorAccumSQL(callInfo, rc);
            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        }
    } catch (SqlException sqle) {
        exceptionsOnXA = com.pivotal.gemfirexd.internal.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
        throwXAException(XAException.XAER_RMERR);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if (rc != XAResource.XA_OK) {
        throwXAException(rc, false);
    }

}
 
Example 10
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 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 spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
 *
 * @param xid A global transaction identifier
 *
 * @return A value indicating the resource manager's vote on the outcome of the transaction. The possible values
 *         are: XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by
 *         raising an appropriate XAException in the prepare method.
 *
 * @throws XAException An error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL,
 *                     XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 */
public int prepare(Xid xid) throws XAException { // public interface for prepare
    // just call prepareX with the recursion flag set to true
    exceptionsOnXA = null;

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

    /// update the XACallInfo
    NetAgent netAgent = conn_.netAgent_;
    int rc = XAResource.XA_OK;
    NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
    callInfo.xid_ = xid;
    callInfo.xaResource_ = this;
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    try {
        netAgent.beginWriteChainOutsideUOW();
        // sent the prepare PROTOCOL
        netAgent.netConnectionRequest_.writeXaPrepare(conn_);
        netAgent.flowOutsideUOW();

        // read the reply to the prepare
        rc = netAgent.netConnectionReply_.readXaPrepare(conn_);
        if ((callInfo.xaRetVal_ != XAResource.XA_OK) &&
                (callInfo.xaRetVal_ != XAException.XA_RDONLY)) { // xaRetVal has possible error, format it
            callInfo.xaFunction_ = XAFUNC_PREPARE;
            rc = xaRetValErrorAccumSQL(callInfo, rc);
            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        }

        netAgent.endReadChain();
    } catch (SqlException sqle) {
        rc = getSqlExceptionXAErrorCode(sqle);
        exceptionsOnXA = com.splicemachine.db.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if ((rc != XAResource.XA_OK ) && (rc != XAResource.XA_RDONLY)) {
        throwXAException(rc, false);
    }
    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceExit(this, "prepare", rc);
    }
    return rc;
}
 
Example 13
Source File: PerfManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int prepare(Xid xid) throws XAException
{
   return XAResource.XA_OK;
}
 
Example 14
Source File: NetXAResource.java    From spliceengine with GNU Affero General Public License v3.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 = getSqlExceptionXAErrorCode(sqle);
        exceptionsOnXA = com.splicemachine.db.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if (rc != XAResource.XA_OK) {
        throwXAException(rc, false);
    }
 
}
 
Example 15
Source File: XaTest.java    From jTDS with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Test to demonstrate the use of the XA_JOIN command.
 *
 * @throws Exception if an error condition occurs
 */
public void testXAJoinTran() throws Exception {
    if ("true".equalsIgnoreCase(props.getProperty(Messages.get(Driver.XAEMULATION)))) {
        // Emulation mode does not joining transactions.
        return;
    }
    Connection con2 = null;
    Connection con3 = null;
    XAConnection xaCon = null;
    XAConnection xaCon2 = null;

    try {
        dropTable("jTDS_XATEST");
        dropTable("jTDS_XATEST2");

        Statement stmt = con.createStatement();
        stmt.execute("CREATE TABLE jTDS_XATEST (id int primary key, data varchar(255))");
        stmt.execute("CREATE TABLE jTDS_XATEST2 (id int primary key, data varchar(255))");
        assertNotNull(stmt.executeQuery("SELECT * FROM jTDS_XATEST"));
        assertNotNull(stmt.executeQuery("SELECT * FROM jTDS_XATEST2"));
        stmt.close();

        XADataSource xaDS = getDataSource();
        XAResource xaRes;
        XAResource xaRes2;
        Xid  xid;
        xaCon = xaDS.getXAConnection();
        xaRes = xaCon.getXAResource();
        xaCon2 = xaDS.getXAConnection();
        xaRes2 = xaCon2.getXAResource();
        con2 = xaCon.getConnection();
        con3 = xaCon2.getConnection();
        stmt = con2.createStatement();
        Statement stmt2 = con3.createStatement();
        xid = new JtdsXid(new byte[]{0x01}, new byte[]{0x02});

        xaRes.start(xid, XAResource.TMNOFLAGS);
        stmt.executeUpdate("INSERT INTO jTDS_XATEST VALUES (1, 'TEST LINE')");
        assertTrue(xaRes.isSameRM(xaRes2));
        xaRes2.start(xid, XAResource.TMJOIN);
        stmt2.executeUpdate("INSERT INTO jTDS_XATEST2 VALUES (1, 'TEST LINE 2')");
        xaRes.end(xid, XAResource.TMSUCCESS);
        xaRes2.end(xid, XAResource.TMSUCCESS);

        int ret = xaRes.prepare(xid);
        if (ret == XAResource.XA_OK) {
            xaRes.commit(xid, false);
        }
        stmt.close();
        stmt2.close();
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM jTDS_XATEST");
        assertNotNull(rs);
        assertTrue(rs.next());
        rs = stmt.executeQuery("SELECT * FROM jTDS_XATEST2");
        assertNotNull(rs);
        assertTrue(rs.next());
        stmt.close();
    } finally {
        if (con2 != null) {
            con2.close();
        }
        if (con3 != null) {
            con3.close();
        }
        if (xaCon != null) {
            xaCon.close();
        }
        if (xaCon2 != null) {
            xaCon2.close();
        }

        dropTable("jTDS_XATEST");
        dropTable("jTDS_XATEST2");
    }
}
 
Example 16
Source File: NetXAResource.java    From spliceengine with GNU Affero General Public License v3.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 = getSqlExceptionXAErrorCode(sqle);
        exceptionsOnXA = com.splicemachine.db.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: LocalXAResourceImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int prepare(Xid xid) throws XAException
{
   return XAResource.XA_OK;
}
 
Example 18
Source File: JMSXDeliveryCountTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public int prepare(final Xid arg0) throws XAException {
   return XAResource.XA_OK;
}
 
Example 19
Source File: LocalXAResourceImpl.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int prepare(Xid xid) throws XAException
{
   return XAResource.XA_OK;
}
 
Example 20
Source File: AbstractLuceneIndexerAndSearcherFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int prepare(Xid xid) throws XAException
{
    // TODO: Track state OK, ReadOnly, Exception (=> rolled back?)
    Map<StoreRef, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);
    if (indexers == null)
    {
        if (suspendedIndexersInGlobalTx.containsKey(xid))
        {
            throw new XAException("Trying to commit indexes for a suspended transaction.");
        }
        else
        {
            // nothing to do
            return XAResource.XA_OK;
        }
    }
    boolean isPrepared = true;
    boolean isModified = false;
    for (LuceneIndexer indexer : indexers.values())
    {
        try
        {
            isModified |= indexer.isModified();
            indexer.prepare();
        }
        catch (IndexerException e)
        {
            isPrepared = false;
        }
    }
    if (isPrepared)
    {
        if (isModified)
        {
            return XAResource.XA_OK;
        }
        else
        {
            return XAResource.XA_RDONLY;
        }
    }
    else
    {
        throw new XAException("Failed to prepare: requires rollback");
    }
}