Package org.apache.derby.iapi.services.io

Examples of org.apache.derby.iapi.services.io.FormatableBitSet


    }

    int size = td.getColumnDescriptorList().size();
    droppedColumnPosition = columnDescriptor.getPosition();

    FormatableBitSet toDrop = new FormatableBitSet(size + 1);
    toDrop.set(droppedColumnPosition);
    td.setReferencedColumnMap(toDrop);

    dm.invalidateFor(td,
                        (cascade ? DependencyManager.DROP_COLUMN
                                 : DependencyManager.DROP_COLUMN_RESTRICT),
                        lcc);
         
    // If column has a default we drop the default and any dependencies
    if (columnDescriptor.getDefaultInfo() != null)
    {
      dm.clearDependencies(
                lcc, columnDescriptor.getDefaultDescriptor(dd));
    }

    // need to deal with triggers if has referencedColumns
    GenericDescriptorList tdl = dd.getTriggerDescriptors(td);
    Enumeration descs = tdl.elements();
    while (descs.hasMoreElements())
    {
      TriggerDescriptor trd = (TriggerDescriptor) descs.nextElement();
      int[] referencedCols = trd.getReferencedCols();
      if (referencedCols == null)
        continue;
      int refColLen = referencedCols.length, j;
      boolean changed = false;
      for (j = 0; j < refColLen; j++)
      {
        if (referencedCols[j] > droppedColumnPosition)
                {
          changed = true;
                }
        else if (referencedCols[j] == droppedColumnPosition)
        {
          if (cascade)
          {
                        trd.drop(lcc);
            activation.addWarning(
              StandardException.newWarning(
                                SQLState.LANG_TRIGGER_DROPPED,
                                trd.getName(), td.getName()));
          }
          else
          // we'd better give an error if don't drop it,
            // otherwsie there would be unexpected behaviors
            throw StandardException.newException(
                            SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT,
                            dm.getActionString(DependencyManager.DROP_COLUMN),
                            columnName, "TRIGGER",
                            trd.getName() );
          }
          break;
        }
      }

      // change triggers to refer to columns in new positions
      if (j == refColLen && changed)
      {
        dd.dropTriggerDescriptor(trd, tc);
        for (j = 0; j < refColLen; j++)
        {
          if (referencedCols[j] > droppedColumnPosition)
            referencedCols[j]--;
        }
        dd.addDescriptor(trd, sd,
                 DataDictionary.SYSTRIGGERS_CATALOG_NUM,
                 false, tc);
      }
    }

    ConstraintDescriptorList csdl = dd.getConstraintDescriptors(td);
    int csdl_size = csdl.size();

    ArrayList newCongloms = new ArrayList();

    // we want to remove referenced primary/unique keys in the second
    // round.  This will ensure that self-referential constraints will
    // work OK.
    int tbr_size = 0;
    ConstraintDescriptor[] toBeRemoved =
            new ConstraintDescriptor[csdl_size];

    // let's go downwards, don't want to get messed up while removing
    for (int i = csdl_size - 1; i >= 0; i--)
    {
      ConstraintDescriptor cd = csdl.elementAt(i);
      int[] referencedColumns = cd.getReferencedColumns();
      int numRefCols = referencedColumns.length, j;
      boolean changed = false;
      for (j = 0; j < numRefCols; j++)
      {
        if (referencedColumns[j] > droppedColumnPosition)
          changed = true;
        if (referencedColumns[j] == droppedColumnPosition)
          break;
      }
      if (j == numRefCols)      // column not referenced
      {
        if ((cd instanceof CheckConstraintDescriptor) && changed)
        {
          dd.dropConstraintDescriptor(cd, tc);
          for (j = 0; j < numRefCols; j++)
          {
            if (referencedColumns[j] > droppedColumnPosition)
              referencedColumns[j]--;
          }
          ((CheckConstraintDescriptor) cd).setReferencedColumnsDescriptor(new ReferencedColumnsDescriptorImpl(referencedColumns));
          dd.addConstraintDescriptor(cd, tc);
        }
        continue;
      }

      if (! cascade)
      {
        // Reject the DROP COLUMN, because there exists a constraint
        // which references this column.
        //
        throw StandardException.newException(
                        SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT,
                        dm.getActionString(DependencyManager.DROP_COLUMN),
                        columnName, "CONSTRAINT",
                        cd.getConstraintName() );
      }

      if (cd instanceof ReferencedKeyConstraintDescriptor)
      {
        // restrict will raise an error in invalidate if referenced
        toBeRemoved[tbr_size++] = cd;
        continue;
      }

      // drop now in all other cases
      dm.invalidateFor(cd, DependencyManager.DROP_CONSTRAINT,
                  lcc);

      dropConstraint(cd, td, newCongloms, activation, lcc, true);
      activation.addWarning(
                StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED,
        cd.getConstraintName(), td.getName()));
    }

    for (int i = tbr_size - 1; i >= 0; i--)
    {
      ConstraintDescriptor cd = toBeRemoved[i];
      dropConstraint(cd, td, newCongloms, activation, lcc, false);

      activation.addWarning(
                StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED,
                cd.getConstraintName(), td.getName()));

      if (cascade)
      {
        ConstraintDescriptorList fkcdl = dd.getForeignKeys(cd.getUUID());
        for (int j = 0; j < fkcdl.size(); j++)
        {
          ConstraintDescriptor fkcd =
                        (ConstraintDescriptor) fkcdl.elementAt(j);

          dm.invalidateFor(fkcd,
                  DependencyManager.DROP_CONSTRAINT,
                  lcc);

          dropConstraint(fkcd, td,
            newCongloms, activation, lcc, true);

          activation.addWarning(
                        StandardException.newWarning(
                            SQLState.LANG_CONSTRAINT_DROPPED,
                fkcd.getConstraintName(),
                            fkcd.getTableDescriptor().getName()));
        }
      }

      dm.invalidateFor(cd, DependencyManager.DROP_CONSTRAINT, lcc);
      dm.clearDependencies(lcc, cd);
    }

    /* If there are new backing conglomerates which must be
     * created to replace a dropped shared conglomerate
     * (where the shared conglomerate was dropped as part
     * of a "drop constraint" call above), then create them
     * now.  We do this *after* dropping all dependent
     * constraints because we don't want to waste time
     * creating a new conglomerate if it's just going to be
     * dropped again as part of another "drop constraint".
     */
    createNewBackingCongloms(
      newCongloms, (long[])null, activation, dd);

        /*
         * The work we've done above, specifically the possible
         * dropping of primary key, foreign key, and unique constraints
         * and their underlying indexes, may have affected the table
         * descriptor. By re-reading the table descriptor here, we
         * ensure that the compressTable code is working with an
         * accurate table descriptor. Without this line, we may get
         * conglomerate-not-found errors and the like due to our
         * stale table descriptor.
         */
    td = dd.getTableDescriptor(tableId);

    compressTable(activation);

    ColumnDescriptorList tab_cdl = td.getColumnDescriptorList();

    // drop the column from syscolumns
    dd.dropColumnDescriptor(td.getUUID(), columnName, tc);
    ColumnDescriptor[] cdlArray =
            new ColumnDescriptor[size - columnDescriptor.getPosition()];

    // For each column in this table with a higher column position,
    // drop the entry from SYSCOLUMNS, but hold on to the column
    // descriptor and reset its position to adjust for the dropped
    // column. Then, re-add all those adjusted column descriptors
    // back to SYSCOLUMNS
    //
    for (int i = columnDescriptor.getPosition(), j = 0; i < size; i++, j++)
    {
      ColumnDescriptor cd = (ColumnDescriptor) tab_cdl.elementAt(i);
      dd.dropColumnDescriptor(td.getUUID(), cd.getColumnName(), tc);
      cd.setPosition(i);
      if (cd.isAutoincrement())
      {
        cd.setAutoinc_create_or_modify_Start_Increment(
            ColumnDefinitionNode.CREATE_AUTOINCREMENT);
      }

      cdlArray[j] = cd;
    }
    dd.addDescriptorArray(cdlArray, td,
                DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);

    List deps = dd.getProvidersDescriptorList(td.getObjectID().toString());
    for (Iterator depsIterator = deps.listIterator();
             depsIterator.hasNext();)
    {
      DependencyDescriptor depDesc =
                (DependencyDescriptor) depsIterator.next();

      DependableFinder finder = depDesc.getProviderFinder();
      if (finder instanceof DDColumnDependableFinder)
      {
        DDColumnDependableFinder colFinder =
                    (DDColumnDependableFinder) finder;
        FormatableBitSet oldColumnBitMap =
                    new FormatableBitSet(colFinder.getColumnBitMap());
        FormatableBitSet newColumnBitMap =
                    new FormatableBitSet(oldColumnBitMap);
        newColumnBitMap.clear();
        int bitLen = oldColumnBitMap.getLength();
        for (int i = 0; i < bitLen; i++)
        {
          if (i < droppedColumnPosition && oldColumnBitMap.isSet(i))
            newColumnBitMap.set(i);
          if (i > droppedColumnPosition && oldColumnBitMap.isSet(i))
            newColumnBitMap.set(i - 1);
        }
        if (newColumnBitMap.equals(oldColumnBitMap))
          continue;
        dd.dropStoredDependency(depDesc, tc);
        colFinder.setColumnBitMap(newColumnBitMap.getByteArray());
        dd.addDescriptor(depDesc, null,
                 DataDictionary.SYSDEPENDS_CATALOG_NUM,
                 true, tc);
      }
    }
View Full Code Here


      indexConglomerateNumbers = (long[]) compressIndexResult[1];
      compressIRGs = (IndexRowGenerator[]) compressIndexResult[2];
      numIndexes = indexConglomerateNumbers.length;
    }

    indexedCols = new FormatableBitSet(compressTable || truncateTable ? td.getNumberOfColumns() + 1 :
                          td.getNumberOfColumns());
    for (int index = 0; index < numIndexes; index++)
    {
      int[] colIds = compressIRGs[index].getIndexDescriptor().baseColumnPositions();
View Full Code Here

    private double getPerRowUsage() throws StandardException
    {
        if( perRowUsage < 0)
        {
            // Do not use getRefCols() because the cached refCols may no longer be valid.
            FormatableBitSet refCols = resultColumns.getReferencedFormatableBitSet(cursorTargetTable(), true, false);
            perRowUsage = 0.0;

            /* Add up the memory usage for each referenced column */
            for (int i = 0; i < refCols.size(); i++)
            {
                if (refCols.isSet(i))
                {
                    ResultColumn rc = (ResultColumn) resultColumns.elementAt(i);
                    DataTypeDescriptor expressionType = rc.getExpression().getTypeServices();
                    if( expressionType != null)
                        perRowUsage += expressionType.estimatedMemoryUsage();
View Full Code Here

  public FormatableBitSet bindResultColumnsByName(TableDescriptor targetTableDescriptor,
                                                    DMLStatementNode statement)
          throws StandardException
  {
    int      size = size();
    FormatableBitSet columnBitSet = new FormatableBitSet( targetTableDescriptor.getNumberOfColumns());

    for (int index = 0; index < size; index++)
    {
      ResultColumn rc = (ResultColumn) elementAt(index);

      rc.bindResultColumnByName(
            targetTableDescriptor,
            index + 1
          );
            int colIdx = rc.getColumnPosition() - 1;
            if( SanityManager.DEBUG)
                SanityManager.ASSERT( colIdx >= 0 && colIdx < targetTableDescriptor.getNumberOfColumns(),
                                      "Invalid column position found for " + rc.getName());
      /* Verify that this column's name is unique within the list if requested */
            if( statement != null && columnBitSet.isSet( colIdx))
            {
                String colName = rc.getName();

        if (statement instanceof UpdateNode)
        {
          throw StandardException.newException(SQLState.LANG_DUPLICATE_COLUMN_NAME_UPDATE, colName);
        }
        else
        {
          throw StandardException.newException(SQLState.LANG_DUPLICATE_COLUMN_NAME_INSERT, colName);
        }
      }
            columnBitSet.set( colIdx);
    }
    return columnBitSet;
  }
View Full Code Here

   *
   * @return the FormatableBitSet
   */
  public FormatableBitSet getColumnReferenceMap()
  {
    FormatableBitSet colMap = new FormatableBitSet(size());
    int size = size();
    for (int index = 0; index < size; index++)
    {
      ResultColumn rc = (ResultColumn) elementAt(index);
      if (rc.isReferenced())
      {
        colMap.set(index);
     
    }
    return colMap;
  }
View Full Code Here

  {
    int  index;
    int colsAdded = 0;
    int size = size();

    FormatableBitSet newReferencedCols = new FormatableBitSet(size);

    /*
    ** For an updatable cursor, we need
    ** all columns.
    */
    if (positionedUpdate)
    {
      if (always)
      {
        /* Set all bits in the bit map */
        for (index = 0; index < size; index++)
        {
          newReferencedCols.set(index);
        }

        return newReferencedCols;
      }
      else
      {
        return null;
      }
    }
 
    for (index = 0; index < size; index++)
    {
      ResultColumn oldCol = (ResultColumn) elementAt(index);
      if (oldCol.isReferenced())
      {
        /* Skip RCs whose expression is not a BCN
         * when requested to do so.
         */
        if (onlyBCNs && ! (oldCol.getExpression() instanceof BaseColumnNode))
        {
          continue;
        }
        newReferencedCols.set(index);
        colsAdded++;
      }
    }

    /* Return the FormatableBitSet if not all RCs are referenced or if
View Full Code Here

    {
      colPermsDescriptor = (ColPermsDescriptor) iterator.next();
      removePermEntryInCache(colPermsDescriptor);
      uuidKey = rf.buildIndexKeyRow(rf.COLPERMSID_INDEX_NUM, colPermsDescriptor);
      curRow=ti.getRow(tc, uuidKey, rf.COLPERMSID_INDEX_NUM);
          FormatableBitSet columns = (FormatableBitSet) curRow.getColumn(
            SYSCOLPERMSRowFactory.COLUMNS_COL_NUM).getObject();
          int currentLength = columns.getLength();
          columns.grow(currentLength+1);
          curRow.setColumn(SYSCOLPERMSRowFactory.COLUMNS_COL_NUM,
            dvf.getDataValue((Object) columns));
      ti.updateRow(keyRow, curRow,
          SYSCOLPERMSRowFactory.TABLEID_INDEX_NUM,
           bArray,
View Full Code Here

    TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM);
    faultInTabInfo(ti);

    TransactionController tc = getTransactionExecute();

    FormatableBitSet columnToReadSet = new FormatableBitSet(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_COLUMN_COUNT);
    FormatableBitSet columnToUpdateSet = new FormatableBitSet(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_COLUMN_COUNT);
    columnToUpdateSet.set(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID -1);
    columnToUpdateSet.set(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_CONSTANTSTATE -1);

    DataValueDescriptor[] replaceRow =
            new DataValueDescriptor[SYSSTATEMENTSRowFactory.SYSSTATEMENTS_COLUMN_COUNT];

    /* Set up a couple of row templates for fetching CHARS */
 
View Full Code Here

                outRow);
 
      // just interested in one column
      DataValueDescriptor[] rowTemplate    =
              new DataValueDescriptor[SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT];
      FormatableBitSet  columnToGetSet =
              new FormatableBitSet(SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT);
      columnToGetSet.set(columnNum - 1);

      rowTemplate[columnNum - 1] =
                dvf.getNullChar((StringDataValue) null);
 
      // Scan the index and go to the data pages for qualifying rows
View Full Code Here

      baseRowLocation = (RowLocationindexTemplateRow.getColumn(
                        indexTemplateRow.nColumns());
 
      /* 1st column is TABLEID (UUID - char(36)) */
      row.setColumn(SYSTABLESRowFactory.SYSTABLES_TABLEID, dvf.getCharDataValue((String) null));
      FormatableBitSet bi = new FormatableBitSet(1);
      bi.set(0);
      boolean base_row_exists =
                heapCC.fetch(
                    baseRowLocation, row.getRowArray(), (FormatableBitSet) null);

            if (SanityManager.DEBUG)
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.services.io.FormatableBitSet

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.