Examples of ScanController


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

               TransactionController  tc,
               boolean wait)
    throws StandardException
  {
    ConglomerateController    heapCC;
    ScanController        drivingScan;
    ExecIndexRow         drivingIndexRow;
    RowLocation          baseRowLocation;
    ExecIndexRow        templateRow;
    ExecRow            baseRow = crf.makeEmptyRow();

    if (SanityManager.DEBUG)
    {
      SanityManager.ASSERT( indicesToUpdate.length == crf.getNumIndexes(),
                 "Wrong number of indices." );
    }

    RowChanger           rc  = getRowChanger( tc, colsToUpdate,baseRow );

    // Row level locking
    rc.openForUpdate(indicesToUpdate, TransactionController.MODE_RECORD, wait);

    /* Open the heap conglomerate */
    heapCC = tc.openConglomerate(
                    getHeapConglomerate(),
                    false,
                    (TransactionController.OPENMODE_FORUPDATE |
                    ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)),
                    TransactionController.MODE_RECORD,
                    TransactionController.ISOLATION_REPEATABLE_READ);

    drivingScan = tc.openScan(
      getIndexConglomerate(indexNumber)// conglomerate to open
      false, // don't hold open across commit
      (TransactionController.OPENMODE_FORUPDATE |
            ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)),
            TransactionController.MODE_RECORD,
            TransactionController.ISOLATION_REPEATABLE_READ,
      (FormatableBitSet) null,     // all fields as objects
      key.getRowArray(),   // start position - first row
            ScanController.GE,      // startSearchOperation
      null, //scanQualifier
      key.getRowArray(),   // stop position - through last row
            ScanController.GT);     // stopSearchOperation

    // Get an index row based on the base row
    drivingIndexRow = getIndexRowFromHeapRow(
      getIndexRowGenerator( indexNumber ),
      heapCC.newRowLocationTemplate(),
      crf.makeEmptyRow());

    int rowNum = 0;
    while (drivingScan.fetchNext(drivingIndexRow.getRowArray()))
    {
      baseRowLocation = (RowLocation)
            drivingIndexRow.getColumn(drivingIndexRow.nColumns());
      boolean base_row_exists =
                heapCC.fetch(
                    baseRowLocation, baseRow.getRowArray(), (FormatableBitSet) null);

            if (SanityManager.DEBUG)
            {
                // it can not be possible for heap row to disappear while
                // holding scan cursor on index at ISOLATION_REPEATABLE_READ.
                SanityManager.ASSERT(base_row_exists, "base row not found");
            }
     
      rc.updateRow(baseRow, (rowNum == newRows.length - 1) ?
            newRows[rowNum] : newRows[rowNum++], baseRowLocation );
    }
    rc.finish();
    heapCC.close();
    drivingScan.close();
    rc.close();
  }
View Full Code Here

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

    ConglomerateDescriptor  indexCD;
    ExecRow          baseRow;
    ExecRow          indexRow;
    RowLocation        rl = null;
    RowLocation        scanRL = null;
    ScanController      scan = null;
    int[]          baseColumnPositions;
    int            baseColumns = 0;
    DataValueFactory    dvf;
    long          indexRows;
    ConglomerateController  baseCC = null;
    ConglomerateController  indexCC = null;
    ExecutionContext    ec;
    SchemaDescriptor    sd;
    ConstraintDescriptor  constraintDesc;

    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    tc = lcc.getTransactionExecute();

    try {

            dd = lcc.getDataDictionary();

            dvf = lcc.getDataValueFactory();

            ec = lcc.getExecutionContext() ;

            sd = dd.getSchemaDescriptor(schemaName, tc, true);
            td = dd.getTableDescriptor(tableName, sd);

            if (td == null)
            {
                throw StandardException.newException(
                    SQLState.LANG_TABLE_NOT_FOUND,
                    schemaName + "." + tableName);
            }

            /* Skip views */
            if (td.getTableType() == TableDescriptor.VIEW_TYPE)
            {
                return true;
            }

      /* Open the heap for reading */
      baseCC = tc.openConglomerate(
                  td.getHeapConglomerateId(), false, 0,
                TransactionController.MODE_TABLE,
              TransactionController.ISOLATION_SERIALIZABLE);

      /* Check the consistency of the heap */
      baseCC.checkConsistency();

      heapCD = td.getConglomerateDescriptor(td.getHeapConglomerateId());

      /* Get a row template for the base table */
      baseRow = ec.getExecutionFactory().getValueRow(td.getNumberOfColumns());

      /* Fill the row with nulls of the correct type */
      ColumnDescriptorList cdl = td.getColumnDescriptorList();
      int           cdlSize = cdl.size();

      for (int index = 0; index < cdlSize; index++)
      {
        ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);
        baseRow.setColumn(cd.getPosition(),
                    cd.getType().getNull());
      }

      /* Look at all the indexes on the table */
      ConglomerateDescriptor[] cds = td.getConglomerateDescriptors();
      for (int index = 0; index < cds.length; index++)
      {
        indexCD = cds[index];
        /* Skip the heap */
        if ( ! indexCD.isIndex())
          continue;

        /* Check the internal consistency of the index */
        indexCC =
              tc.openConglomerate(
                indexCD.getConglomerateNumber(),
                        false,
              0,
            TransactionController.MODE_TABLE,
                      TransactionController.ISOLATION_SERIALIZABLE);

        indexCC.checkConsistency();
        indexCC.close();
        indexCC = null;

        /* if index is for a constraint check that the constraint exists */

        if (indexCD.isConstraint())
        {
          constraintDesc = dd.getConstraintDescriptor(td, indexCD.getUUID());
          if (constraintDesc == null)
          {
            throw StandardException.newException(
                    SQLState.LANG_OBJECT_NOT_FOUND,
                    "CONSTRAINT for INDEX",
                    indexCD.getConglomerateName());
          }
        }

        /*
        ** Set the base row count when we get to the first index.
        ** We do this here, rather than outside the index loop, so
        ** we won't do the work of counting the rows in the base table
        ** if there are no indexes to check.
        */
        if (baseRowCount < 0)
        {
          scan = tc.openScan(heapCD.getConglomerateNumber(),
                    false,  // hold
                    0,    // not forUpdate
                      TransactionController.MODE_TABLE,
                      TransactionController.ISOLATION_SERIALIZABLE,
                                        RowUtil.EMPTY_ROW_BITSET,
                    null,  // startKeyValue
                    0,    // not used with null start posn.
                    null,  // qualifier
                    null,  // stopKeyValue
                    0);    // not used with null stop posn.

          /* Also, get the row location template for index rows */
          rl = scan.newRowLocationTemplate();
          scanRL = scan.newRowLocationTemplate();

          for (baseRowCount = 0; scan.next(); baseRowCount++)
            /* Empty statement */

          scan.close();
          scan = null;
        }

        baseColumnPositions =
            indexCD.getIndexDescriptor().baseColumnPositions();
        baseColumns = baseColumnPositions.length;

        FormatableBitSet indexColsBitSet = new FormatableBitSet();
        for (int i = 0; i < baseColumns; i++)
        {
          indexColsBitSet.grow(baseColumnPositions[i]);
          indexColsBitSet.set(baseColumnPositions[i] - 1);
        }

        /* Get one row template for the index scan, and one for the fetch */
        indexRow = ec.getExecutionFactory().getValueRow(baseColumns + 1);

        /* Fill the row with nulls of the correct type */
        for (int column = 0; column < baseColumns; column++)
        {
          /* Column positions in the data dictionary are one-based */
           ColumnDescriptor cd = td.getColumnDescriptor(baseColumnPositions[column]);
          indexRow.setColumn(column + 1,
                      cd.getType().getNull());
        }

        /* Set the row location in the last column of the index row */
        indexRow.setColumn(baseColumns + 1, rl);

        /* Do a full scan of the index */
        scan = tc.openScan(indexCD.getConglomerateNumber(),
                  false,  // hold
                  0,    // not forUpdate
                    TransactionController.MODE_TABLE,
                        TransactionController.ISOLATION_SERIALIZABLE,
                  (FormatableBitSet) null,
                  null,  // startKeyValue
                  0,    // not used with null start posn.
                  null,  // qualifier
                  null,  // stopKeyValue
                  0);    // not used with null stop posn.

        DataValueDescriptor[] baseRowIndexOrder =
                    new DataValueDescriptor[baseColumns];
        DataValueDescriptor[] baseObjectArray = baseRow.getRowArray();

        for (int i = 0; i < baseColumns; i++)
        {
          baseRowIndexOrder[i] = baseObjectArray[baseColumnPositions[i] - 1];
        }
     
        /* Get the index rows and count them */
        for (indexRows = 0; scan.fetchNext(indexRow.getRowArray()); indexRows++)
        {
          /*
          ** Get the base row using the RowLocation in the index row,
          ** which is in the last column. 
          */
          RowLocation baseRL = (RowLocation) indexRow.getColumn(baseColumns + 1);

          boolean base_row_exists =
                    baseCC.fetch(
                      baseRL, baseObjectArray, indexColsBitSet);

          /* Throw exception if fetch() returns false */
          if (! base_row_exists)
          {
            String indexName = indexCD.getConglomerateName();
            throw StandardException.newException(SQLState.LANG_INCONSISTENT_ROW_LOCATION,
                  (schemaName + "." + tableName),
                  indexName,
                  baseRL.toString(),
                  indexRow.toString());
          }

          /* Compare all the column values */
          for (int column = 0; column < baseColumns; column++)
          {
            DataValueDescriptor indexColumn =
              indexRow.getColumn(column + 1);
            DataValueDescriptor baseColumn =
              baseRowIndexOrder[column];

            /*
            ** With this form of compare(), null is considered equal
            ** to null.
            */
            if (indexColumn.compare(baseColumn) != 0)
            {
              ColumnDescriptor cd =
                                td.getColumnDescriptor(
                                    baseColumnPositions[column]);

                            /*
                            System.out.println(
                                "SQLState.LANG_INDEX_COLUMN_NOT_EQUAL:" +
                                "indexCD.getConglomerateName()" + indexCD.getConglomerateName() +
                                ";td.getSchemaName() = " + td.getSchemaName() +
                                ";td.getName() = " + td.getName() +
                                ";baseRL.toString() = " + baseRL.toString() +
                                ";cd.getColumnName() = " + cd.getColumnName() +
                                ";indexColumn.toString() = " + indexColumn.toString() +
                                ";baseColumn.toString() = " + baseColumn.toString() +
                                ";indexRow.toString() = " + indexRow.toString());
                            */

              throw StandardException.newException(
                                SQLState.LANG_INDEX_COLUMN_NOT_EQUAL,
                                indexCD.getConglomerateName(),
                                td.getSchemaName(),
                                td.getName(),
                                baseRL.toString(),
                                cd.getColumnName(),
                                indexColumn.toString(),
                                baseColumn.toString(),
                                indexRow.toString());
            }
          }
        }

        /* Clean up after the index scan */
        scan.close();
        scan = null;

        /*
        ** The index is supposed to have the same number of rows as the
        ** base conglomerate.
        */
        if (indexRows != baseRowCount)
        {
          throw StandardException.newException(SQLState.LANG_INDEX_ROW_COUNT_MISMATCH,
                    indexCD.getConglomerateName(),
                    td.getSchemaName(),
                    td.getName(),
                    Long.toString(indexRows),
                    Long.toString(baseRowCount));
        }
      }
      /* check that all constraints have backing index */
      ConstraintDescriptorList constraintDescList =
        dd.getConstraintDescriptors(td);
      for (int index = 0; index < constraintDescList.size(); index++)
      {
        constraintDesc = constraintDescList.elementAt(index);
        if (constraintDesc.hasBackingIndex())
        {
          ConglomerateDescriptor conglomDesc;

          conglomDesc = td.getConglomerateDescriptor(
              constraintDesc.getConglomerateId());
          if (conglomDesc == null)
          {
            throw StandardException.newException(
                    SQLState.LANG_OBJECT_NOT_FOUND,
                    "INDEX for CONSTRAINT",
                    constraintDesc.getConstraintName());
          }
        }
      }
     
    }
    catch (StandardException se)
    {
      throw PublicAPI.wrapStandardException(se);
    }
    finally
    {
            try
            {
                /* Clean up before we leave */
                if (baseCC != null)
                {
                    baseCC.close();
                    baseCC = null;
                }
                if (indexCC != null)
                {
                    indexCC.close();
                    indexCC = null;
                }
                if (scan != null)
                {
                    scan.close();
                    scan = null;
                }
            }
            catch (StandardException se)
            {
View Full Code Here

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

        /**********************************************************************
         * Forward scan test case
         **********************************************************************
         */

        ScanController scan =
            tc.openScan(
                conglomid, false,
                0,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE,
                (FormatableBitSet) null,
                start_key, start_op,
                qualifier,
                stop_key, stop_op);

        long key     = -42;
        int numrows = 0;

        while (scan.next())
        {
            scan.fetch(fetch_template);

            key = ((SQLLongint)(fetch_template[2])).getLong();

            if (ordered)
            {
                if (key != expect_key)
                {
                    return(
                        fail("(t_scanNext) wrong key, expected (" +
                              expect_key + ")" + "but got (" + key + ")."));
                }
                else
                {
          if (order == ORDER_DESC)
            expect_key--;
          else
            expect_key++;
                }
            }
            else
            {
                if (!set.remove(new Long(key)))
                {
                    return(
                        fail("(t_scanNext) wrong key, expected (" +
                              expect_key + ")" + "but got (" + key + ")."));
                }
            }
            numrows++;

        }

        scan.close();

        if (numrows != expect_numrows)
        {
            return(fail("(t_scanNext) wrong number of rows. Expected " +
                 expect_numrows + " rows, but got " + numrows + "rows."));
View Full Code Here

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

         * Forward scan test case
         **********************************************************************
         */


        ScanController scan =
            tc.openScan(
                conglomid, false,
                0,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE,
                (FormatableBitSet) null,
                start_key, start_op,
                qualifier,
                stop_key, stop_op);

        int  expect_key = input_expect_key;
        long key        = -42;
        long numrows    = 0;

        while (scan.fetchNext(fetch_template))
        {
            scan.fetch(init_scan_template);

            // make sure all columns from fetchNext() match subsequent fetch().
            for (int i = 0; i < init_scan_template.length; i++)
            {
                if ((fetch_template[i]).compare(
                        (init_scan_template[i])) != 0)
                {
                    return(
                        fail("(t_scanFetchNext) wrong key, expected (" +
                              fetch_template[i] + ")" + "but got (" +
                              init_scan_template[i] + ")."));
                }
            }

            // see if we are getting the right keys.
            key = ((SQLLongint)(init_scan_template[2])).getLong();

            if (ordered)
            {
                if (key != expect_key)
                {
                    return(
                        fail("(t_scanFetchNext) wrong key, expected (" +
                             expect_key + ")" + "but got (" + key + ")."));
                }
                else
                {
          if (order == ORDER_DESC)
            expect_key--;
          else
            expect_key++;
                }
            }
            else
            {
                if (!set.remove(new Long(key)))
                {
                    return(
                        fail("(t_scanFetchNext) wrong key, expected (" +
                              expect_key + ")" + "but got (" + key + ")."));
                }
            }
            numrows++;

        }

        scan.close();

        if (numrows != expect_numrows)
        {
            return(fail("(t_scanFetchNext) wrong number of rows. Expected " +
                 expect_numrows + " rows, but got " + numrows + "rows."));
View Full Code Here

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

        if (!ordered)
        {
            set = create_hash_set(input_expect_key, expect_numrows, order);
        }

        ScanController scan =
            tc.openScan(
                conglomid, false,
                0,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE,
                (FormatableBitSet) fetch_row_validColumns,
                start_key, start_op,
                qualifier,
                stop_key, stop_op);

        int  expect_key = input_expect_key;
        long key        = -42;
        long key2       = -42;
        long numrows    = 0;

        while (scan.fetchNext(fetch_template))
        {
            // see if we are getting the right keys.
            key = key_column.getLong();

            // make sure a subsequent fetch also works.
            key_column.setValue(-42);

            scan.fetch(fetch_template);
            key2 = key_column.getLong();

            if (ordered)
            {
                if ((key != expect_key) || (key2 != expect_key))
                {
                    return(
                        fail("(t_scanFetchNext) wrong key, expected (" +
                             expect_key + ")" + "but got (" + key + ")."));
                }
                else
                {
          if (order == ORDER_DESC)
            expect_key--;
          else
            expect_key++;
                }
            }
            else
            {
                if (!set.remove(new Long(key)))
                {
                    return(
                        fail("(t_scanFetchNext) wrong key, expected (" +
                             expect_key + ")" + "but got (" + key + ")."));
                }
            }
            numrows++;

        }

        scan.close();

        if (numrows != expect_numrows)
        {
            return(fail("(t_scanFetchNext) wrong number of rows. Expected " +
                 expect_numrows + " rows, but got " + numrows + "rows."));
View Full Code Here

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

        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."));
View Full Code Here

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

        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 " +
View Full Code Here

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

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

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

   * @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,
                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();

            // 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_002: there are still rows in table.");
            }
        }
View Full Code Here

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

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

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.