Package org.apache.derby.iapi.sql.depend

Examples of org.apache.derby.iapi.sql.depend.DependencyManager


      ** dictionary.  We have probably already done this
      ** but it is ok to call startWriting more than once.
      */
      dd.startWriting(lcc);

            DependencyManager dm = dd.getDependencyManager();
      /*
      ** Clear out all the dependencies that exist
      ** before we recreate them so we don't grow
      ** SYS.SYSDEPENDS forever.
      */
      dm.clearDependencies(lcc, this, tc);

      /*
      ** Copy over all the dependencies to me
      */
      dm.copyDependencies(preparedStatement,   // from
                      this,   // to
                      false,  // persistent only
                      cm,
                      tc);
    }
View Full Code Here


      /*
      ** The rest are errors
      */
        default:

        DependencyManager dm;

        dm = getDataDictionary().getDependencyManager();
        throw StandardException.newException(SQLState.LANG_PROVIDER_HAS_DEPENDENT_S_P_S,
          dm.getActionString(action),
          p.getObjectName(), name);

    }
  }
View Full Code Here

   */
  public final synchronized void makeInvalid(int action,
                         LanguageConnectionContext lcc)
    throws StandardException
  {
    DependencyManager dm;

    dm = getDataDictionary().getDependencyManager();

    switch (action)
    {
      /*
      ** Some things that don't affect stored prepared
       ** statements.
      */
      case DependencyManager.PREPARED_STATEMENT_RELEASE:
        case DependencyManager.CREATE_VIEW:
        break;

      /*
       ** Things that can invalidate a stored
      ** prepared statement.
      */
      case DependencyManager.CREATE_INDEX:
      case DependencyManager.CREATE_CONSTRAINT:
      case DependencyManager.DROP_CONSTRAINT:
      case DependencyManager.DROP_TABLE:
      case DependencyManager.DROP_INDEX:
      case DependencyManager.DROP_VIEW:
      case DependencyManager.DROP_METHOD_ALIAS:
      case DependencyManager.DROP_SYNONYM:
      case DependencyManager.ALTER_TABLE:
      case DependencyManager.RENAME:
      case DependencyManager.RENAME_INDEX:
      case DependencyManager.USER_RECOMPILE_REQUEST:
      case DependencyManager.CHANGED_CURSOR:
      case DependencyManager.BULK_INSERT:
      case DependencyManager.COMPRESS_TABLE:
      case DependencyManager.SET_CONSTRAINTS_ENABLE:
      case DependencyManager.SET_CONSTRAINTS_DISABLE:
      case DependencyManager.SET_TRIGGERS_ENABLE:
      case DependencyManager.SET_TRIGGERS_DISABLE:
      case DependencyManager.ROLLBACK:
      case DependencyManager.INTERNAL_RECOMPILE_REQUEST:
      case DependencyManager.CREATE_TRIGGER:
      case DependencyManager.DROP_TRIGGER:
      case DependencyManager.DROP_COLUMN:
      case DependencyManager.DROP_COLUMN_RESTRICT:
        case DependencyManager.UPDATE_STATISTICS:
        case DependencyManager.DROP_STATISTICS:
      case DependencyManager.TRUNCATE_TABLE:
        /*
        ** If we are already invalid, don't write ourselves
        ** out.  Just to be safe, we'll send out an invalidate
        ** to our dependents either way.
        */
        if (valid == true)
        {
          valid = false;
          updateSYSSTATEMENTS(lcc, INVALIDATE, null);
        }
        dm.invalidateFor(this, dm.USER_RECOMPILE_REQUEST, lcc);
        break;
      case DependencyManager.DROP_SPS:
        //System.out.println("SPSD " + preparedStatement);
        dm.clearDependencies(lcc, this);
        break;
 
        default:

        /*
        ** We should never get here, since we can't have dangling references
        */
        if (SanityManager.DEBUG)
        {
          SanityManager.THROWASSERT("makeInvalid("+
            dm.getActionString(action)+
            ") not expected to get called; should have failed in "+
            "prepareToInvalidate()");
        }
        break;

View Full Code Here

     */
  public ConglomerateDescriptor drop(LanguageConnectionContext lcc,
    TableDescriptor td) throws StandardException
  {
        DataDictionary dd = getDataDictionary();
        DependencyManager dm = dd.getDependencyManager();
        TransactionController tc = lcc.getTransactionExecute();
       
        // invalidate any prepared statements that
        // depended on the index (including this one)
        dm.invalidateFor(this, DependencyManager.DROP_INDEX, lcc);
     
        // only drop the conglomerate if no similar index but with different
      // name. Get from dd in case we drop other dup indexes with a cascade operation     
      ConglomerateDescriptor [] congDescs =
          dd.getConglomerateDescriptors(getConglomerateNumber());
View Full Code Here

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

    int              numRows = 0;
        boolean            tableScanned = false;

    /*
    ** 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 and phantom table
    // descriptor, in which case table shape could be changed by a
    // concurrent thread doing add/drop column.

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

    if (truncateTable)
      dm.invalidateFor(td, DependencyManager.TRUNCATE_TABLE, lcc);
    else
      dm.invalidateFor(td, DependencyManager.ALTER_TABLE, lcc);

    // 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)
    {
            boolean tableNeedsScanning = false;
View Full Code Here

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

    // We already verified this in bind, but do it again
    if (columnDescriptor == null)
    {
      throw
        StandardException.newException(
                    SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE,
                    columnInfo[ix].name,
                    td.getQualifiedName());
    }

    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    ColumnDescriptorList tab_cdl = td.getColumnDescriptorList();
    int size = tab_cdl.size();

    // can NOT drop a column if it is the only one in the table
    if (size == 1)
    {
      throw StandardException.newException(
                    SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT,
                    dm.getActionString(DependencyManager.DROP_COLUMN),
                    "THE *LAST* COLUMN " + columnInfo[ix].name,
                    "TABLE",
                    td.getQualifiedName() );
    }

    droppedColumnPosition = columnDescriptor.getPosition();
    boolean cascade = (behavior == StatementType.DROP_CASCADE);

    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),
                            columnInfo[ix].name, "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();

    // 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),
                        columnInfo[ix].name, "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);
            cd.drop(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];
      cd.drop(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);

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

        /*
         * The work we've done above, specifically the possible
         * dropping of primary key, foreign key, and unique constraints
View Full Code Here

                   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);
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    int columnPosition = columnDescriptor.getPosition();

    // Clean up after the old default, if non-null
    if (columnDescriptor.hasNonNullDefault())
    {
      // Invalidate off of the old default
      DefaultDescriptor defaultDescriptor = new DefaultDescriptor(dd, columnInfo[ix].oldDefaultUUID,
                     td.getUUID(), columnPosition);

   
      dm.invalidateFor(defaultDescriptor, DependencyManager.MODIFY_COLUMN_DEFAULT, lcc);
   
      // Drop any dependencies
      dm.clearDependencies(lcc, defaultDescriptor);
    }

    UUID defaultUUID = columnInfo[ix].newDefaultUUID;

    /* Generate a UUID for the default, if one exists
View Full Code Here

            // that if role is no longer available to the current
            // user (e.g. grant is revoked, role is dropped,
            // another role has been set), we are able to
            // invalidate the ps or activation (the latter is used
            // if the current role changes).
            DependencyManager dm = dd.getDependencyManager();
            RoleGrantDescriptor rgd =
              dd.getRoleDefinitionDescriptor(role);
            ContextManager cm = lcc.getContextManager();

            dm.addDependency(ps, rgd, cm);
            dm.addDependency(activation, rgd, cm);
          }
        }
      }
    }
    return result;
View Full Code Here

        // Also add a dependency on the role (qua provider), so that if
        // role is no longer available to the current user (e.g. grant
        // is revoked, role is dropped, another role has been set), we
        // are able to invalidate the ps or activation (the latter is
        // used if the current role changes).
        DependencyManager dm = dd.getDependencyManager();
        RoleGrantDescriptor rgd = dd.getRoleDefinitionDescriptor(role);
        ContextManager cm = lcc.getContextManager();
        dm.addDependency(ps, rgd, cm);
        dm.addDependency(activation, rgd, cm);
      }
    }

    if (!resolved)
        {
View Full Code Here

     */
  public void drop(LanguageConnectionContext lcc,
           Activation activation) throws StandardException
  {
        DataDictionary dd = getDataDictionary();
        DependencyManager dm = dd.getDependencyManager();
        TransactionController tc = lcc.getTransactionExecute();
      
      //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 (getSchemaName().equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME)
                && (getUUID() == null))
          throw StandardException.newException(SQLState.LANG_SCHEMA_DOES_NOT_EXIST, getSchemaName());
     
      /*
       ** Make sure the schema is empty.
       ** In the future we want to drop everything
       ** in the schema if it is CASCADE.
       */
      if (!dd.isSchemaEmpty(this))
      {
          throw StandardException.newException(SQLState.LANG_SCHEMA_NOT_EMPTY, getSchemaName());
      }
     
      /* 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.
       */
      dm.invalidateFor(this, DependencyManager.DROP_SCHEMA, lcc);
     
      dd.dropSchemaDescriptor(getSchemaName(), tc);
     
      /*
       ** If we have dropped the current default schema,
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.depend.DependencyManager

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.