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

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


    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


                columnReference.setColumnNumber(
                    resultColumn.getColumnPosition());

        if (tableDescriptor != null)
        {
          FormatableBitSet referencedColumnMap = tableDescriptor.getReferencedColumnMap();
          if (referencedColumnMap == null)
            referencedColumnMap = new FormatableBitSet(
                  tableDescriptor.getNumberOfColumns() + 1);
          referencedColumnMap.set(resultColumn.getColumnPosition());
          tableDescriptor.setReferencedColumnMap(referencedColumnMap);
        }
      }
    }
View Full Code Here

     * NOTE: We need to re-get all of the columns from the heap
     * when doing a bulk fetch because we will be requalifying
     * the row in the IndexRowToBaseRow.
     */
    // Get the BitSet for all of the referenced columns
    FormatableBitSet indexReferencedCols = null;
    FormatableBitSet heapReferencedCols = null;
    if ((bulkFetch == UNSET) &&
      (requalificationRestrictionList == null ||
       requalificationRestrictionList.size() == 0))
    {
      /* No BULK FETCH or requalification, XOR off the columns coming from the heap
View Full Code Here

       * bind the constraint definition trees against that
       * FromList.  When doing this, we verify that there are
       * no nodes which can return non-deterministic results.
       */
      FromList fromList = makeFromList( dd, tableElementList, false );
            FormatableBitSet    generatedColumns = baseTable.makeColumnMap( baseTable.getGeneratedColumns() );

      /* Now that we've finally goobered stuff up, bind and validate
       * the check constraints and generation clauses.
       */
      if  (numGenerationClauses > 0)
View Full Code Here

    }

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

    //Now go through each trigger on this table and see if the column
    //being dropped is part of it's trigger columns or trigger action
    //columns which are used through REFERENCING clause
    GenericDescriptorList tdl = dd.getTriggerDescriptors(td);
    Enumeration descs = tdl.elements();
    while (descs.hasMoreElements())
    {
      TriggerDescriptor trd = (TriggerDescriptor) descs.nextElement();
      //If we find that the trigger is dependent on the column being
      //dropped because column is part of trigger columns list, then
      //we will give a warning or drop the trigger based on whether
      //ALTER TABLE DROP COLUMN is RESTRICT or CASCADE. In such a
      //case, no need to check if the trigger action columns referenced
      //through REFERENCING clause also used the column being dropped.
      boolean triggerDroppedAlready = false;

      int[] referencedCols = trd.getReferencedCols();
      if (referencedCols != null) {
        int refColLen = referencedCols.length, j;
        boolean changed = false;
        for (j = 0; j < refColLen; j++)
        {
          if (referencedCols[j] > droppedColumnPosition)
                  {
            //Trigger is not defined on the column being dropped
            //but the column position of trigger column is changing
            //because the position of the column being dropped is
            //before the the trigger column
            changed = true;
                  }
          else if (referencedCols[j] == droppedColumnPosition)
          {
            //the trigger is defined on the column being dropped
            if (cascade)
            {
                          trd.drop(lcc);
                          triggerDroppedAlready = true;
              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;
          }
        }

        // The following if condition will be true if the column
        // getting dropped is not a trigger column, but one or more
        // of the trigge column's position has changed because of
        // drop column.
        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);
        }
      }

      // If the trigger under consideration got dropped through the
      // loop above, then move to next trigger
      if (triggerDroppedAlready) continue;
     
      // Column being dropped is not one of trigger columns. Check if
      // that column is getting used inside the trigger action through
      // REFERENCING clause. This can be tracked only for triggers
      // created in 10.7 and higher releases. Derby releases prior to
      // that did not keep track of trigger action columns used
      // through the REFERENCING clause.
      int[] referencedColsInTriggerAction = trd.getReferencedColsInTriggerAction();
      if (referencedColsInTriggerAction != null) {
        int refColInTriggerActionLen = referencedColsInTriggerAction.length, j;
        boolean changedColPositionInTriggerAction = false;
        for (j = 0; j < refColInTriggerActionLen; j++)
        {
          if (referencedColsInTriggerAction[j] > droppedColumnPosition)
          {
            changedColPositionInTriggerAction = true;
          }
          else if (referencedColsInTriggerAction[j] == droppedColumnPosition)
          {
            if (cascade)
            {
                          trd.drop(lcc);
                          triggerDroppedAlready = true;
              activation.addWarning(
                StandardException.newWarning(
                                  SQLState.LANG_TRIGGER_DROPPED,
                                  trd.getName(), td.getName()));
            }
            else
            // we'd better give an error if don't drop it,
              throw StandardException.newException(
                              SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT,
                              dm.getActionString(DependencyManager.DROP_COLUMN),
                              columnName, "TRIGGER",
                              trd.getName() );
            }
            break;
          }
        }

        // change trigger to refer to columns in new positions
        // The following if condition will be true if the column
        // getting dropped is not getting used in the trigger action
        // sql through the REFERENCING clause but one or more of those
        // column's position has changed because of drop column.
        // This applies only to triggers created with 10.7 and higher.
        // Prior to that, Derby did not keep track of the trigger
        // action column used through the REFERENCING clause. Such
        // triggers will be caught later on in this method after the
        // column has been actually dropped from the table descriptor.
        if (j == refColInTriggerActionLen && changedColPositionInTriggerAction)
        {
          dd.dropTriggerDescriptor(trd, tc);
          for (j = 0; j < refColInTriggerActionLen; j++)
          {
            if (referencedColsInTriggerAction[j] > droppedColumnPosition)
              referencedColsInTriggerAction[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);

        /*
         * 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();

    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

            if (init_scanColumnList != null)
            {
                // verify that all columns specified in qualifiers, start
                // and stop positions are specified in the scanColumnList. 
               
                FormatableBitSet required_cols;

                if (qualifier != null)
                    required_cols = RowUtil.getQualifierBitSet(qualifier);
                else
                    required_cols = new FormatableBitSet(0);

                // add in start columns
                if (this.init_startKeyValue != null)
                {
          required_cols.grow(this.init_startKeyValue.length);
                    for (int i = 0; i < this.init_startKeyValue.length; i++)
                        required_cols.set(i);
                }

                if (this.init_stopKeyValue != null)
                {
          required_cols.grow(this.init_stopKeyValue.length);
                    for (int i = 0; i < this.init_stopKeyValue.length; i++)
                        required_cols.set(i);
                }

                FormatableBitSet required_cols_and_scan_list =
                    (FormatableBitSet) required_cols.clone();

                required_cols_and_scan_list.and(init_scanColumnList);

        // FormatableBitSet equals requires the two FormatableBitSets to be of same
        // length.
        required_cols.grow(init_scanColumnList.size());

                if (!required_cols_and_scan_list.equals(required_cols))
                {
                    SanityManager.THROWASSERT(
                        "Some column specified in a Btree " +
                        " qualifier/start/stop list is " +
                        "not represented in the scanColumnList." +
View Full Code Here

    // and we really want it to have (such as in drop column), in any case
    // if we passed in table descriptor to this function with a bit map,
    // we really need this, we generate the bitmaps on the fly and update
    // SYSDEPENDS

    FormatableBitSet affectedCols = null, subsetCols = null;
    if (p instanceof TableDescriptor)
    {
      affectedCols = ((TableDescriptor) p).getReferencedColumnMap();
      if (affectedCols != null)
        subsetCols = new FormatableBitSet(affectedCols.getLength());
    }

    {
      StandardException noInvalidate = null;
      // We cannot use an iterator here as the invalidations can remove
      // entries from this list.
      for (int ei = list.size() - 1; ei >= 0; ei--)
      {
        if (ei >= list.size())
          continue;
        Dependency dependency = (Dependency) list.get(ei);

        Dependent dep = dependency.getDependent();

        if (affectedCols != null)
        {
          TableDescriptor td = (TableDescriptor) dependency.getProvider();
          FormatableBitSet providingCols = td.getReferencedColumnMap();
          if (providingCols == null)
          {
            if (dep instanceof ViewDescriptor)
            {
              ViewDescriptor vd = (ViewDescriptor) dep;
              SchemaDescriptor compSchema;
              compSchema = dd.getSchemaDescriptor(vd.getCompSchemaId(), null);
              CompilerContext newCC = lcc.pushCompilerContext(compSchema);
              Parser  pa = newCC.getParser();

              // Since this is always nested inside another SQL
              // statement, so topLevel flag should be false
              CreateViewNode cvn = (CreateViewNode)pa.parseStatement(
                        vd.getViewText());

              // need a current dependent for bind
              newCC.setCurrentDependent(dep);
              cvn.bindStatement();
              ProviderInfo[] providerInfos = cvn.getProviderInfo();
              lcc.popCompilerContext(newCC);

              boolean    interferent = false;
              for (int i = 0; i < providerInfos.length; i++)
              {
                Provider provider = null;
                  provider = (Provider) providerInfos[i].
                          getDependableFinder().
                          getDependable(dd,
                          providerInfos[i].getObjectId());
                if (provider instanceof TableDescriptor)
                {
                  TableDescriptor tab = (TableDescriptor)provider;
                  FormatableBitSet colMap = tab.getReferencedColumnMap();
                  if (colMap == null)
                    continue;
                  // if later on an error is raised such as in
                  // case of interference, this dependency line
                  // upgrade will not happen due to rollback
View Full Code Here

    if (!allColumns && targetVTI == null)
    {
      getCompilerContext().pushCurrentPrivType( Authorizer.NULL_PRIV);
      try
      {
        readColsBitSet = new FormatableBitSet();
        FromBaseTable fbt = getResultColumnList(resultSet.getResultColumns());
        afterColumns = resultSet.getResultColumns().copyListAndObjects();

        readColsBitSet = getReadMap(dataDictionary,
                    targetTableDescriptor,
View Full Code Here

        lockMode,
        false,
        changedColumnIds, null, null,
        getFKInfo(),
        getTriggerInfo(),
        (readColsBitSet == null) ? (FormatableBitSet)null : new FormatableBitSet(readColsBitSet),
        getReadColMap(targetTableDescriptor.getNumberOfColumns(),readColsBitSet),
        resultColumnList.getStreamStorableColIds(targetTableDescriptor.getNumberOfColumns()),
        (readColsBitSet == null) ?
          targetTableDescriptor.getNumberOfColumns() :
          readColsBitSet.getNumBitsSet(),     
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.