Package org.apache.derby.iapi.store.access

Examples of org.apache.derby.iapi.store.access.ConglomerateController


                null, //column sort order - not required for heap
                null,     // default properties
                TransactionController.IS_DEFAULT);// not temporary

        // Open the base table
        ConglomerateController base_cc =
            tc.openConglomerate(
                base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        // initialize the secondary index row - pointing it at base row
        RowLocation base_rowloc = base_cc.newRowLocationTemplate();
        index_row.init(base_row, base_rowloc, num_cols + 1);
       
        // create the secondary index
        Properties properties =
            createProperties(
View Full Code Here


        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)
        {
View Full Code Here

        // 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,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        if (!(index_cc instanceof B2IController))
        {
      throw T_Fail.testFailMsg("openConglomerate returned wrong type");
        }

        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);

        // Commit the create of the tables so that the following aborts don't
        // undo that work.
        tc.commit();

        // Now try aborts of transactions during splits, using magic
        // trace flags.  This test inserts enough rows to cause a split
        // and then forces the split to fail at various key points.  The
        // split should be backed out and also the rows before the split.
        // The test makes sure that there are some inserts before the forced
        // split abort.
        String[] debug_strings = {
            "leaf_split_growRoot1",
            "leaf_split_growRoot2",
            "leaf_split_growRoot3",
            "leaf_split_growRoot4",
            "leaf_split_growRoot5",
            "leaf_split_abort1",
            "leaf_split_abort2",
            "leaf_split_abort3",
            "leaf_split_abort4",
            "branch_split_abort1",
            "branch_split_abort2",
            "branch_split_abort3",
            "branch_split_abort4",
            "BTreeController_doIns2"
            };

        for (int errs = 0; errs < debug_strings.length; errs++)
        {
            REPORT("Doing abort test: " + debug_strings[errs]);

            // set the debug flag, which will cause an error
            // RESOLVE (mmm) these tests should be run from the language to
            // make sure error handling really works.

            if (SanityManager.DEBUG)
                SanityManager.DEBUG_SET(debug_strings[errs]);
           
            try
            {

                // Open the base table
                base_cc =
                    tc.openConglomerate(
                        create_ret.base_conglomid,
                        false,
                        TransactionController.OPENMODE_FORUPDATE,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE);

                // Open the secondary index
                index_cc = 
                    tc.openConglomerate(
                        create_ret.index_conglomid,
                        false,
                        TransactionController.OPENMODE_FORUPDATE,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE);

                // insert one row that does not cause failure.
                ((SQLLongint)r1[0]).setValue(2);
                ((SQLLongint)r1[1]).setValue(10000 + errs);

                // Insert the row into the base table;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");


                // set the debug flag, which will cause an error
                // RESOLVE (mmm) these tests should be run from the
                // language to make sure error handling really works.
                if (SanityManager.DEBUG)
                    SanityManager.DEBUG_SET(debug_strings[errs]);

                // now insert enough rows to cause failure
                for (int i = 100; i > 0; i -= 2)
                {
                    ((SQLLongint)r1[0]).setValue(2);
                    ((SQLLongint)r1[1]).setValue(i);

                    // Insert the row into the base table;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");
                    }
                }

                throw T_Fail.testFailMsg(
                    "debug flag (" + debug_strings[errs] +
                    ")did not cause exception.");
            }
            catch (StandardException e)
            {
                ContextService contextFactory = ContextService.getFactory();

                // Get the context manager.
                ContextManager cm = contextFactory.getCurrentContextManager();

                if (SanityManager.DEBUG)
                    SanityManager.ASSERT(cm != null);

                cm.cleanupOnError(e);
               
                // RESOLVE (mikem) - when split abort works come up with
                // a good sanity check here.
                //
                // index check - there should be no records:
                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);


                index_cc = 
                    tc.openConglomerate(
                        create_ret.index_conglomid,
                        false,
                        TransactionController.OPENMODE_FORUPDATE,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE);

                index_cc.checkConsistency();
                index_cc.close();

                if (scan.next())
                {
                    throw T_Fail.testFailMsg(
                            "t_002: there are still rows in table.");
                }


                scan.close();
            }

            // Unset the flag.
            if (SanityManager.DEBUG)
                SanityManager.DEBUG_CLEAR(debug_strings[errs]);
        }

        // Try a simple abort.  The following adds enough rows to cause a
        // split.  The result of the split should be a tree with no rows, but
        // the splits will not be undone.  It is up to the implementation
        // whether the undo's cause shrinks in the tree.  In the initial
        // implementation it won't.
        {
            tc.commit();

            // Open the base table
            base_cc =
                tc.openConglomerate(
                    create_ret.base_conglomid,
                    false,
                    TransactionController.OPENMODE_FORUPDATE,
                    TransactionController.MODE_RECORD,
                    TransactionController.ISOLATION_SERIALIZABLE);

            // Open the secondary index
            index_cc = 
                tc.openConglomerate(
                    create_ret.index_conglomid,
                    false,
                    TransactionController.OPENMODE_FORUPDATE,
                    TransactionController.MODE_RECORD,
                    TransactionController.ISOLATION_SERIALIZABLE);

            // BTree.PROPERTY_MAX_ROWS_PER_PAGE_PARAMETER has been set to 2 so
            // inserting 3 rows will cause a split at the leaf level.
            // Make sure that normal abort leaves the committed split.
            for (int i = 0; i < 3; i++)
            {
                ((SQLLongint)r1[0]).setValue(2);
                ((SQLLongint)r1[1]).setValue(i);

                // Insert the row into the base table;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");
            }

            tc.abort();
View Full Code Here

        null, //column sort order - not required for heap
                null,                              // default properties
                TransactionController.IS_DEFAULT); // not temporary

        // Open the base table
        ConglomerateController base_cc =
            tc.openConglomerate(
                base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        // initialize the secondary index row - pointing it at base row
        index_row.init(base_row, base_cc.newRowLocationTemplate(), 5);

        Properties properties =
            createProperties(
                null,               // no current properties list
                false,              // don't allow duplicates
                5,                  // 4 columns in index row
                5,                  // non-unique index
                true,               // maintain parent links
                base_conglomid,     // base conglom id
                4);                 // row loc in last column

        long index_conglomid =
            tc.createConglomerate(
                "BTREE",            // create a btree secondary
                index_row.getRow(),         // row template
        null, //column sort order - default
                properties,                 // properties
                TransactionController.IS_DEFAULT);   // not temporary

    // Open the conglomerate.
    ConglomerateController index_cc = 
            tc.openConglomerate(
                index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a row.
        T_SecondaryIndexRow template = new T_SecondaryIndexRow();
        RowLocation         row_loc  = base_cc.newRowLocationTemplate();
        template.init(base_row, row_loc, 5);

        // insert them in reverse order just to make sure btree is sorting them
        for (int i = col1.length - 1; i >= 0; i--)
        {
            ((SQLLongint)(template.getRow()[0])).setValue(col1[i]);
            ((SQLLongint)(template.getRow()[1])).setValue(col2[i]);
            ((SQLLongint)(template.getRow()[2])).setValue(col3[i]);
            base_row[3] = new SQLChar(string_1500char);

            base_cc.insertAndFetchLocation(base_row, row_loc);

            // Insert the row.
            // System.out.println("Adding record (" + -(i - (col1.length -1)) +
            //                ")" + template);
            if (index_cc.insert(template.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }

        index_cc.checkConsistency();

        ((B2IController)index_cc).debugConglomerate();

        ret_val = t_003_scan_test_cases(tc, index_conglomid, template);

        // insert and delete some interesting rows, deleted space management
        // may or may not clean these up.
        for (int i = d_col1.length - 1; i >= 0; i--)
        {
            ((SQLLongint)(template.getRow()[0])).setValue(d_col1[i]);
            ((SQLLongint)(template.getRow()[1])).setValue(d_col2[i]);
            ((SQLLongint)(template.getRow()[2])).setValue(d_col3[i]);
            base_row[3] = new SQLChar(string_1500char);

            base_cc.insertAndFetchLocation(base_row, row_loc);

            // Insert the row.
            // System.out.println("Adding record (" + -(i - (col1.length -1)) +
            //                ")" + template);
            if (index_cc.insert(template.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");

            // now delete the row.
            base_cc.delete(row_loc);

            ScanController delete_scan =
                tc.openScan(index_conglomid, false,
                            TransactionController.OPENMODE_FORUPDATE,
                            TransactionController.MODE_RECORD,
                            TransactionController.ISOLATION_SERIALIZABLE,
                            (FormatableBitSet) null,
                            template.getRow(), ScanController.GE,
                            null,
                            template.getRow(), ScanController.GT);

            if (!delete_scan.next())
            {
                throw T_Fail.testFailMsg("delete could not find key");
            }
            else
            {
                delete_scan.delete();

                if (delete_scan.next())
                    throw T_Fail.testFailMsg("delete found more than one key");
            }

            delete_scan.close();
        }

        ret_val = t_003_scan_test_cases(tc, index_conglomid, template);


    // Close the conglomerate.
    index_cc.close();

        tc.commit();
        REPORT("Ending t_003");

        return(ret_val);
View Full Code Here

        T_CreateConglomRet create_ret = new T_CreateConglomRet();

        createCongloms(tc, 2, false, false, 0, create_ret);

    // Open the base conglomerate.
    ConglomerateController base_cc = 
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Open the index conglomerate.
    ConglomerateController index_cc = 
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);


    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
        RowLocation             rowloc    = base_cc.newRowLocationTemplate();
        DataValueDescriptor[]   base_row  = TemplateRow.newU8Row(2);
        index_row.init(base_row, rowloc, 3);

        // insert them in reverse order just to make sure btree is sorting them
        for (int i = 200; i >= 0; i -= 4)
        {
            ((SQLLongint)base_row[0]).setValue(1);
            ((SQLLongint)base_row[1]).setValue(i);
            base_cc.insertAndFetchLocation(base_row, rowloc);

            if (index_cc.insert(index_row.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }
        for (int i = 199; i >= 0; i -= 4)
        {
            ((SQLLongint)base_row[0]).setValue(1);
            ((SQLLongint)base_row[1]).setValue(i);

            base_cc.insertAndFetchLocation(base_row, rowloc);
            if (index_cc.insert(index_row.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }

        index_cc.checkConsistency();

    // Close the conglomerate.
    index_cc.close();

        tc.commit();

        // Search for each of the keys and delete them one at a time.
        DataValueDescriptor[] delete_key = TemplateRow.newU8Row(2);
        for (int i = 200; i >= 0; i -= 4)
        {
            ((SQLLongint)delete_key[0]).setValue(1);
            ((SQLLongint)delete_key[1]).setValue(i);

            if (!t_delete(
                tc, create_ret.index_conglomid, delete_key, index_row.getRow()))
            {
                ret_val = false;
            }
        }
        for (int i = 199; i >= 0; i -= 4)
        {
            ((SQLLongint)delete_key[0]).setValue(1);
            ((SQLLongint)delete_key[1]).setValue(i);

            if (!t_delete(
                tc, create_ret.index_conglomid, delete_key, index_row.getRow()))
            {
                ret_val = false;
            }
        }

        tc.commit();

    // Open the base conglomerate.
    base_cc =
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);


    // Open the conglomerate.
    index_cc =
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        // flush and empty cache to make sure rereading stuff works.
        RawStoreFactory rawstore =
            (RawStoreFactory) Monitor.findServiceModule(
                this.store_module, RawStoreFactory.MODULE);

        rawstore.idle();

        // now make sure that additional splits don't cause delete bits to
        // be enabled (one early bug did so).
       
        for (int i = 200; i >= 0; i -= 3)
        {
            ((SQLLongint)base_row[0]).setValue(1);
            ((SQLLongint)base_row[1]).setValue(i);

            base_cc.insertAndFetchLocation(base_row, rowloc);
            if (index_cc.insert(index_row.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }
        for (int i = 200; i >= 0; i -= 3)
        {
            ((SQLLongint)delete_key[0]).setValue(1);
            ((SQLLongint)delete_key[1]).setValue(i);

            if (!t_delete(
                tc, create_ret.index_conglomid, delete_key, index_row.getRow()))
            {
                ret_val = false;
            }
        }

        // index check - there should be no records left.
        ScanController empty_scan =
            tc.openScan(create_ret.index_conglomid, false,
                        0,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
            (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);
        if (empty_scan.next())
      throw T_Fail.testFailMsg("t_005: there are still rows in table.");

        index_cc.checkConsistency();

        for (int i = 600; i >= 400; i -= 3)
        {
            ((SQLLongint)base_row[0]).setValue(1);
            ((SQLLongint)base_row[1]).setValue(i);

            base_cc.insertAndFetchLocation(base_row, rowloc);
            if (index_cc.insert(index_row.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }

        index_cc.checkConsistency();

        tc.abort();

        // index check - there should be no records left.
        empty_scan =
View Full Code Here

        T_CreateConglomRet create_ret = new T_CreateConglomRet();

        createCongloms(tc, 2, false, false, 0, create_ret);

    // Open the base conglomerate.
    ConglomerateController base_cc = 
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Open the index conglomerate.
    ConglomerateController index_cc = 
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a base row template.
        DataValueDescriptor[]   base_row    = TemplateRow.newU8Row(2);
        RowLocation             base_rowloc = base_cc.newRowLocationTemplate();

        T_SecondaryIndexRow index_row_from_base_row = new T_SecondaryIndexRow();
        index_row_from_base_row.init(base_row, base_rowloc, 3);
        ((SQLLongint)base_row[0]).setValue(1);

    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
        index_row.init(TemplateRow.newU8Row(2),
                        base_cc.newRowLocationTemplate(), 3);

        // test: make sure scan position is right after inserts before scan
        //       no split case.  In this case the slot position of the current
        //       position should change, but the code will keep a record handle
        //       and not need to reposition by key.
        // before keys: 1000, 3000
        // last key gotten froms scan : 0
        // insert keys:1-900
        // next key from scan should be: 5

        // insert 1000
        ((SQLLongint)base_row[1]).setValue(1000);
        base_cc.insertAndFetchLocation(base_row, base_rowloc);
        if (index_cc.insert(index_row_from_base_row.getRow()) != 0)
        {
      throw T_Fail.testFailMsg("insert failed");
        }

        // try each of the unsupported interfaces:
        try
        {
            index_cc.delete(null);
            return(FAIL("t_006: ConglomerateController.delete() succeeded."));
        }
        catch (StandardException e)
        {
        }
        try
        {
            if (!index_cc.fetch(
                    null, RowUtil.EMPTY_ROW, (FormatableBitSet) null))
            {
                return(FAIL("t_006: ConglomerateController.fetch() bad ret."));
            }
            return(FAIL("t_006: ConglomerateController.fetch() succeeded."));
        }
        catch (StandardException e)
        {
        }
        try
        {
            index_cc.insertAndFetchLocation((DataValueDescriptor[]) null, null);
            return(FAIL(
                "t_006: ConglomerateController.insertAndFetchLocation() succeeded."));
        }
        catch (StandardException e)
        {
        }
        try
        {
            RowLocation rowloc = index_cc.newRowLocationTemplate();
            return(FAIL(
                "t_006: ConglomerateController.newRowLocationTemplate() succeeded."));
        }
        catch (StandardException e)
        {
        }
        try
        {
            index_cc.replace(null, null, null);
            return(FAIL("t_006: ConglomerateController.replace() succeeded."));
        }
        catch (StandardException e)
        {
        }

        index_cc.close();

        // open a new scan

        ScanController scan =
            tc.openScan(create_ret.index_conglomid, false,
View Full Code Here

        T_CreateConglomRet create_ret = new T_CreateConglomRet();

        createCongloms(tc, 2, false, false, 0, create_ret);

    // Open the base conglomerate.
    ConglomerateController base_cc = 
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Open the index conglomerate.
    ConglomerateController index_cc = 
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a row.
    T_SecondaryIndexRow   index_row = new T_SecondaryIndexRow();
        DataValueDescriptor[] base_row  = TemplateRow.newU8Row(2);
        RowLocation           row_loc   = base_cc.newRowLocationTemplate();
        index_row.init(base_row, row_loc, 3);

    // Create a row.
        ((SQLLongint)(index_row.getRow()[0])).setValue(1);

        // test: make sure scan position is right after inserts before scan
        //       no split case.  In this case the slot position of the current
        //       position should change, but the code will keep a record handle
        //       and not need to reposition by key.
        // before keys: 3, 5
        // last key gotten froms scan : 0
        // insert keys:1, 2
        // next key from scan should be: 5

        // insert 3
        ((SQLLongint)(index_row.getRow()[1])).setValue(3);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        if (index_cc.insert(index_row.getRow()) != 0)
      throw T_Fail.testFailMsg("insert failed");

        // insert 5
        ((SQLLongint)(index_row.getRow()[1])).setValue(5);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        if (index_cc.insert(index_row.getRow()) != 0)
      throw T_Fail.testFailMsg("insert failed");

        // open a new scan

        ScanController scan =
            tc.openScan(create_ret.index_conglomid, false,
                        0,                       
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
            (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(scan.next());

        scan.fetch(index_row.getRow());
        long key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 3);

        // insert 1
        ((SQLLongint)(index_row.getRow()[1])).setValue(1);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        if (index_cc.insert(index_row.getRow()) != 0)
      throw T_Fail.testFailMsg("insert failed");

        // insert 2
        ((SQLLongint)(index_row.getRow()[1])).setValue(2);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        if (index_cc.insert(index_row.getRow()) != 0)
      throw T_Fail.testFailMsg("insert failed");

        // current position should not have changed
        scan.fetch(index_row.getRow());
        key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 3);

        // next position should be 5
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(scan.next());
        scan.fetch(index_row.getRow());
        key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 5);

        index_cc.close();
        scan.close();

        REPORT("Ending t_007");

        return(ret_val);
View Full Code Here

        T_CreateConglomRet create_ret = new T_CreateConglomRet();

        createCongloms(tc, 2, false, false, 0, create_ret);

    // Open the base conglomerate.
    ConglomerateController base_cc = 
            tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Open the index conglomerate.
    ConglomerateController index_cc = 
            tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a base row template.
        DataValueDescriptor[]   base_row    = TemplateRow.newU8Row(2);
        RowLocation             base_rowloc = base_cc.newRowLocationTemplate();

        T_SecondaryIndexRow index_row_from_base_row = new T_SecondaryIndexRow();
        index_row_from_base_row.init(base_row, base_rowloc, 3);
        ((SQLLongint)base_row[0]).setValue(1);

    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
        index_row.init(TemplateRow.newU8Row(2),
                        base_cc.newRowLocationTemplate(), 3);

        // test: make sure scan position is right after inserts before scan
        //       no split case.  In this case the slot position of the current
        //       position should change, but the code will keep a record handle
        //       and not need to reposition by key.
        // before keys: 1000, 3000
        // last key gotten froms scan : 0
        // insert keys:1-900
        // next key from scan should be: 5

        // insert 1000
        ((SQLLongint)base_row[1]).setValue(1000);
        base_cc.insertAndFetchLocation(base_row, base_rowloc);
        if (index_cc.insert(index_row_from_base_row.getRow()) != 0)
        {
      throw T_Fail.testFailMsg("insert failed");
        }

        // open a new scan

        ScanController scan =
            tc.openScan(create_ret.index_conglomid, false,
                        0,
                        TransactionController.MODE_RECORD,
                        TransactionController.ISOLATION_SERIALIZABLE,
            (FormatableBitSet) null,
                        null, ScanController.NA,
                        null,
                        null, ScanController.NA);

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(scan.next());

        scan.fetch(index_row.getRow());
        long key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 1000);

        // The following test works best if 5 rows fit on one page

        //for (int i = 1; i < 900; i++)
        for (int i = 0; i < 6; i++)
        {
            // insert i
            ((SQLLongint)base_row[1]).setValue(i);
            base_cc.insertAndFetchLocation(base_row, base_rowloc);

            if (index_cc.insert(index_row_from_base_row.getRow()) != 0)
            {
                throw T_Fail.testFailMsg("insert failed");
            }

            // About every 2nd split page, recheck the position
           
            if (i % 10 == 0)
            {
                // current position should not have changed
                scan.fetch(index_row.getRow());
                key = ((SQLLongint)(index_row.getRow()[1])).getLong();
                if (SanityManager.DEBUG)
                    SanityManager.ASSERT(key == 1000);
            }

        }

        // insert 3000
        ((SQLLongint)base_row[1]).setValue(3000);
        base_cc.insertAndFetchLocation(base_row, base_rowloc);
        if (index_cc.insert(index_row_from_base_row.getRow()) != 0)
        {
      throw T_Fail.testFailMsg("insert failed");
        }

        // current position should not have changed
        scan.fetch(index_row.getRow());
        key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 1000);

        // next position should be 3000
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(scan.next());
        scan.fetch(index_row.getRow());
        key = ((SQLLongint)(index_row.getRow()[1])).getLong();

        if (SanityManager.DEBUG)
            SanityManager.ASSERT(key == 3000);

        index_cc.checkConsistency();

        index_cc.close();
        scan.close();

        REPORT("Ending t_008");

        return(ret_val);
View Full Code Here

        T_CreateConglomRet create_ret = new T_CreateConglomRet();

        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,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // 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(1);
        ((SQLLongint)r1[1]).setValue(1000);

        // Insert the row into the base table;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");

        if (index_cc.insert(index_row1.getRow()) !=
                ConglomerateController.ROWISDUPLICATE)
        {
            throw T_Fail.testFailMsg(
                "insert of duplicate returned wrong return value:");
        }

        // Delete the only entry and make sure it can be reinserted in same
        // xact.
        DataValueDescriptor[] delete_key = TemplateRow.newU8Row(2);
        ((SQLLongint)delete_key[0]).setValue(1);
        ((SQLLongint)delete_key[1]).setValue(1000);

        if (!t_delete(tc, create_ret.index_conglomid,
                 delete_key, create_ret.index_template_row))
        {
            throw T_Fail.testFailMsg(
                "t_008: could not delete key.");
        }

        if (index_cc.insert(index_row1.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");

        tc.commit();

        // UNIQUE INDEX
        create_ret = new T_CreateConglomRet();

        // Create the btree so that it only allows 2 rows per page.
        createCongloms(tc, 2, true, false, 2, create_ret);

        // Open the base table
        base_cc = tc.openConglomerate(
                create_ret.base_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Open the secondary index
    index_cc =  tc.openConglomerate(
                create_ret.index_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a row and insert into base table, remembering it's location.
    r1              = TemplateRow.newU8Row(2);
        index_row1      = new T_SecondaryIndexRow();
        base_rowloc1    = base_cc.newRowLocationTemplate();

        index_row1.init(r1, base_rowloc1, 3);

        ((SQLLongint)r1[0]).setValue(1);
        ((SQLLongint)r1[1]).setValue(1000);

        // Insert the row into the base table;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");

        // Insert the row into the base table;remember its location.
        base_cc.insertAndFetchLocation(r1, base_rowloc1);

        // Insert the row into the secondary index.
        if (index_cc.insert(index_row1.getRow()) !=
                ConglomerateController.ROWISDUPLICATE)
        {
            throw T_Fail.testFailMsg(
                "insert of duplicate returned wrong return value:");
        }

        // Delete the only entry and make sure it can be reinserted in same
        // xact.
        delete_key = TemplateRow.newU8Row(2);
        ((SQLLongint)delete_key[0]).setValue(1);
        ((SQLLongint)delete_key[1]).setValue(1000);

        if (!t_delete(tc, create_ret.index_conglomid,
                 delete_key, create_ret.index_template_row))
        {
            throw T_Fail.testFailMsg(
                "t_008: could not delete key.");
        }


        if (index_cc.insert(index_row1.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");

        REPORT("Ending t_009");

        return(true);
View Full Code Here

            // the following open should fail with a containerNotFound error
           
            // for testing purposes - assume TransactionController can be casted
            TransactionManager tm = (TransactionManager) tc;
            ConglomerateController cc =
                testbtree.open(
                    tm, tm.getRawStoreXact(), false, 0, 0,
                    (LockingPolicy) null,
                    null, null);

            throw T_Fail.testFailMsg("bad open succeeded.");
        }
        catch(StandardException t)
        {
            // expected path comes here.
        }


        // create the base table
        DataValueDescriptor[]   base_row        = TemplateRow.newU8Row(2);
        T_SecondaryIndexRow     index_row1      = new T_SecondaryIndexRow();

        long base_conglomid = tc.createConglomerate(
                                        "heap",   // create a heap conglomerate
                                        base_row, // base table template row
                    null, //column sort order - not required for heap
                                        null,     // default properties
                                        TransactionController.IS_DEFAULT);
        // Open the base table
        ConglomerateController base_cc =
            tc.openConglomerate(
                base_conglomid,
                false,
                0,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        RowLocation         base_rowloc1    = base_cc.newRowLocationTemplate();

        index_row1.init(base_row, base_rowloc1, 3);

        // create the secondary index
        Properties properties =
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.store.access.ConglomerateController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.