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

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


    // Translate the base column names to column positions
    baseColumnPositions = new int[columnNames.length];
    for (int i = 0; i < columnNames.length; i++)
    {
      ColumnDescriptor columnDescriptor;

      // Look up the column in the data dictionary
      columnDescriptor = td.getColumnDescriptor(columnNames[i]);
      if (columnDescriptor == null)
      {
        throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE,
                              columnNames[i],
                              tableName);
      }

      // Don't allow a column to be created on a non-orderable type
      // (for primaryKey and unique constraints)
      if ( columnsMustBeOrderable &&
         ( ! columnDescriptor.getType().getTypeId().orderable(
                              cf))
         )
      {
        throw StandardException.newException(SQLState.LANG_COLUMN_NOT_ORDERABLE_DURING_EXECUTION,
          columnDescriptor.getType().getTypeId().getSQLTypeName());
      }

      // Remember the position in the base table of each column
      baseColumnPositions[i] = columnDescriptor.getPosition();
    }

    return baseColumnPositions;
  }
View Full Code Here


    throws StandardException
  {
    TableDescriptor       td;
    UUID             toid;
    SchemaDescriptor      schemaDescriptor;
    ColumnDescriptor      columnDescriptor;
    ExecRow            template;

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

    /* Mark the activation as being for create table */
    activation.setForCreateTable();

        // setup for create conglomerate call:
        //   o create row template to tell the store what type of rows this
        //     table holds.
        //   o create array of collation id's to tell collation id of each
        //     column in table.
    template            = RowUtil.getEmptyValueRow(columnInfo.length, lcc);
        int[] collation_ids = new int[columnInfo.length];

    for (int ix = 0; ix < columnInfo.length; ix++)
    {
            ColumnInfo  col_info = columnInfo[ix];

            // Get a template value for each column

      if (col_info.defaultValue != null)
            {
                /* If there is a default value, use it, otherwise use null */
        template.setColumn(ix + 1, col_info.defaultValue);
            }
      else
            {
        template.setColumn(ix + 1, col_info.dataType.getNull());
            }

            // get collation info for each column.

            collation_ids[ix] = col_info.dataType.getCollationType();
    }


    /* create the conglomerate to hold the table's rows
     * RESOLVE - If we ever have a conglomerate creator
     * that lets us specify the conglomerate number then
     * we will need to handle it here.
     */
    long conglomId = tc.createConglomerate(
        "heap", // we're requesting a heap conglomerate
        template.getRowArray(), // row template
        null, //column sort order - not required for heap
                collation_ids,
        properties, // properties
        tableType == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE ?
                    (TransactionController.IS_TEMPORARY |
                     TransactionController.IS_KEPT) :
                        TransactionController.IS_DEFAULT);

    /*
    ** 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.
    */
    if ( tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE )
      dd.startWriting(lcc);

    SchemaDescriptor sd;
    if (tableType == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE)
      sd = dd.getSchemaDescriptor(schemaName, tc, true);
    else
      sd = DDLConstantAction.getSchemaDescriptorForCreate(dd, activation, schemaName);

    //
    // Create a new table descriptor.
    //
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();

    if ( tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE )
    {
      td = ddg.newTableDescriptor(tableName, sd, tableType, lockGranularity);
      dd.addDescriptor(td, sd, DataDictionary.SYSTABLES_CATALOG_NUM, false, tc);
    } else
    {
      td = ddg.newTableDescriptor(tableName, sd, tableType, onCommitDeleteRows, onRollbackDeleteRows);
      td.setUUID(dd.getUUIDFactory().createUUID());
    }
    toid = td.getUUID();

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

    /* NOTE: We must write the columns out to the system
     * tables before any of the conglomerates, including
     * the heap, since we read the columns before the
     * conglomerates when building a TableDescriptor.
     * This will hopefully reduce the probability of
     * a deadlock involving those system tables.
     */
   
    // for each column, stuff system.column
    int index = 1;

    ColumnDescriptor[] cdlArray = new ColumnDescriptor[columnInfo.length];
    for (int ix = 0; ix < columnInfo.length; ix++)
    {
      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();
      }

      if (columnInfo[ix].autoincInc != 0)//dealing with autoinc column
      columnDescriptor = new ColumnDescriptor(
                           columnInfo[ix].name,
                   index++,
                   columnInfo[ix].dataType,
                   columnInfo[ix].defaultValue,
                   columnInfo[ix].defaultInfo,
                   td,
                   defaultUUID,
                   columnInfo[ix].autoincStart,
                   columnInfo[ix].autoincInc,
                   columnInfo[ix].autoinc_create_or_modify_Start_Increment
                 );
      else
        columnDescriptor = new ColumnDescriptor(
                       columnInfo[ix].name,
               index++,
               columnInfo[ix].dataType,
               columnInfo[ix].defaultValue,
               columnInfo[ix].defaultInfo,
View Full Code Here

      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 = ef.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());
            }
          }
View Full Code Here

    throws StandardException
  {
    int         size = size();
    int[]        myPositions = new int[ size ];
    String        columnName;
    ColumnDescriptor  cd;

    for ( int index = 0; index < size; index++ )
    {
      ResultColumn resultColumn = (ResultColumn) elementAt( index );
      columnName = resultColumn.getName();
      cd = td.getColumnDescriptor( columnName );

      if ( cd == null )
      {
        throw StandardException.newException
          ( SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE, columnName, td.getQualifiedName() );
      }

      myPositions[ index ] = cd.getPosition();
    }

    return myPositions;
  }
View Full Code Here

                        SQLState.LANG_INVALID_USE_OF_DEFAULT);
                }

        //        DefaultNode defaultNode = (DefaultNode) rc.getExpression();
        // Get ColumnDescriptor by name or by position?
        ColumnDescriptor cd = null;
        if (tcl == null)
        {
          cd = ttd.getColumnDescriptor(index + 1);
        }
        else if (index < tcl.size())
        {
          ResultColumn trc = (ResultColumn) tcl.elementAt(index);
          cd = ttd.getColumnDescriptor(trc.getName());
        }

        // Too many RCs if no ColumnDescriptor
        if (cd == null)
        {
          throw StandardException.newException(SQLState.LANG_TOO_MANY_RESULT_COLUMNS,
                  ttd.getQualifiedName());
        }

        if (cd.isAutoincrement())
        {
          rc.setAutoincrementGenerated();
        } // end of if ()
       
        DefaultInfoImpl defaultInfo = (DefaultInfoImpl) cd.getDefaultInfo();

                //
                // For generated columns, we don't have enough context at this
                // point to bind the generation clause (the default) and
                // unfortunately that step occurs very soon after defaults are substituted in. The
                // parsing and binding of generation clauses happens considerably
                // later on. At this juncture, we can be patient and just plug
                // in a NULL literal as a placeholder. For generated columns,
                // the generation clause tree is plugged in in DMLModStatementNode.parseAndBindGenerationClauses().
                //
        if ( (defaultInfo != null) && !defaultInfo.isGeneratedColumn() )
        {
          /* Query is dependent on the DefaultDescriptor */
          DefaultDescriptor defaultDescriptor = cd.getDefaultDescriptor(getDataDictionary());
          getCompilerContext().createDependency(defaultDescriptor);

          rc.setExpression(
            DefaultNode.parseDefault(
              defaultInfo.getDefaultText(),
View Full Code Here

    for (int index = 0; index < size; index++)
    {
      ResultColumn rc = (ResultColumn) elementAt(index);
      ResultColumn sourceRC =
        (ResultColumn)((sourceRSRCL == null) ? null : sourceRSRCL.elementAt(index));
      ColumnDescriptor cd = rc.getTableColumnDescriptor();

            if ( (cd != null) && cd.hasGenerationClause() )
            {
                if ( (sourceRC != null) && !sourceRC.hasGenerationClause() && !sourceRC.wasDefaultColumn() )
                {
                    throw StandardException.newException(SQLState.LANG_CANT_OVERRIDE_GENERATION_CLAUSE, rc.getName());
                }

                if ( sourceRC != null ) { sourceRC.setColumnDescriptor(cd.getTableDescriptor(), cd); }
            }
     
      if ((cd != null) && (cd.isAutoincrement()))
      {
        if ((sourceRC != null) &&
          (sourceRC.isAutoincrementGenerated()))
        {
          sourceRC.setColumnDescriptor(cd.getTableDescriptor(), cd);

        }else{
          if(cd.isAutoincAlways())
            throw StandardException.newException(SQLState.LANG_AI_CANNOT_MODIFY_AI,
                  rc.getName());
        }
      }
    }
View Full Code Here

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

            DataValueDescriptor[][] row_array = new DataValueDescriptor[100][];
            row_array[0] = baseRow.getRowArray();
            RowLocation[] old_row_location_array = new RowLocation[100];
View Full Code Here

                            // SELECT (for example), rather than the
                            // FromSubquery's, so we need to match the table
                            // number one level above, cf the test cases in
                            // JoinTest#testDerby_4679 which have subqueries.

                            ColumnDescriptor cd = rc.getTableColumnDescriptor();

                            if (SanityManager.DEBUG) {
                                SanityManager.ASSERT(
                                    cd != null || ft instanceof FromSubquery);
                            }

                            if ( (cd != null && cd.getPosition() ==
                                      columnNumber) ||
                                 (vcn.getSourceColumn().getColumnPosition() ==
                                     columnNumber) ) {

                                // Found matching (t,c) within this top
View Full Code Here

      }

      /* We have a match.  We need to create a dummy ColumnDescriptor
       * since calling code expects one to get column info.
       */
      ColumnDescriptor cd = new ColumnDescriptor(
                      rc.getName(),
                      matchRC.getVirtualColumnId(),
                      matchRC.getType(),
                      null,
                      null,
View Full Code Here

      ResultColumn rc = (ResultColumn) elementAt(index);

      if (rc.getTypeId().streamStorable())
      {
                //System.out.println("    streamStorable=true");
        ColumnDescriptor cd = rc.getTableColumnDescriptor();
        isSS[cd.getPosition()-1] = true;
      }
    }

    for (int ix=0;ix<isSS.length;ix++) if (isSS[ix]) ssCount++;
View Full Code Here

TOP

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

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.