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

📄 t_xa.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            store.startXATransaction(                cm,                42, // fake format id                global_id,                branch_id);		// Create a heap conglomerate.        T_AccessRow template_row = new T_AccessRow(1);		long conglomid =             xa_tc.createConglomerate(                "heap",       // create a heap conglomerate                template_row.getRowArray(), // 1 column template.				null, //column sort order - not required for heap                null,         // default properties                TransactionController.IS_DEFAULT);       // not temporary        // Should be no prepared transactions, there is one update global xact.        if (((XAResourceManager) store.getXAResourceManager()).recover(                XAResource.TMSTARTRSCAN).length != 0)        {			throw T_Fail.testFailMsg(                "recover incorrectly returned prepared xacts.");        }        // commit an idle transaction - using onePhase optimization.        commit_method.commit(true, 42, global_id, branch_id, xa_tc);        // done with this xact.        xa_tc.destroy();        // COMMIT A READ ONLY TRANSACTION.        // Start a global transaction        xa_tc = (XATransactionController)            store.startXATransaction(                cm,                42, // fake format id                global_id,                branch_id);		// Open a scan on the conglomerate.		ScanController scan1 = xa_tc.openScan(			conglomid,			false, // don't hold			0,     // not for update            TransactionController.MODE_RECORD,            TransactionController.ISOLATION_SERIALIZABLE,			(FormatableBitSet) null, // all columns, all as objects			null, // start position - first row in conglomerate            0,    // unused if start position is null.			null, // qualifier - accept all rows			null, // stop position - last row in conglomerate            0);   // unused if stop position is null.        scan1.next();        scan1.close();        // Should be no prepared transactions, there is one update global xact.        if (((XAResourceManager) store.getXAResourceManager()).recover(                XAResource.TMSTARTRSCAN).length != 0)        {			throw T_Fail.testFailMsg(                "recover incorrectly returned prepared xacts.");        }        // commit an idle transaction - using onePhase optimization.        commit_method.commit(true, 42, global_id, branch_id, xa_tc);        // done with this xact.        xa_tc.destroy();        // PREPARE AN UPDATE TRANSACTION.        // Start a global transaction        xa_tc = (XATransactionController)            store.startXATransaction(                cm,                42, // fake format id                global_id,                branch_id);		// Create a heap conglomerate.        template_row = new T_AccessRow(1);		conglomid =             xa_tc.createConglomerate(                "heap",       // create a heap conglomerate                template_row.getRowArray(), // 1 column template.				null, //column sort order - not required for heap                null,         // default properties                TransactionController.IS_DEFAULT);       // not temporary        // Should be no prepared transactions, there is one update global xact.        if (((XAResourceManager) store.getXAResourceManager()).recover(                XAResource.TMSTARTRSCAN).length != 0)        {			throw T_Fail.testFailMsg(                "recover incorrectly returned prepared xacts.");        }        // prepare the update xact.        if (xa_tc.xa_prepare() != XATransactionController.XA_OK)        {			throw T_Fail.testFailMsg(                "prepare of update xact did not return XA_OK.");        }        try        {            // Open a scan on the conglomerate.            scan1 = xa_tc.openScan(                conglomid,                false, // don't hold                0,     // not for update                TransactionController.MODE_RECORD,                TransactionController.ISOLATION_SERIALIZABLE,                (FormatableBitSet) null, // all columns, all as objects                null, // start position - first row in conglomerate                0,    // unused if start position is null.                null, // qualifier - accept all rows                null, // stop position - last row in conglomerate                0);   // unused if stop position is null.            scan1.next();            scan1.close();			throw T_Fail.testFailMsg(                "Should not be able to do anything on xact after prepare.");        }        catch (StandardException se)        {            // expected exception, fall through.        }        // Should be no prepared transactions, there is one update global xact.        Xid[] prepared_xacts =             ((XAResourceManager) store.getXAResourceManager()).recover(                XAResource.TMSTARTRSCAN);        if (prepared_xacts.length != 1)        {			throw T_Fail.testFailMsg(                "recover incorrectly returned wrong prepared xacts.");        }        if (prepared_xacts[0].getFormatId() != 42)			throw T_Fail.testFailMsg(                "bad format id = " + prepared_xacts[0].getFormatId());        byte[] gid = prepared_xacts[0].getGlobalTransactionId();        if (!java.util.Arrays.equals(gid, global_id))        {			throw T_Fail.testFailMsg(                "bad global id = " + org.apache.derbyTesting.unitTests.util.BitUtil.hexDump(gid));        }        byte[] bid = prepared_xacts[0].getBranchQualifier();        if (!java.util.Arrays.equals(bid, branch_id))        {			throw T_Fail.testFailMsg(                "bad branch id = " + org.apache.derbyTesting.unitTests.util.BitUtil.hexDump(bid));        }        if (((XAResourceManager) store.getXAResourceManager()).recover(                XAResource.TMNOFLAGS).length != 0)        {			throw T_Fail.testFailMsg("NOFLAGS should always return 0.");        }        // commit a prepared transaction - using two phase.        commit_method.commit(false, 42, global_id, branch_id, xa_tc);        // Should be no prepared transactions, there is one update global xact.        if (((XAResourceManager) store.getXAResourceManager()).recover(                XAResource.TMSTARTRSCAN).length != 0)        {			throw T_Fail.testFailMsg(                "recover incorrectly returned prepared xacts.");        }        // done with this xact.        xa_tc.destroy();        // Should be no prepared transactions, there is one update global xact.        if (((XAResourceManager) store.getXAResourceManager()).recover(                XAResource.TMSTARTRSCAN).length != 0)        {			throw T_Fail.testFailMsg(                "recover incorrectly returned prepared xacts.");        }        REPORT("(XATest_5) finishing");    }    /**     * Very simple testing of changing a local transaction to a global.     * <p>	 * @exception  StandardException  Standard exception policy.     **/    void XATest_6(    commit_method   commit_method)        throws StandardException, T_Fail    {        REPORT("(XATest_5) starting");        ContextManager cm =                 ContextService.getFactory().getCurrentContextManager();        TransactionController   tc = store.getTransaction(cm);		// Create a heap conglomerate.        T_AccessRow template_row = new T_AccessRow(1);		long conglomid =             tc.createConglomerate(                "heap",       // create a heap conglomerate                template_row.getRowArray(), // 1 column template.				null, //column sort order - not required for heap                null,         // default properties                TransactionController.IS_DEFAULT);       // not temporary        tc.commit();        // COMMIT AN IDLE TRANSACTION.        // Start a global transaction        XATransactionController xa_tc = (XATransactionController)            tc.createXATransactionFromLocalTransaction(                42, // fake format id                global_id,                branch_id);        if (!xa_tc.isGlobal())        {			throw T_Fail.testFailMsg("should be a global transaction.");        }		// Open a scan on the conglomerate.		ScanController scan1 = xa_tc.openScan(			conglomid,			false, // don't hold			0,     // not for update            TransactionController.MODE_RECORD,            TransactionController.ISOLATION_SERIALIZABLE,			(FormatableBitSet) null, // all columns, all as objects			null, // start position - first row in conglomerate            0,    // unused if start position is null.			null, // qualifier - accept all rows			null, // stop position - last row in conglomerate            0);   // unused if stop position is null.        scan1.next();        scan1.close();		// Create a heap conglomerate.        template_row = new T_AccessRow(1);		conglomid =             xa_tc.createConglomerate(                "heap",       // create a heap conglomerate                template_row.getRowArray(), // 1 column template.				null, //column sort order - not required for heap                null,         // default properties                TransactionController.IS_DEFAULT);       // not temporary        // Should be no prepared transactions, there is one update global xact.        if (((XAResourceManager) store.getXAResourceManager()).recover(                XAResource.TMSTARTRSCAN).length != 0)        {			throw T_Fail.testFailMsg(                "recover incorrectly returned prepared xacts.");        }        // prepare the update xact.        if (xa_tc.xa_prepare() != XATransactionController.XA_OK)        {			throw T_Fail.testFailMsg(                "prepare of update xact did not return XA_OK.");        }        try        {            // Open a scan on the conglomerate.            scan1 = xa_tc.openScan(                conglomid,                false, // don't hold                0,     // not for update                TransactionController.MODE_RECORD,                TransactionController.ISOLATION_SERIALIZABLE,                (FormatableBitSet) null, // all columns, all as objects                null, // start position - first row in conglomerate                0,    // unused if start position is null.                null, // qualifier - accept all rows                null, // stop position - last row in conglomerate                0);   // unused if stop position is null.            scan1.next();            scan1.close();			throw T_Fail.testFailMsg(                "Should not be able to do anything on xact after prepare.");        }        catch (StandardException se)        {            // expected exception, fall through.        }        // commit a prepared transaction - using two phase.        commit_method.commit(false, 42, global_id, branch_id, xa_tc);        xa_tc.destroy();        REPORT("(XATest_6) finishing");    }}class commit_method{    private boolean         online_xact;    private AccessFactory   store;    public commit_method(    AccessFactory   store,    boolean         online_xact)    {        this.store       = store;        this.online_xact = online_xact;    }    public void commit(    boolean                 one_phase,    int                     format_id,    byte[]                  global_id,    byte[]                  branch_id,    XATransactionController xa_tc)        throws StandardException    {        if (SanityManager.DEBUG)            SanityManager.ASSERT((global_id != null) || (xa_tc != null));        boolean local_online_xact = online_xact;        if (global_id == null)            local_online_xact = true;        if (xa_tc == null)            local_online_xact = false;                    if (local_online_xact)        {            xa_tc.xa_commit(one_phase);        }        else        {            Xid xid = new XAXactId(format_id, global_id, branch_id);            ContextManager cm =                 ((XAResourceManager) store.getXAResourceManager()).find(xid);            if (SanityManager.DEBUG)            {                SanityManager.ASSERT(cm != null, "could not find xid = " + xid);                SanityManager.ASSERT(                    cm ==                     ContextService.getFactory().getCurrentContextManager(),                    "cm = " + cm +                    "current = " +                         ContextService.getFactory().getCurrentContextManager());            }            ((XAResourceManager) store.getXAResourceManager()).commit(                cm, xid, one_phase);        }    }    public void rollback(    int                     format_id,    byte[]                  global_id,    byte[]                  branch_id,    XATransactionController xa_tc)        throws StandardException    {        if (SanityManager.DEBUG)            SanityManager.ASSERT((global_id != null) || (xa_tc != null));        boolean local_online_xact = online_xact;        if (global_id == null)            local_online_xact = true;        if (xa_tc == null)            local_online_xact = false;                    if (local_online_xact)        {            xa_tc.xa_rollback();        }        else        {            Xid xid = new XAXactId(format_id, global_id, branch_id);            ContextManager cm =                 ((XAResourceManager) store.getXAResourceManager()).find(xid);            if (SanityManager.DEBUG)            {                SanityManager.ASSERT(cm != null, "could not find xid = " + xid);                SanityManager.ASSERT(                    cm ==                     ContextService.getFactory().getCurrentContextManager(),                    "cm = " + cm +                    "current = " +                         ContextService.getFactory().getCurrentContextManager());            }            ((XAResourceManager) store.getXAResourceManager()).rollback(                cm, xid);        }    }}

⌨️ 快捷键说明

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