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

📄 t_b2i.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    int                     start_op,    Qualifier               qualifier[][],    DataValueDescriptor[]	stop_key,    int                     stop_op,    int                     expect_numrows,    int                     expect_key)        throws StandardException    {        // open a new scan        ScanController scan =             tc.openScan(                conglomid,                 false,                TransactionController.OPENMODE_FORUPDATE,                TransactionController.MODE_RECORD,                TransactionController.ISOLATION_SERIALIZABLE,                (FormatableBitSet) null,                start_key, start_op,                qualifier,                stop_key, stop_op);        long key     = -42;        long numrows = 0;        while (scan.next())        {            scan.fetch(template);            key = ((SQLLongint)template[2]).getLong();            if (key != expect_key)            {                return(                    FAIL("(t_scan) wrong key, expected (" + expect_key + ")" +                     "but got (" + key + ")."));            }            else            {                expect_key++;                numrows++;            }        }        ((B2IForwardScan)scan).checkConsistency();                scan.close();        if (numrows != expect_numrows)        {            return(FAIL("(t_scan) wrong number of rows. Expected " +                 expect_numrows + " rows, but got " + numrows + "rows."));        }        return(true);    }    /**     * delete a single key, given key value.  assumes 3 column table, first     * column = 1, second column is a unique key, and 3rd column is a      * RecordHandle into the base table.     *	 * @exception  StandardException  Standard exception policy.     */    protected boolean t_delete(    TransactionController   tc,    long                    conglomid,    DataValueDescriptor[]   search_key,    DataValueDescriptor[]   template)         throws StandardException    {        SQLLongint column0 = new SQLLongint(-1);        SQLLongint column1 = new SQLLongint(-1);        // open a new scan        ScanController scan =             tc.openScan(conglomid, false,                        TransactionController.OPENMODE_FORUPDATE,                        TransactionController.MODE_RECORD,                        TransactionController.ISOLATION_SERIALIZABLE,                        (FormatableBitSet) null,                        search_key, ScanController.GE,                         null,                        search_key, ScanController.GT);         long expect_key =             ((SQLLongint) search_key[1]).getLong();        int numrows = 0;		DataValueDescriptor[] partialRow = new DataValueDescriptor[2];		partialRow[0] = column0;		partialRow[1] = column1;        while (scan.next())        {            numrows++;			scan.fetch(partialRow);            if (column0.getLong() != 1)                return(FAIL("(t_delete) column[0] value is not 1"));            if (column1.getLong() != expect_key)                return(                    FAIL("(t_delete) column[1]  value is not " + expect_key));            if (!scan.delete())            {                return(FAIL("(t_delete): delete of row failed"));            }            if (scan.delete())            {                return(FAIL("(t_delete): re-delete of row succeeded"));            }        }        scan.close();        // This function expects unique keys, so scan should find single row.        if (numrows != 1)        {            return(FAIL("(t_delete) wrong number of rows. Expected " +                   "1 row, but got " + numrows + "rows."));        }        return(true);    }    /**     * Test BTreeController.insert()     * <p>     * Just verify that insert code works for a secondary index.  Just call     * the interface and make sure the row got there.     *	 * @exception  StandardException  Standard exception policy.	 * @exception  T_Fail  Throws T_Fail on any test failure.     **/    protected boolean t_001(TransactionController tc)        throws StandardException, T_Fail    {        REPORT("Starting t_001");        T_CreateConglomRet create_ret = new T_CreateConglomRet();        createCongloms(tc, 2, false, false, 0, create_ret);        // Open the base table        ConglomerateController base_cc =             tc.openConglomerate(                create_ret.base_conglomid,                 false,                TransactionController.OPENMODE_FORUPDATE,                TransactionController.MODE_RECORD,                TransactionController.ISOLATION_SERIALIZABLE);		// Open the secondary index		ConglomerateController index_cc =	            tc.openConglomerate(                create_ret.index_conglomid,                 false,                TransactionController.OPENMODE_FORUPDATE,                TransactionController.MODE_RECORD,                TransactionController.ISOLATION_SERIALIZABLE);        if (!(index_cc instanceof B2IController))        {			throw T_Fail.testFailMsg("openConglomerate returned wrong type");        }        if (!index_cc.isKeyed())        {			throw T_Fail.testFailMsg("btree is not keyed.");        }        index_cc.checkConsistency();		// Create a row and insert into base table, remembering it's location.		DataValueDescriptor[] r1             = TemplateRow.newU8Row(2);        T_SecondaryIndexRow  index_row1      = new T_SecondaryIndexRow();        RowLocation          base_rowloc1    = base_cc.newRowLocationTemplate();        index_row1.init(r1, base_rowloc1, 3);		((SQLLongint) r1[0]).setValue(2);		((SQLLongint) r1[1]).setValue(2);		// Insert the row into the base table and remember its location.		base_cc.insertAndFetchLocation(r1, base_rowloc1);        // Insert the row into the secondary index.        if (index_cc.insert(index_row1.getRow()) != 0)			throw T_Fail.testFailMsg("insert failed");		// Make sure we read back the value we wrote from base and index table.		DataValueDescriptor[] r2            = TemplateRow.newU8Row(2);        T_SecondaryIndexRow   index_row2    = new T_SecondaryIndexRow();        RowLocation           base_rowloc2  = base_cc.newRowLocationTemplate();        index_row2.init(r2, base_rowloc2, 3);        // base table check:        if (!base_cc.fetch(base_rowloc1, r2, (FormatableBitSet) null))        {            return(FAIL("(t_001) insert into base table failed"));        }        if (((SQLLongint) r2[0]).getLong() != 2 ||            ((SQLLongint) r2[1]).getLong() != 2)        {            return(FAIL("(t_001) insert into base table failed"));        }        // index check - there should be only one record:        ScanController scan =             tc.openScan(create_ret.index_conglomid, false,                        TransactionController.OPENMODE_FORUPDATE,                        TransactionController.MODE_RECORD,                        TransactionController.ISOLATION_SERIALIZABLE,						(FormatableBitSet) null,                        null, ScanController.NA,                        null,                        null, ScanController.NA);        scan.next();        scan.fetch(index_row2.getRow());        // delete the only row in the table, and make sure         // isCurrentPositionDeleted() works.        if (scan.isCurrentPositionDeleted())            throw T_Fail.testFailMsg("current row should not be deleted\n");        if (!scan.doesCurrentPositionQualify())            throw T_Fail.testFailMsg("current row should still qualify\n");        scan.delete();        if (!scan.isCurrentPositionDeleted())            throw T_Fail.testFailMsg("current row should be deleted\n");        if (scan.doesCurrentPositionQualify())            throw T_Fail.testFailMsg("deleted row should not qualify\n");        // just call the debugging code to make sure it doesn't fail.        REPORT("Calling scan.tostring(): " + scan);        if (scan.next()                                                     ||            ((SQLLongint)(index_row2.getRow()[0])).getLong() != 2 ||            ((SQLLongint)(index_row2.getRow()[1])).getLong() != 2)        {            return(FAIL("(t_001) insert into index failed in base cols"));        }        // test the scaninfo interface.        ScanInfo   scan_info = scan.getScanInfo();        Properties prop      = scan_info.getAllScanInfo(null);        if (Integer.parseInt(prop.getProperty(		   MessageService.getTextMessage(SQLState.STORE_RTS_NUM_PAGES_VISITED)))				!= 1)        {            throw T_Fail.testFailMsg(                "(scanInfo) wrong numPagesVisited.  Expected 1, got " +                 Integer.parseInt(prop.getProperty(					MessageService.getTextMessage(								SQLState.STORE_RTS_NUM_PAGES_VISITED))));        }        if (Integer.parseInt(prop.getProperty(			MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_VISITED)))				!= 1)        {            throw T_Fail.testFailMsg(                "(scanInfo) wrong numRowsVisited. Expected 1, got " +                 Integer.parseInt(prop.getProperty(					MessageService.getTextMessage(								SQLState.STORE_RTS_NUM_ROWS_VISITED))));        }        if (Integer.parseInt(prop.getProperty(		  MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_QUALIFIED)))				!= 1)        {            throw T_Fail.testFailMsg(                "(scanInfo) wrong numRowsQualified. Expected 1, got " +                 Integer.parseInt(prop.getProperty(		   			MessageService.getTextMessage(								SQLState.STORE_RTS_NUM_ROWS_QUALIFIED))));        }        int compare_result = base_rowloc1.compare(base_rowloc2);        if (compare_result != 0)        {            return(FAIL("(t_001) insert into index failed in recordhandle.\n" +                        "\texpected RecordHandle = " + base_rowloc1 + "\n" +                        "\tgot      RecordHandle = " + base_rowloc2 +                         "\tcompare result = " + compare_result));        }        index_cc.checkConsistency();		// Close the conglomerates.		base_cc.close();		index_cc.close();        try         {            base_cc.insert(r1);            return(FAIL("(t_001) insert on closed conglomerate worked"));        }        catch (StandardException e)        {            // e.printStackTrace();        }        try         {            if (index_cc.insert(r1) != 0)                throw T_Fail.testFailMsg("insert failed");            return(FAIL("(t_001) insert on closed conglomerate worked"));        }        catch (StandardException e)        {            // e.printStackTrace();        }        tc.commit();        REPORT("Ending t_001");        return true;    }    /**     * Test backout during critical times of splits.     * <p>     * Use trace points to force errors in split at critical points:     *     leaf_split_abort{1,2,3,4}     *	 * @exception  StandardException  Standard exception policy.	 * @exception  T_Fail  Throws T_Fail on any test failure.     **/    protected boolean t_002(TransactionController tc)        throws StandardException, T_Fail    {        ScanController scan         = null;        // SanityManager.DEBUG_SET("LockTrace");        REPORT("Starting t_002");        T_CreateConglomRet create_ret = new T_CreateConglomRet();        // Create the btree so that it only allows 2 rows per page.        createCongloms(tc, 2, false, false, 2, create_ret);        // Open the base table        ConglomerateController base_cc =             tc.openConglomerate(                create_ret.base_conglomid,                 false,                TransactionController.OPENMODE_FORUPDATE,                TransactionController.MODE_RECORD,                TransactionController.ISOLATION_SERIALIZABLE);		// Open the secondary index		ConglomerateController index_cc =	            tc.openConglomerate(                create_ret.index_conglomid,                false,

⌨️ 快捷键说明

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