Package org.apache.derby.iapi.sql.dictionary

Examples of org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor


        row.nColumns() == SYSCONSTRAINTS_COLUMN_COUNT,
        "Wrong number of columns for a SYSCONSTRAINTS row");
    }

    DataValueDescriptor  col;
    ConglomerateDescriptor conglomDesc;
    DataDescriptorGenerator ddg;
    TableDescriptor    td = null;
    int          constraintIType = -1;
    int[]        keyColumns = null;
    UUID        constraintUUID;
    UUID        schemaUUID;
    UUID        tableUUID;
    UUID        referencedConstraintId = null;
    SchemaDescriptor  schema;
    String        tableUUIDString;
    String        constraintName;
    String        constraintSType;
    String        constraintStateStr;
    boolean        constraintEnabled;
    int          referenceCount;
    String        constraintUUIDString;
    String        schemaUUIDString;
    SubConstraintDescriptor scd;

    if (SanityManager.DEBUG)
    {
      if (!(parentTupleDescriptor instanceof SubConstraintDescriptor))
      {
        SanityManager.THROWASSERT(
          "parentTupleDescriptor expected to be instanceof " +
          "SubConstraintDescriptor, not " +
          parentTupleDescriptor.getClass().getName());
      }
    }

    scd = (SubConstraintDescriptor) parentTupleDescriptor;

    ddg = dd.getDataDescriptorGenerator();

    /* 1st column is CONSTRAINTID (UUID - char(36)) */
    col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTID);
    constraintUUIDString = col.getString();
    constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);

    /* 2nd column is TABLEID (UUID - char(36)) */
    col = row.getColumn(SYSCONSTRAINTS_TABLEID);
    tableUUIDString = col.getString();
    tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);

    /* Get the TableDescriptor. 
     * It may be cached in the SCD,
     * otherwise we need to go to the
     * DD.
     */
    if (scd != null)
    {
      td = scd.getTableDescriptor();
    }
    if (td == null)
    {
      td = dd.getTableDescriptor(tableUUID);
    }

    /* 3rd column is NAME (varchar(128)) */
    col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTNAME);
    constraintName = col.getString();

    /* 4th column is TYPE (char(1)) */
    col = row.getColumn(SYSCONSTRAINTS_TYPE);
    constraintSType = col.getString();
    if (SanityManager.DEBUG)
    {
      SanityManager.ASSERT(constraintSType.length() == 1,
        "Fourth column type incorrect");
    }

    boolean typeSet = false;
    switch (constraintSType.charAt(0))
    {
      case 'P' :
        constraintIType = DataDictionary.PRIMARYKEY_CONSTRAINT;
        typeSet = true;
        // fall through

      case 'U' :
        if (! typeSet)
        {
          constraintIType = DataDictionary.UNIQUE_CONSTRAINT;
          typeSet = true;
        }
        // fall through

      case 'F' :
        if (! typeSet)
          constraintIType = DataDictionary.FOREIGNKEY_CONSTRAINT;
        if (SanityManager.DEBUG)
        {
          if (!(parentTupleDescriptor instanceof SubKeyConstraintDescriptor))
          {
            SanityManager.THROWASSERT(
            "parentTupleDescriptor expected to be instanceof " +
            "SubKeyConstraintDescriptor, not " +
            parentTupleDescriptor.getClass().getName());
          }
        }
        conglomDesc = td.getConglomerateDescriptor(
                    ((SubKeyConstraintDescriptor)
                      parentTupleDescriptor).getIndexId());
        /* Take care the rare case of conglomDesc being null.  The
         * reason is that our "td" is out of date.  Another thread
         * which was adding a constraint committed between the moment
         * we got the table descriptor (conglomerate list) and the
         * moment we scanned and got the constraint desc list.  Since
         * that thread just added a new row to SYSCONGLOMERATES,
         * SYSCONSTRAINTS, etc.  We wouldn't have wanted to lock the
         * system tables just to prevent other threads from adding new
         * rows.
         */
        if (conglomDesc == null)
        {
          // we can't be getting td from cache because if we are
          // here, we must have been in dd's ddl mode (that's why
          // the ddl thread went through), we are not done yet, the
          // dd ref count is not 0, hence it couldn't have turned
          // into COMPILE_ONLY mode
          td = dd.getTableDescriptor(tableUUID);
          if (scd != null)
            scd.setTableDescriptor(td);
          // try again now
          conglomDesc = td.getConglomerateDescriptor(
                  ((SubKeyConstraintDescriptor)
                    parentTupleDescriptor).getIndexId());
        }

        if (SanityManager.DEBUG)
        {
          SanityManager.ASSERT(conglomDesc != null,
          "conglomDesc is expected to be non-null for backing index");
        }
        keyColumns = conglomDesc.getIndexDescriptor().baseColumnPositions();
        referencedConstraintId = ((SubKeyConstraintDescriptor)
                      parentTupleDescriptor).getKeyConstraintId();
        keyColumns = conglomDesc.getIndexDescriptor().baseColumnPositions();
        break;

      case 'C' :
        constraintIType = DataDictionary.CHECK_CONSTRAINT;
        if (SanityManager.DEBUG)
View Full Code Here


        /* Now we have a lot of painful work to get the
         * table name for the error message.  All we have
         * is the conglomerate number to work with.
         */
        DataDictionary dd = activation.getLanguageConnectionContext().getDataDictionary();
        ConglomerateDescriptor cd = dd.getConglomerateDescriptor( heapConglom );
        TableDescriptor td = dd.getTableDescriptor(cd.getTableID());

        StandardException se = StandardException.newException(SQLState.LANG_CHECK_CONSTRAINT_VIOLATED,
          td.getQualifiedName(), checkName);

        throw se;
View Full Code Here

          ConglomerateDescriptor[] conglom_descriptors =
                td.getConglomerateDescriptors();

            for (int cd_idx = 0; cd_idx < conglom_descriptors.length; cd_idx++)
            {
                ConglomerateDescriptor cd = conglom_descriptors[cd_idx];

                tc.compressConglomerate(cd.getConglomerateNumber());
            }
          }
        }

        return;
View Full Code Here

            default:
              break;
            }


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

      /* Get a row template for the base table */
      ExecRow baseRow =
                lcc.getLanguageConnectionFactory().getExecutionFactory().getValueRow(
View Full Code Here


        int index_idx = 0;
        for (int cd_idx = 0; cd_idx < conglom_descriptors.length; cd_idx++)
        {
            ConglomerateDescriptor index_cd = conglom_descriptors[cd_idx];

            if (!index_cd.isIndex())
            {
                // skip the heap descriptor entry
                continue;
            }

            // ScanControllers are used to delete old index row
            index_scan[index_idx] =
                tc.openScan(
                    index_cd.getConglomerateNumber(),
                    true,  // hold
                    TransactionController.OPENMODE_FORUPDATE,
                    TransactionController.MODE_TABLE,
                    TransactionController.ISOLATION_SERIALIZABLE,
                    null,   // full row is retrieved,
                            // so that full row can be used for start/stop keys
                    null,  // startKeyValue - will be reset with reopenScan()
                    0,    //
                    null,  // qualifier
                    null,  // stopKeyValue  - will be reset with reopenScan()
                    0);    //

            // ConglomerateControllers are used to insert new index row
            index_cc[index_idx] =
                tc.openConglomerate(
                    index_cd.getConglomerateNumber(),
                    true,  // hold
                    TransactionController.OPENMODE_FORUPDATE,
                    TransactionController.MODE_TABLE,
                    TransactionController.ISOLATION_SERIALIZABLE);

            // build column map to allow index row to be built from base row
            int[] baseColumnPositions   =
                index_cd.getIndexDescriptor().baseColumnPositions();
            int[] zero_based_map        =
                new int[baseColumnPositions.length];

            for (int i = 0; i < baseColumnPositions.length; i++)
            {
View Full Code Here

            ConglomerateDescriptor[] conglom_descriptors =
                td.getConglomerateDescriptors();

            for (int cd_idx = 0; cd_idx < conglom_descriptors.length; cd_idx++)
            {
                ConglomerateDescriptor cd = conglom_descriptors[cd_idx];

                tc.purgeConglomerate(cd.getConglomerateNumber());
            }
          }
        }

        return;
View Full Code Here

                {
                    if (columns.elementAt(count).getPosition() != columnPostion)
                        break;

                    //get backing index
                    ConglomerateDescriptor desc =
                        td.getConglomerateDescriptor(cd.getConglomerateId());

                    //check if the backing index was created when the column
                    //not null ie is backed by unique index
                    if (!desc.getIndexDescriptor().isUnique())
                        break;

                    // replace backing index with a unique when not null index.
                    recreateUniqueConstraintBackingIndexAsUniqueWhenNotNull(
                        desc, td, activation, lcc);
View Full Code Here

     * RESOLVE - this will change in 1.4 because we will get
     * back the same conglomerate number
     */
    // Get the ConglomerateDescriptor for the heap
    long oldHeapConglom       = td.getHeapConglomerateId();
    ConglomerateDescriptor cd =
            td.getConglomerateDescriptor(oldHeapConglom);

    // Update sys.sysconglomerates with new conglomerate #
    dd.updateConglomerateDescriptor(cd, newHeapConglom, tc);

View Full Code Here

    }

    // Update the DataDictionary
    // Get the ConglomerateDescriptor for the heap
    long oldHeapConglom = td.getHeapConglomerateId();
    ConglomerateDescriptor cd = td.getConglomerateDescriptor(oldHeapConglom);

    // Update sys.sysconglomerates with new conglomerate #
    dd.updateConglomerateDescriptor(cd, newHeapConglom, tc);
    // Drop the old conglomerate
    tc.dropConglomerate(oldHeapConglom);
View Full Code Here

    throws StandardException
  {
    Properties properties = new Properties();

    // Get the ConglomerateDescriptor for the index
    ConglomerateDescriptor cd =
            td.getConglomerateDescriptor(indexConglomerateNumbers[index]);

    // Build the properties list for the new conglomerate
    ConglomerateController 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));
    }
    if(cd.getIndexDescriptor().isUniqueWithDuplicateNulls())
    {
      properties.put(
                    "uniqueWithDuplicateNulls", Boolean.toString(true));
    }

    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
    // Populate the index.
   
    RowLocationRetRowSource cCount           = null;
    boolean                 statisticsExist  = false;

    if (!truncateTable)
    {
      sorters[index].completedInserts();
      sorters[index] = null;

      if (td.statisticsExist(cd))
      {
        cCount =
                    new CardinalityCounter(
                            tc.openSortRowSource(sortIds[index]));

        statisticsExist = true;
      }
      else
            {
        cCount =
                    new CardinalityCounter(
                            tc.openSortRowSource(sortIds[index]));
            }

            newIndexCongloms[index] =
                tc.createAndLoadConglomerate(
                    "BTREE",
                    indexRows[index].getRowArray(),
                    ordering[index],
                    collation[index],
                    properties,
                    TransactionController.IS_DEFAULT,
                    cCount,
                    (long[]) null);

      //For an index, if the statistics already exist, then drop them.
      //The statistics might not exist for an index if the index was
      //created when the table was empty.
            //
            //For all alter table actions, including ALTER TABLE COMPRESS,
      //for both kinds of indexes (ie. one with preexisting statistics
            //and with no statistics), create statistics for them if the table
            //is not empty.
      if (statisticsExist)
        dd.dropStatisticsDescriptors(td.getUUID(), cd.getUUID(), tc);
     
      long numRows;
      if ((numRows = ((CardinalityCounter)cCount).getRowCount()) > 0)
      {
        long[] c = ((CardinalityCounter)cCount).getCardinality();
        for (int i = 0; i < c.length; i++)
        {
          StatisticsDescriptor statDesc =
            new StatisticsDescriptor(
                            dd,
                            dd.getUUIDFactory().createUUID(),
                            cd.getUUID(),
                            td.getUUID(),
                            "I",
                            new StatisticsImpl(numRows, c[i]),
                            i + 1);

          dd.addDescriptor(
                            statDesc,
                            null,   // no parent descriptor
              DataDictionary.SYSSTATISTICS_CATALOG_NUM,
              true,   // no error on duplicate.
                            tc)
        }
      }
    }
        else
    {
            newIndexCongloms[index] =
                tc.createConglomerate(
                    "BTREE",
                    indexRows[index].getRowArray(),
                    ordering[index],
                    collation[index],
                    properties,
                    TransactionController.IS_DEFAULT);


      //on truncate drop the statistics because we know for sure
      //rowscount is zero and existing statistic will be invalid.
      if (td.statisticsExist(cd))
        dd.dropStatisticsDescriptors(td.getUUID(), cd.getUUID(), tc);
    }

    /* Update the DataDictionary
     *
     * Update sys.sysconglomerates with new conglomerate #, we need to
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor

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.