⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netxaresource.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */    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 = XAException.XAER_RMERR;            exceptionsOnXA = org.apache.derby.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;    }    /**     * 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 = org.apache.derby.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;    }    /**     * 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 = org.apache.derby.client.am.Utils.accumulateSQLException                    (sqle, exceptionsOnXA);        } finally {            conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo        }        if (rc != XAResource.XA_OK) {            throwXAException(rc, false);        }     }    /**     * <P>Set the current transaction timeout value for this <CODE>XAResource</CODE> instance. This value overwrites the     * default transaction timeout value in the resource manager. The newly assigned timeout value is effective for the     * life of this <CODE>XAResource</CODE> instance unless a new value is set.<P>     *     * @param the transaction timeout value in seconds.     *     * @throws XAException An error has occurred. Possible exception values are XAER_RMERR, XAER_RMFAIL, or XAER_INVAL.     */    public boolean setTransactionTimeout(int seconds) throws XAException {        if (conn_.agent_.loggingEnabled()) {            conn_.agent_.logWriter_.traceExit(this, "setTransactionTimeout", false);        }        exceptionsOnXA = null;        return false; // we don't support transaction timeout in our layer.        /* int rc = xaSetTransTimeOut(seconds);           if (rc != XAResource.XA_OK)             throwXAException(rc); */    }    /**     * Start work on behalf of a transaction branch specified in xid     *     * @param xid   A global transaction identifier to be associated with the resource     * @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME     *     * @throws XAException An error has occurred. Possible exceptions   * are XA_RB*, XAER_RMERR, XAER_RMFAIL,     *                     XAER_DUPID, XAER_OUTSIDE, XAER_NOTA, XAER_INVAL, or XAER_PROTO.     */    public synchronized void start(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, "start", xid, flags);        }        if (conn_.isPhysicalConnClosed()) {            connectionClosedFailure();        }                // DERBY-1025 - Flow an auto-commit if in auto-commit mode before         // entering a global transaction        try {        	if(conn_.autoCommit_)        		conn_.flowAutoCommit();        } catch (SqlException sqle) {        	rc = XAException.XAER_RMERR;            exceptionsOnXA = org.apache.derby.client.am.Utils.accumulateSQLException                    (sqle, exceptionsOnXA);        }         // update the XACallInfo        NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];        callInfo.xaFlags_ = flags;        callInfo.xaInProgress_ = true;        callInfo.xid_ = xid;        callInfo.xaResource_ = this;        callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL        try {            netAgent.beginWriteChainOutsideUOW();            netAgent.netConnectionRequest_.writeXaStartUnitOfWork(conn_);            netAgent.flowOutsideUOW();            netAgent.netConnectionReply_.readXaStartUnitOfWork(conn_);            if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it                callInfo.xaFunction_ = XAFUNC_START;                rc = xaRetValErrorAccumSQL(callInfo, rc);                callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL            }            // Setting this is currently required to avoid client from sending            // commit for autocommit.            if (rc == XAResource.XA_OK) {                conn_.setXAState(Connection.XA_T1_ASSOCIATED);            }        } catch (SqlException sqle) {            rc = XAException.XAER_RMERR;            exceptionsOnXA = org.apache.derby.client.am.Utils.accumulateSQLException                    (sqle, exceptionsOnXA);        } finally {            conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo        }        if (rc != XAResource.XA_OK) {            throwXAException(rc, false);        }    }    protected void throwXAException(int rc) throws XAException {        throwXAException(rc, rc != XAException.XAER_NOTA);    }    private String getXAExceptionText(int rc) {        String xaExceptionText;        switch (rc) {        case javax.transaction.xa.XAException.XA_RBROLLBACK:            xaExceptionText = "XA_RBROLLBACK";            break;        case javax.transaction.xa.XAException.XA_RBCOMMFAIL:            xaExceptionText = "XA_RBCOMMFAIL";            break;        case javax.transaction.xa.XAException.XA_RBDEADLOCK:            xaExceptionText = "XA_RBDEADLOCK";            break;        case javax.transaction.xa.XAException.XA_RBINTEGRITY:            xaExceptionText = "XA_RBINTEGRITY";            break;        case javax.transaction.xa.XAException.XA_RBOTHER:            xaExceptionText = "XA_RBOTHER";            break;        case javax.transaction.xa.XAException.XA_RBPROTO:            xaExceptionText = "XA_RBPROTO";            break;        case javax.transaction.xa.XAException.XA_RBTIMEOUT:            xaExceptionText = "XA_RBTIMEOUT";            break;        case javax.transaction.xa.XAException.XA_RBTRANSIENT:            xaExceptionText = "XA_RBTRANSIENT";            break;        case javax.transaction.xa.XAException.XA_NOMIGRATE:            xaExceptionText = "XA_NOMIGRATE";            break;        case javax.transaction.xa.XAException.XA_HEURHAZ:            xaExceptionText = "XA_HEURHAZ";            break;        case javax.transaction.xa.XAException.XA_HEURCOM:            xaExceptionText = "XA_HEURCOM";            break;        case javax.transaction.xa.XAException.XA_HEURRB:            xaExceptionText = "XA_HEURRB";            break;        case javax.transaction.xa.XAException.XA_HEURMIX:            xaExceptionText = "XA_HEURMIX";            break;        case javax.transaction.xa.XAException.XA_RETRY:            xaExceptionText = "XA_RETRY";            break;        case javax.transaction.xa.XAException.XA_RDONLY:            xaExceptionText = "XA_RDONLY";            break;        case javax.transaction.xa.XAException.XAER_ASYNC:            xaExceptionText = "XAER_ASYNC";            break;        case javax.transaction.xa.XAException.XAER_RMERR:            xaExceptionText = "XAER_RMERR";            break;        case javax.transaction.xa.XAException.XAER_NOTA:            xaExceptionText = "XAER_NOTA";            break;        case javax.transaction.xa.XAException.XAER_INVAL:            xaExceptionText = "XAER_INVAL";            break;        case javax.transaction.xa.XAException.XAER_PROTO:            xaExceptionText = "XAER_PROTO";            break;        case javax.transaction.xa.XAException.XAER_RMFAIL:            xaExceptionText = "XAER_RMFAIL";            break;        case javax.transaction.xa.XAException.XAER_DUPID:            xaExceptionText = "XAER_DUPID";            break;        case javax.transaction.xa.XAException.XAER_OUTSIDE:            xaExceptionText = "XAER_OUTSIDE";            break;        case XAResource.XA_OK:            xaExceptionText = "XA_OK";            break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -