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

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


  public ResultColumnList expandToAll(TableDescriptor td,
                TableName tableName)
            throws StandardException
  {
    ResultColumn        rc;
    ColumnDescriptor      cd;
    ResultColumnList      retval;
    ResultColumn[]        originalRCS;
    int              posn;

    /* Get a new ResultColumnList */
    retval = (ResultColumnList) getNodeFactory().getNode(
                    C_NodeTypes.RESULT_COLUMN_LIST,
                    getContextManager());

    /*
    ** Form a sorted array of the ResultColumns
    */
    originalRCS = getSortedByPosition();

    posn = 0;
    /* Iterate through the ColumnDescriptors for the given table */
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    int           cdlSize = cdl.size();

    for (int index = 0; index < cdlSize; index++)
    {
      cd = (ColumnDescriptor) cdl.elementAt(index);

      if ((posn < originalRCS.length) &&
        (cd.getPosition() == originalRCS[posn].getColumnPosition()))
      {
        rc = originalRCS[posn];
        posn++;
      }
      else
      {
        /* Build a ResultColumn/ColumnReference pair for the column */
        rc = makeColumnReferenceFromName( tableName, cd.getColumnName() );

        /* Bind the new ResultColumn */
        rc.bindResultColumnByPosition(td, cd.getPosition());
      }

      /* Add the ResultColumn to the list */
      retval.addResultColumn(rc);
    }
 
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

      if (rc.isDefaultColumn())
      {
        //        DefaultNode defaultNode = (DefaultNode) rc.getExpression();
        // Get ColumnDescriptor by name or by position?
        ColumnDescriptor cd;
        if (tcl == null)
        {
          cd = ttd.getColumnDescriptor(index + 1);
        }
        else
        {
          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

      throws StandardException
  {
    ResultColumnList       rcList = null;
    ResultColumn         resultColumn;
    ValueNode           valueNode;
    ColumnDescriptor       colDesc = null;
    TableName           exposedName;

    /* Cache exposed name for this table.
     * The exposed name becomes the qualifier for each column
     * in the expanded list.
     */
    exposedName = getExposedTableName();

    /* Add all of the columns in the table */
    rcList = (ResultColumnList) getNodeFactory().getNode(
                    C_NodeTypes.RESULT_COLUMN_LIST,
                    getContextManager());
    ColumnDescriptorList cdl = tableDescriptor.getColumnDescriptorList();
    int           cdlSize = cdl.size();

    for (int index = 0; index < cdlSize; index++)
    {
      /* Build a ResultColumn/BaseColumnNode pair for the column */
      colDesc = (ColumnDescriptor) cdl.elementAt(index);
      //A ColumnDescriptor instantiated through SYSCOLUMNSRowFactory only has
      //the uuid set on it and no table descriptor set on it. Since we know here
      //that this columnDescriptor is tied to tableDescriptor, set it so using
      //setTableDescriptor method. ColumnDescriptor's table descriptor is used
      //to get ResultSetMetaData.getTableName & ResultSetMetaData.getSchemaName
      colDesc.setTableDescriptor(tableDescriptor);

      valueNode = (ValueNode) getNodeFactory().getNode(
                      C_NodeTypes.BASE_COLUMN_NODE,
                      colDesc.getColumnName(),
                        exposedName,
                      colDesc.getType(),
                      getContextManager());
      resultColumn = (ResultColumn) getNodeFactory().getNode(
                      C_NodeTypes.RESULT_COLUMN,
                      colDesc,
                      valueNode,
View Full Code Here

      throws StandardException
  {
    ResultColumnList       rcList = null;
    ResultColumn         resultColumn;
    ValueNode           valueNode;
    ColumnDescriptor       cd = null;
    TableName           exposedName;

    /* Cache exposed name for this table.
     * The exposed name becomes the qualifier for each column
     * in the expanded list.
     */
    exposedName = getExposedTableName();

    /* Add all of the columns in the table */
    ResultColumnList newRcl = (ResultColumnList) getNodeFactory().getNode(
                        C_NodeTypes.RESULT_COLUMN_LIST,
                        getContextManager());
    ColumnDescriptorList cdl = tableDescriptor.getColumnDescriptorList();
    int           cdlSize = cdl.size();

    for (int index = 0; index < cdlSize; index++)
    {
      /* Build a ResultColumn/BaseColumnNode pair for the column */
      cd = (ColumnDescriptor) cdl.elementAt(index);
      int position = cd.getPosition();

      if (!colsWeWant.get(position))
      {
        continue;
      }

      if ((resultColumn = inputRcl.getResultColumn(position)) == null)
      { 
        valueNode = (ValueNode) getNodeFactory().getNode(
                        C_NodeTypes.COLUMN_REFERENCE,
                        cd.getColumnName(),
                        exposedName,
                        getContextManager());
        resultColumn = (ResultColumn) getNodeFactory().
                        getNode(
                          C_NodeTypes.RESULT_COLUMN,
View Full Code Here

      throws StandardException
  {
    ResultColumnList       rcList = null;
    ResultColumn         resultColumn;
    ValueNode           valueNode;
    ColumnDescriptor       colDesc = null;


    TableName tableName = makeTableName(td.getSchemaName(),
                      td.getName());

    /* Add all of the columns in the table */
    rcList = (ResultColumnList) getNodeFactory().getNode(
                    C_NodeTypes.RESULT_COLUMN_LIST,
                    getContextManager());
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    int           cdlSize = cdl.size();

    for (int index = 0; index < cdlSize; index++)
    {
      /* Build a ResultColumn/BaseColumnNode pair for the column */
      colDesc = (ColumnDescriptor) cdl.elementAt(index);

      valueNode = (ValueNode) getNodeFactory().getNode(
                      C_NodeTypes.BASE_COLUMN_NODE,
                      colDesc.getColumnName(),
                        exposedName,
                      colDesc.getType(),
                      getContextManager());
      resultColumn = (ResultColumn) getNodeFactory().getNode(
                      C_NodeTypes.RESULT_COLUMN,
                      colDesc,
                      valueNode,
View Full Code Here

   */
  public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList,
      Vector  aggregateVector)
    throws StandardException
  {
    ColumnDescriptor  cd;
    TableDescriptor    td;

    if (SanityManager.DEBUG)
    {
      SanityManager.ASSERT(fromList.size() != 0,
        "fromList expected to be non-empty");
      if (! (fromList.elementAt(0) instanceof FromBaseTable))
      {
        SanityManager.THROWASSERT(
          "fromList.elementAt(0) expected to be instanceof FromBaseTable, not " +
          fromList.elementAt(0).getClass().getName());
      }

    }
    // Get the TableDescriptor for the target table
    td = ((FromBaseTable) fromList.elementAt(0)).getTableDescriptor();

    // Get the ColumnDescriptor for the column
    cd = td.getColumnDescriptor(columnName);
    if (SanityManager.DEBUG)
    {
      SanityManager.ASSERT(cd != null,
        "cd expected to be non-null");
    }

    /* If we have the default text, then parse and bind it and
     * return the tree.
     */
    DefaultInfoImpl defaultInfo = (DefaultInfoImpl) cd.getDefaultInfo();
    if (defaultInfo != null)
    {
      String    defaultText = defaultInfo.getDefaultText();
      ValueNode  defaultTree = parseDefault(defaultText, getLanguageConnectionContext(),
                           getCompilerContext());

      /* Query is dependent on the DefaultDescriptor */
      DefaultDescriptor defaultDescriptor = cd.getDefaultDescriptor(
                          getDataDictionary());
      getCompilerContext().createDependency(defaultDescriptor);

      return defaultTree.bindExpression(
                  fromList,
View Full Code Here

    }

    private DataTypeDescriptor getColumnDataTypeDescriptor(String colName, TableDescriptor td)
    {
        // check existing columns
        ColumnDescriptor cd = td.getColumnDescriptor(colName);
        if (cd != null)
        {
            return cd.getType();
        }
        // check for new columns
        return getColumnDataTypeDescriptor(colName);
    }
View Full Code Here

                      UUID           uuid,
                      ColumnDescriptorList   cdl,
                      TupleDescriptor     td)
      throws StandardException
  {
    ColumnDescriptor    cd;
    ColumnDescriptorList    cdlCopy         = new ColumnDescriptorList();
    DataValueDescriptor    refIDOrderable  = null;
    TabInfoImpl                 ti              = coreInfo[SYSCOLUMNS_CORE_NUM];

    /* Use refIDOrderable in both start and stop position for scan. */
    refIDOrderable = getIDValueAsCHAR(uuid);

    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(1);
    keyRow.setColumn(1, refIDOrderable);

    getDescriptorViaIndex(
            SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID,
            keyRow,
            (ScanQualifier [][]) null,
            ti,
            td,
            (ColumnDescriptorList) cdl,
            false);

    /* The TableDescriptor's column descriptor list must be ordered by
     * columnNumber.  (It is probably not ordered correctly at this point due
     * to the index on syscolumns being on (tableId, columnName).)  The
     * cheapest way to reorder the list appears to be to copy it (above), and then
     * walk the copy and put the elements back into the original in the
     * expected locations.
     */
    int cdlSize = cdl.size();
    for (int index = 0; index < cdlSize; index++)
    {
      cdlCopy.add( cdl.get(index));
    }
    for (int index = 0; index < cdlSize; index++)
    {
      cd = (ColumnDescriptor) cdlCopy.elementAt(index);
      cdl.set(cd.getPosition() - 1, cd);
    }
  }
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.