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

    // create the index with all the columns in descending order
        ColumnOrdering order[] = new ColumnOrdering[5];
    order[0] new T_ColumnOrderingImpl(0, false); // Descending
    order[1] new T_ColumnOrderingImpl(1, true); // Ascending
    order[2] new T_ColumnOrderingImpl(2, true); // Ascending
    order[3] new T_ColumnOrderingImpl(3, false); // descending
    order[4] new T_ColumnOrderingImpl(4, true); // asccending

    long index_conglomid =
            tc.createConglomerate(
                "BTREE",            // create a btree secondary
                index_row.getRow(),         // row template
        order, //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_ascdesc1_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_ascdesc1_scan_test_cases(tc, index_conglomid, template);


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

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

        return(ret_val);
View Full Code Here


  private void updateIndex(long newHeapConglom, DataDictionary dd,
               int index, long[] newIndexCongloms)
    throws StandardException
  {
    ConglomerateController indexCC;
    Properties properties = new Properties();
    ConglomerateDescriptor cd;
    // Get the ConglomerateDescriptor for the index
    cd = td.getConglomerateDescriptor(indexConglomerateNumbers[index]);

    // Build the properties list for the new conglomerate
    indexCC = tc.openConglomerate(
              indexConglomerateNumbers[index],
                            false,
                            TransactionController.OPENMODE_FORUPDATE,
                            TransactionController.MODE_TABLE,
                            TransactionController.ISOLATION_SERIALIZABLE);

    // Get the properties on the old index
    indexCC.getInternalTablePropertySet(properties);

    /* Create the properties that language supplies when creating the
     * the index.  (The store doesn't preserve these.)
     */
    int indexRowLength = indexRows[index].nColumns();
    properties.put("baseConglomerateId", Long.toString(newHeapConglom));
    if (cd.getIndexDescriptor().isUnique())
    {
      properties.put("nUniqueColumns",
               Integer.toString(indexRowLength - 1));
    }
    else
    {
      properties.put("nUniqueColumns",
               Integer.toString(indexRowLength));
    }
    properties.put("rowLocationColumn",
            Integer.toString(indexRowLength - 1));
    properties.put("nKeyFields", Integer.toString(indexRowLength));

    indexCC.close();

    // We can finally drain the sorter and rebuild the index
    // RESOLVE - all indexes are btrees right now
    // Populate the index.
   
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);

    // objects used to insert rows into base and index tables.
    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);

        // insert one row into the table/index

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

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

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

    ExecRow firstRow = t_cc.getHeapRowOfNulls();
    heapScan.fetch(firstRow.getRowArray());
    heapScan.close();

    // Insert another copy of the 1st row into the heap
    ConglomerateController heapCC = t_cc.openHeapCC();
    heapCC.insert(firstRow.getRowArray());
    heapCC.close();
  }
View Full Code Here

    // Insert another copy of the 1st row into the index with a bad row location
    int keyLength =
        t_cc.getIndexDescriptor().getIndexDescriptor().baseColumnPositions().length;
    indexRow.setColumn(keyLength + 1, badRL);

    ConglomerateController indexCC = t_cc.openIndexCC();
    indexCC.insert(indexRow.getRowArray());
    indexCC.close();
  }
View Full Code Here

  /* Get a heap row full of nulls */
  private ExecRow getHeapRowOfNulls()
    throws StandardException
  {
    ConglomerateController  baseCC;
    ExecRow          baseRow;

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

    /* 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);
      DataTypeDescriptor dts = cd.getType();
      baseRow.setColumn(cd.getPosition(),
                  dts.getNull());
    }

    baseCC.close();
    return baseRow;
  }
View Full Code Here

  /* Open the heap conglomerate for update */
  private ConglomerateController openHeapCC()
    throws StandardException
  {
    ConglomerateController heapCC;

    heapCC = tc.openConglomerate(
                  td.getHeapConglomerateId(),
                        false,
            TransactionController.OPENMODE_FORUPDATE,    //  forUpdate
View Full Code Here

  /* Open the index conglomerate for update */
  private ConglomerateController openIndexCC()
    throws StandardException
  {
    ConglomerateController indexCC;

    indexCC = tc.openConglomerate(
                  id.getConglomerateNumber(),
                        false,
            TransactionController.OPENMODE_FORUPDATE,    //  forUpdate
View Full Code Here

  }

  private static Properties  getConglomerateProperties( String schemaName, String conglomerateName, boolean isIndex )
        throws java.sql.SQLException
  {
    ConglomerateController    cc;
    ConglomerateDescriptor    cd;
    DataDictionary            dd;
    Properties          properties;
    SchemaDescriptor      sd;
    TableDescriptor           td;
    TransactionController     tc;
    long            conglomerateNumber;

        // find the language context.
        LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();

        // Get the current transaction controller
        tc = lcc.getTransactionExecute();

    try {

    // find the DataDictionary
    dd = lcc.getDataDictionary();


    // get the SchemaDescriptor
    sd = dd.getSchemaDescriptor(schemaName, tc, true);
    if ( !isIndex)
    {
      // get the TableDescriptor for the table
      td = dd.getTableDescriptor(conglomerateName, sd);

      // Return an empty Properties if table does not exist or if it is for a view.
      if ((td == null) || td.getTableType() == TableDescriptor.VIEW_TYPE) { return new Properties(); }

      conglomerateNumber = td.getHeapConglomerateId();
    }
    else
    {
      // get the ConglomerateDescriptor for the index
      cd = dd.getConglomerateDescriptor(conglomerateName, sd, false);

      // Return an empty Properties if index does not exist
      if (cd == null) { return new Properties(); }

      conglomerateNumber = cd.getConglomerateNumber();
    }

    cc = tc.openConglomerate(
                conglomerateNumber,
                false,
                0,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    properties = cc.getInternalTablePropertySet( new Properties() );

    cc.close();

    } catch (StandardException se) {
      throw PublicAPI.wrapStandardException(se);
    }
View Full Code Here

   */
  private int insertRowListImpl(ExecRow[] rowList, TransactionController tc, RowLocation[] rowLocationOut,
                   boolean wait)
    throws StandardException
  {
    ConglomerateController    heapController;
    RowLocation          heapLocation;
    ExecIndexRow        indexableRow;
    int              insertRetCode;
    int              retCode = ROWNOTDUPLICATE;
    int              indexCount = crf.getNumIndexes();
    ConglomerateController[]  indexControllers = new ConglomerateController[ indexCount ];

    // Open the conglomerates
    heapController =
            tc.openConglomerate(
                getHeapConglomerate(),
                false,
        (TransactionController.OPENMODE_FORUPDATE |
                    ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)),
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_REPEATABLE_READ);
   
    /* NOTE: Due to the lovely problem of trying to add
     * a new column to syscolumns and an index on that
     * column during upgrade, we have to deal with the
     * issue of the index not existing yet.  So, it's okay
     * if the index doesn't exist yet.  (It will magically
     * get created at a later point during upgrade.)
     */

    for ( int ictr = 0; ictr < indexCount; ictr++ )
    {
      long conglomNumber = getIndexConglomerate(ictr);
      if (conglomNumber > -1)
      {
        indexControllers[ ictr ] =
                tc.openConglomerate(
                  conglomNumber,
                        false,
            (TransactionController.OPENMODE_FORUPDATE |
                        ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)),
              TransactionController.MODE_RECORD,
            TransactionController.ISOLATION_REPEATABLE_READ);
      }
    }

    heapLocation = heapController.newRowLocationTemplate();
    rowLocationOut[0]=heapLocation;

    // loop through rows on this list, inserting them into system table
    for (int rowNumber = 0; rowNumber < rowList.length; rowNumber++)
    {
      ExecRow row = rowList[rowNumber];
      // insert the base row and get its new location
      heapController.insertAndFetchLocation(row.getRowArray(), heapLocation);
     
      for ( int ictr = 0; ictr < indexCount; ictr++ )
        {
        if (indexControllers[ ictr ] == null)
        {
          continue;
        }

        // Get an index row based on the base row
        indexableRow = getIndexRowFromHeapRow( getIndexRowGenerator(ictr),
                             heapLocation,
                             row );

        insertRetCode =
                    indexControllers[ ictr ].insert(indexableRow.getRowArray());

        if ( insertRetCode == ConglomerateController.ROWISDUPLICATE )
        {
          retCode = rowNumber;
        }
      }

    }  // end loop through rows on list

    // Close the open conglomerates
    for ( int ictr = 0; ictr < indexCount; ictr++ )
    {
      if (indexControllers[ ictr ] == null)
      {
        continue;
      }

      indexControllers[ ictr ].close();
    }
    heapController.close();

    return  retCode;
  }
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.