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

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


    throws StandardException
  {
    LanguageConnectionContext lcc = getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    ViewDescriptor vd = dd.getViewDescriptor(td);
    DependencyManager dm = dd.getDependencyManager();
    ProviderInfo[] pis = dm.getPersistentProviderInfos(vd);
    this.descriptorList = new ArrayList();
         
    int siz = pis.length;
    for (int i=0; i < siz; i++)
    {
View Full Code Here


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


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

    if (sd == null) {
      sd = dd.getSchemaDescriptor(schemaName, lcc.getTransactionExecute(), true);
    }


    /* Get the alias descriptor.  We're responsible for raising
     * the error if it isn't found
     */
    AliasDescriptor ad = dd.getAliasDescriptor(sd.getUUID().toString(), aliasName, nameSpace);

    // RESOLVE - fix error message
    if (ad == null)
    {
      throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, ad.getAliasType(nameSpace),  aliasName);
    }

    /* Prepare all dependents to invalidate.  (This is their 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.
     * We check for invalidation before we drop the descriptor
     * since the descriptor may be looked up as part of
     * decoding tuples in SYSDEPENDS.
     */
    int invalidationType = 0;
    switch (ad.getAliasType())
    {
      case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
      case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
        invalidationType = DependencyManager.DROP_METHOD_ALIAS;
        break;

      case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
        invalidationType = DependencyManager.DROP_SYNONYM;
        break;
    }

    dm.invalidateFor(ad, invalidationType, lcc);

    if (ad.getAliasType() == AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
    {
      // Drop the entry from SYSTABLES as well.
      DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
View Full Code Here

    ConstraintDescriptorList  tmpCdl;
    boolean            enforceThisConstraint;

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

    tmpCdl = getConstraintDescriptorList(dd);

    int[] enabledCol = new int[1];
    enabledCol[0] = ConstraintDescriptor.SYSCONSTRAINTS_STATE_FIELD;
    /*
    ** 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);

    /*
    ** Callback to rep subclass
    */
    publishToTargets(activation);

    boolean skipFKs = false;

    /*
    ** If the constraint list is empty, then we are getting
    ** all constraints.  In this case, don't bother going
    ** after referencing keys (foreign keys) when we are
    ** disabling a referenced key (pk or unique key) since
    ** we know we'll hit it eventually. 
    */
    if (tmpCdl == null)
    {
      skipFKs = true;
      tmpCdl = dd.getConstraintDescriptors((TableDescriptor)null);
    }
 
    Hashtable checkConstraintTables = null;
    int cdlSize = tmpCdl.size();
    for (int index = 0; index < cdlSize; index++)
    {
      cd = tmpCdl.elementAt(index);

      /* 
      ** We are careful to enable this constraint before trying
      ** to enable constraints that reference it.  Similarly,
      ** we disabled constraints that reference us before we
      ** disable ourselves, to make sure everything works ok.
      */
      if (unconditionallyEnforce)
      {
        enforceThisConstraint = true;
      }
      else
      {
        enforceThisConstraint = (enable && !cd.isEnabled());
      }

      if (enforceThisConstraint)
      {
        if (cd instanceof ForeignKeyConstraintDescriptor)
        {
          validateFKConstraint((ForeignKeyConstraintDescriptor)cd, dd, tc, lcc.getContextManager());
        }
        /*
        ** For check constraints, we build up a list of check constriants
        ** by table descriptor.  Once we have collected them all, we
        ** execute them in a single query per table descriptor.
        */
        else if (cd instanceof CheckConstraintDescriptor)
        {
          td = cd.getTableDescriptor();

          if (checkConstraintTables == null)
          {
            checkConstraintTables = new Hashtable(10);
          }

          ConstraintDescriptorList tabCdl = (ConstraintDescriptorList)
                        checkConstraintTables.get(td.getUUID());
          if (tabCdl == null)
          {
            tabCdl = new ConstraintDescriptorList();
            checkConstraintTables.put(td.getUUID(), tabCdl);
          }
          tabCdl.add(cd);
        }
        /*
        ** If we are enabling a constraint, we need to issue
        ** the invalidation on the underlying table rather than
        ** the constraint we are enabling.  This is because
        ** stmts that were compiled against a disabled constraint
        ** have no depedency on that disabled constriant.
        */
        dm.invalidateFor(cd.getTableDescriptor(),
                  DependencyManager.SET_CONSTRAINTS_ENABLE, lcc);
        cd.setEnabled();
        dd.updateConstraintDescriptor(cd,
                      cd.getUUID(),
                      enabledCol,
                      tc);
      }
 
      /*
      ** If we are dealing with a referenced constraint, then
      ** we find all of the constraints that reference this constraint.
      ** Turn them on/off based on what we are doing to this
      ** constraint.
      */
      if (!skipFKs &&
        (cd instanceof ReferencedKeyConstraintDescriptor))
      {
        ForeignKeyConstraintDescriptor fkcd;
        ReferencedKeyConstraintDescriptor refcd;
        ConstraintDescriptorList fkcdl;
 
        refcd = (ReferencedKeyConstraintDescriptor)cd;
        fkcdl = refcd.getForeignKeyConstraints(ReferencedKeyConstraintDescriptor.ALL);

        int fkcdlSize = fkcdl.size();
        for (int inner = 0; inner < fkcdlSize; inner++)
        {
          fkcd = (ForeignKeyConstraintDescriptor) fkcdl.elementAt(inner)
          if (enable && !fkcd.isEnabled())
          {
            dm.invalidateFor(fkcd.getTableDescriptor(),
                  DependencyManager.SET_CONSTRAINTS_ENABLE, lcc);
            validateFKConstraint(fkcd, dd, tc, lcc.getContextManager());
            fkcd.setEnabled();
            dd.updateConstraintDescriptor(fkcd,
                fkcd.getUUID(),
                enabledCol,
                tc);
          }
          else if (!enable && fkcd.isEnabled())
          {
            dm.invalidateFor(fkcd, DependencyManager.SET_CONSTRAINTS_DISABLE,
                     lcc);
            fkcd.setDisabled();
            dd.updateConstraintDescriptor(fkcd,
                fkcd.getUUID(),
                enabledCol,
                tc);
          }
        }
      }
 
      if (!enable && cd.isEnabled())
      {
        dm.invalidateFor(cd, DependencyManager.SET_CONSTRAINTS_DISABLE,
                 lcc);
        cd.setDisabled();
        dd.updateConstraintDescriptor(cd,
                        cd.getUUID(),
                        enabledCol,
View Full Code Here

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

 
View Full Code Here

        if (apl != null && apl.size() > 0)
        {
          /* Get all the dependencies for the current statement and transfer
           * them to this view.
           */
          DependencyManager dm = dd.getDependencyManager();
          providerInfos = dm.getPersistentProviderInfos(apl);
        }
        else
        {
          providerInfos = new ProviderInfo[0];
          // System.out.println("TABLE ELEMENT LIST EMPTY");
View Full Code Here

   */
  private void dropAllDeclaredGlobalTempTables() throws StandardException {
    if (allDeclaredGlobalTempTables == null)
      return;
   
    DependencyManager dm = getDataDictionary().getDependencyManager();
    StandardException topLevelStandardException = null;

    //collect all the exceptions we might receive while dropping the temporary tables and throw them as one chained exception at the end.
    for (int i = 0; i < allDeclaredGlobalTempTables.size(); i++) {
      try {
        TempTableInfo tempTableInfo = (TempTableInfo)allDeclaredGlobalTempTables.get(i);
        TableDescriptor td = tempTableInfo.getTableDescriptor();
        //the following 2 lines of code has been copied from DropTableConstantAction. If there are any changes made there in future,
        //we should check if they need to be made here too.
        dm.invalidateFor(td, DependencyManager.DROP_TABLE, this);
        tran.dropConglomerate(td.getHeapConglomerateId());
      } catch (StandardException e) {
        if (topLevelStandardException == null) {
          // always keep the first exception unchanged
          topLevelStandardException = e;
View Full Code Here

        /* is there an open result set? */
        if (rs != null && ! rs.isClosed())
        {
          if ((provider != null) && rs.returnsRows()) {
          DependencyManager dmgr = getDataDictionary().getDependencyManager();

          throw StandardException.newException(SQLState.LANG_CANT_INVALIDATE_OPEN_RESULT_SET,
                  dmgr.getActionString(action),
                  provider.getObjectName());

          }
          return true;
        }
View Full Code Here

    try {
   
      notifyLoader(false);
      dd.invalidateAllSPSPlans();
      DependencyManager dm = dd.getDependencyManager();
      dm.invalidateFor(fid, DependencyManager.DROP_JAR, lcc);

      dd.dropFileInfoDescriptor(fid);

      fr.remove(JarUtil.mkExternalName(schemaName, sqlName, fr.getSeparatorChar()),
        fid.getGenerationId());
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

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.