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

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


   * @exception StandardException    Thrown on error
   */
  void verifyTargetTable()
    throws StandardException
  {
                DataDictionary dataDictionary = getDataDictionary();
    if (targetTableName != null)
    {
      /*
      ** Get the TableDescriptor for the table we are inserting into
      */
 
View Full Code Here


   * @exception StandardException    Thrown on error
   */

  public void bindStatement() throws StandardException
  {
    DataDictionary        dataDictionary;

    dataDictionary = getDataDictionary();

    // This is how we handle queries like: SELECT A FROM T ORDER BY B.
    // We pull up the order by columns (if they don't appear in the SELECT
View Full Code Here

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

    try
        {
            DataDictionary data_dictionary = lcc.getDataDictionary();

            // Each of the following may give up locks allowing ddl on the
            // table, so each phase needs to do the data dictionary lookup.
            // The order is important as it makes sense to first purge
            // deleted rows, then defragment existing non-deleted rows, and
View Full Code Here

        TransactionController tc = lcc.getTransactionExecute();

    try {

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


    // get the SchemaDescriptor
    SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true);
    if ( !isIndex)
    {
      // get the TableDescriptor for the table
      TableDescriptor 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
      ConglomerateDescriptor cd = dd.getConglomerateDescriptor(conglomerateName, sd, false);

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

      conglomerateNumber = cd.getConglomerateNumber();
View Full Code Here

    }

    private void getConglomInfo(LanguageConnectionContext lcc)
        throws StandardException
    {
        DataDictionary dd = lcc.getDataDictionary();
   
    if (schemaName == null)
      schemaName = lcc.getCurrentSchemaName();

        // if schemaName is null, it gets the default schema
        SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, lcc.getTransactionExecute(), true);
        TableDescriptor td = dd.getTableDescriptor(tableName,sd);
        if (td == null// table does not exist
        {
            conglomTable = new ConglomInfo[0];   // make empty conglom table
            return;
        }
View Full Code Here

   *                  exception is thrown..
   */
  public static boolean checkTable(String schemaName, String tableName)
            throws SQLException
  {
    DataDictionary      dd;
    TableDescriptor      td;
    long          baseRowCount = -1;
    TransactionController  tc;
    ConglomerateDescriptor  heapCD;
    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())
        {
View Full Code Here

            throws StandardException
  {
    SchemaDescriptor  sd;

    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();

    /*
    ** Inform the data dictionary that we are about to write to it.
    ** There are several calls to data dictionary "get" methods here
    ** that might be done in "read" mode in the data dictionary, but
    ** it seemed safer to do this whole operation in "write" mode.
    **
    ** We tell the data dictionary we're done writing at the end of
    ** the transaction.
    */
    dd.startWriting(lcc);

    sd = dd.getSchemaDescriptor(schemaName, null, true);

    //If user is attempting to drop SESSION schema and there is no physical SESSION schema, then throw an exception
    //Need to handle it this special way is because SESSION schema is also used for temporary tables. If there is no
    //physical SESSION schema, we internally generate an in-memory SESSION schema in order to support temporary tables
    //But there is no way for the user to access that in-memory SESSION schema. Following if will be true if there is
    //no physical SESSION schema and hence getSchemaDescriptor has returned an in-memory SESSION schema
    if (schemaName.equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME) && (sd != null) && (sd.getUUID() == null))
      throw StandardException.newException(SQLState.LANG_SCHEMA_DOES_NOT_EXIST, schemaName);

    /*
    ** Make sure the schema is empty.
    ** In the future we want to drop everything
    ** in the schema if it is CASCADE.
    */
    if (!dd.isSchemaEmpty(sd))
    {
      throw StandardException.newException(SQLState.LANG_SCHEMA_NOT_EMPTY, schemaName);
    }

    /* Prepare all dependents to invalidate.  (This is there chance
     * to say that they can't be invalidated.  For example, an open
     * cursor referencing a table/view that the user is attempting to
     * drop.) If no one objects, then invalidate any dependent objects.
     * We check for invalidation before we drop the table descriptor
     * since the table descriptor may be looked up as part of
     * decoding tuples in SYSDEPENDS.
     */
    dm.invalidateFor(sd, DependencyManager.DROP_SCHEMA, lcc);

    dd.dropSchemaDescriptor(schemaName, tc);

    /*
    ** If we have dropped the current default schema,
    ** then we will set the default to null.  The
    ** LCC is free to set the new default schema to
View Full Code Here

   */
  public void  executeConstantAction( Activation activation )
            throws StandardException
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();

    /*
    ** Inform the data dictionary that we are about to write to it.
    ** There are several calls to data dictionary "get" methods here
    ** that might be done in "read" mode in the data dictionary, but
    ** it seemed safer to do this whole operation in "write" mode.
    **
    ** We tell the data dictionary we're done writing at the end of
    ** the transaction.
    */
    dd.startWriting(lcc);

    // now do the real work

    // get an exclusive lock of the heap, to avoid deadlock on rows of
    // SYSCOLUMNS etc datadictionary tables (track 879) and phantom table
    // descriptor, in which case table shape could be changed by a
    // concurrent thread doing add/drop column (track 3804 and 3825)

    // older version (or at target) has to get td first, potential deadlock
    if (tableConglomerateId == 0)
    {
      td = dd.getTableDescriptor(tableId);
      if (td == null)
      {
        throw StandardException.newException(
          SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
      }
      tableConglomerateId = td.getHeapConglomerateId();
    }

    lockTableForDDL(tc, tableConglomerateId, true);

    td = dd.getTableDescriptor(tableId);
    if (td == null)
    {
      throw StandardException.newException(
        SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
    }
View Full Code Here

    int              numRows = 0;
    boolean            tableNeedsScanning = false;
    boolean            tableScanned = false;

    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();

    // Save the TableDescriptor off in the Activation
    activation.setDDLTableDescriptor(td);

    /*
    ** If the schema descriptor is null, then
    ** we must have just read ourselves in. 
    ** So we will get the corresponding schema
    ** descriptor from the data dictionary.
    */
    if (sd == null)
    {
      sd = getAndCheckSchemaDescriptor(dd, schemaId, "ALTER TABLE");
    }
   

    /* Prepare all dependents to invalidate.  (This is there chance
     * to say that they can't be invalidated.  For example, an open
     * cursor referencing a table/view that the user is attempting to
     * alter.) If no one objects, then invalidate any dependent objects.
     */
    if(truncateTable)
      dm.invalidateFor(td, DependencyManager.TRUNCATE_TABLE, lcc);
    else
      dm.invalidateFor(td, DependencyManager.ALTER_TABLE, lcc);

    // Are we working on columns?
    if (columnInfo != null)
    {
      /* NOTE: We only allow a single column to be added within
       * each ALTER TABLE command at the language level.  However,
       * this may change some day, so we will try to plan for it.
       */
      /* for each new column, see if the user is adding a non-nullable
       * column.  This is only allowed on an empty table.
       */
      for (int ix = 0; ix < columnInfo.length; ix++)
      {

        /* Is this new column non-nullable? 
         * If so, it can only be added to an
         * empty table if it does not have a default value. 
         * We need to scan the table to find out how many rows
         * there are.
         */
        if ((columnInfo[ix].action == ColumnInfo.CREATE) &&
          !(columnInfo[ix].dataType.isNullable()) &&
          (columnInfo[ix].defaultInfo == null) &&
          (columnInfo[ix].autoincInc == 0)
          )
        {
          tableNeedsScanning = true;
        }
      }

      // Scan the table if necessary
      if (tableNeedsScanning)
      {
        numRows = getSemiRowCount(tc);
        // Don't allow user to add non-nullable column to non-empty table
        if (numRows > 0)
        {
          throw StandardException.newException(SQLState.LANG_ADDING_NON_NULL_COLUMN_TO_NON_EMPTY_TABLE,
                  td.getQualifiedName());
        }
        tableScanned = true;
      }

      // for each related column, stuff system.column
      for (int ix = 0; ix < columnInfo.length; ix++)
      {
        ColumnDescriptorList cdl = new ColumnDescriptorList();

        /* If there is a default value, use it, otherwise use null */
       
        // Are we adding a new column or modifying a default?
       
        if (columnInfo[ix].action == ColumnInfo.CREATE)
        {
          addNewColumnToTable(activation, ix);
        }
        else if (columnInfo[ix].action ==
             ColumnInfo.MODIFY_COLUMN_DEFAULT_RESTART ||
             columnInfo[ix].action == ColumnInfo.MODIFY_COLUMN_DEFAULT_INCREMENT)
        {
          modifyColumnDefault(activation, ix);
        }
        else if (columnInfo[ix].action ==
             ColumnInfo.MODIFY_COLUMN_TYPE)
        {
          modifyColumnType(activation, ix);
        }
        else if (columnInfo[ix].action ==
             ColumnInfo.MODIFY_COLUMN_CONSTRAINT)
        {
          modifyColumnConstraint(activation, columnInfo[ix].name, true);
        }
        else if (columnInfo[ix].action ==
             ColumnInfo.MODIFY_COLUMN_CONSTRAINT_NOT_NULL)
        {
          if (! tableScanned)
          {
            tableScanned = true;
            numRows = getSemiRowCount(tc);
          }
          // check that the data in the column is not null
          String colNames[] = new String[1];
          colNames[0] = columnInfo[ix].name;
          boolean nullCols[] = new boolean[1];

          /* note validateNotNullConstraint returns true if the
           * column is nullable
           */
          if (validateNotNullConstraint(colNames, nullCols,
              numRows, lcc, SQLState.LANG_NULL_DATA_IN_NON_NULL_COLUMN))
          {
            /* nullable column - modify it to be not null
             * This is O.K. at this point since we would have
             * thrown an exception if any data was null
             */
            modifyColumnConstraint(activation, columnInfo[ix].name, false);
          }
        }
        else if (columnInfo[ix].action == ColumnInfo.DROP)
        {
          dropColumnFromTable(activation, ix);
        }
        else if (SanityManager.DEBUG)
        {
          SanityManager.THROWASSERT(
                "Unexpected action in AlterTableConstantAction");
        }
      }
    }

    /* Create/Drop any constraints */
    if (constraintActions != null)
    {
      for (int conIndex = 0; conIndex < constraintActions.length; conIndex++)
      {
        ConstraintConstantAction cca = constraintActions[conIndex];

        if (cca instanceof CreateConstraintConstantAction)
        {
          int constraintType = cca.getConstraintType();

          /* Some constraint types require special checking:
           *    Check    - table must be empty, for now
           *    Primary Key - table cannot already have a primary key
           */
          switch (constraintType)
          {
            case DataDictionary.PRIMARYKEY_CONSTRAINT:
              // Check to see if a constraint of the same type already exists
              ConstraintDescriptorList cdl = dd.getConstraintDescriptors(td);
              if (cdl.getPrimaryKey() != null)
              {
                throw StandardException.newException(SQLState.LANG_ADD_PRIMARY_KEY_FAILED1,
                      td.getQualifiedName());
              }
              if (! tableScanned)
              {
                tableScanned = true;
                numRows = getSemiRowCount(tc);
              }

              break;
            case DataDictionary.CHECK_CONSTRAINT:
              if (! tableScanned)
              {
                tableScanned = true;
                numRows = getSemiRowCount(tc);
              }
              if (numRows > 0)
              {
                /*
                ** We are assuming that there will only be one
                ** check constraint that we are adding, so it
                ** is ok to do the check now rather than try
                ** to lump together several checks. 
                */
                ConstraintConstantAction.validateConstraint(
                      cca.getConstraintName(),
                      ((CreateConstraintConstantAction)cca).getConstraintText(),
                      td,
                      lcc, true);
              }
              break;
          }
        }
        else
        {
          if (SanityManager.DEBUG)
          {
            if (!(cca instanceof DropConstraintConstantAction))
            {
              SanityManager.THROWASSERT("constraintActions[" + conIndex +
              "] expected to be instanceof DropConstraintConstantAction not " +
              cca.getClass().getName());
            }
          }
        }
        constraintActions[conIndex].executeConstantAction(activation);
      }
    }

    // Are we changing the lock granularity?
    if (lockGranularity != '\0')
    {
      if (SanityManager.DEBUG)
      {
        if (lockGranularity != 'T' &&
          lockGranularity != 'R')
        {
          SanityManager.THROWASSERT(
            "lockGranularity expected to be 'T'or 'R', not " + lockGranularity);
        }
      }

      // update the TableDescriptor
      td.setLockGranularity(lockGranularity);
      // update the DataDictionary
      dd.updateLockGranularity(td, sd, lockGranularity, tc);
    }

    // Are we doing a compress table?
    if (compressTable)
    {
View Full Code Here

  private void addNewColumnToTable(Activation activation,
                   int ix)
          throws StandardException
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();

    ColumnDescriptor columnDescriptor =
      td.getColumnDescriptor(columnInfo[ix].name);
    DataValueDescriptor storableDV;
    int colNumber = td.getMaxColumnID() + ix;
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();

    /* We need to verify that the table does not have an existing
     * column with the same name before we try to add the new
     * one as addColumnDescriptor() is a void method.
     */
    if (columnDescriptor != null)
    {
      throw
        StandardException.newException(
                         SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT,
                         columnDescriptor.getDescriptorType(),
                         columnInfo[ix].name,
                         td.getDescriptorType(),
                         td.getQualifiedName());
    }

    if (columnInfo[ix].defaultValue != null)
      storableDV = columnInfo[ix].defaultValue;
    else
      storableDV = columnInfo[ix].dataType.getNull();

    // Add the column to the conglomerate.(Column ids in store are 0-based)
    tc.addColumnToConglomerate(td.getHeapConglomerateId(), colNumber,
                   storableDV);

    UUID defaultUUID = columnInfo[ix].newDefaultUUID;

    /* Generate a UUID for the default, if one exists
     * and there is no default id yet.
     */
    if (columnInfo[ix].defaultInfo != null &&
      defaultUUID == null)
    {
      defaultUUID = dd.getUUIDFactory().createUUID();
    }

    // Add the column to syscolumns.
    // Column ids in system tables are 1-based
    columnDescriptor = new ColumnDescriptor(
                           columnInfo[ix].name,
                           colNumber + 1,
                           columnInfo[ix].dataType,
                           columnInfo[ix].defaultValue,
                           columnInfo[ix].defaultInfo,
                           td,
                           defaultUUID,
                           columnInfo[ix].autoincStart,
                           columnInfo[ix].autoincInc
                           );

    dd.addDescriptor(columnDescriptor, td,
             DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);

    // now add the column to the tables column descriptor list.
    td.getColumnDescriptorList().add(columnDescriptor);

    if (columnDescriptor.isAutoincrement())
    {
      updateNewAutoincrementColumn(activation, columnInfo[ix].name,
                     columnInfo[ix].autoincStart,
                     columnInfo[ix].autoincInc);
    }

    // Update the new column to its default, if it has a non-null default
    if (columnDescriptor.hasNonNullDefault())
    {
      updateNewColumnToDefault(activation,
                columnInfo[ix].name,
                columnInfo[ix].defaultInfo.getDefaultText(),
                lcc);
   

    // Update SYSCOLPERMS table which tracks the permissions granted
    // at columns level. The sytem table has a bit map of all the columns
    // in the user table to help determine which columns have the
    // permission granted on them. Since we are adding a new column,
    // that bit map needs to be expanded and initialize the bit for it
    // to 0 since at the time of ADD COLUMN, no permissions have been
    // granted on that new column.
    //
    dd.updateSYSCOLPERMSforAddColumnToUserTable(td.getUUID(), tc);
  }
View Full Code Here

TOP

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

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.