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

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


           TableDescriptor td, Activation activation)
    throws StandardException
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();
    //for indexes, we only invalidate sps, rest we ignore(ie views)
    dm.invalidateFor(td, DependencyManager.RENAME_INDEX, lcc);

    ConglomerateDescriptor conglomerateDescriptor =
      dd.getConglomerateDescriptor(oldObjectName, sd, true);

    if (conglomerateDescriptor == null)
View Full Code Here


    TableDescriptor td;
    ConglomerateDescriptor cd = null;

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


    dd.startWriting(lcc);

    if (forTable)
    {
      td = dd.getTableDescriptor(objectName, sd);
    }
   
    else
    {
      cd = dd.getConglomerateDescriptor(objectName,
                       sd, false);
      td = dd.getTableDescriptor(cd.getTableID());
    }

    /* invalidate all SPS's on the table-- bad plan on SPS, so user drops
     * statistics and would want SPS's invalidated so that recompile would
     * give good plans; thats the theory anyways....
     */
    dm.invalidateFor(td, DependencyManager.DROP_STATISTICS, lcc);

    dd.dropStatisticsDescriptors(td.getUUID(), ((cd != null) ? cd.getUUID() :
                   null), tc);
  }
View Full Code Here

    UUID tableID;
    ConglomerateDescriptor[] cds;

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

    if ((sd != null) && sd.getSchemaName().equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME)) {
      td = lcc.getTableDescriptorForDeclaredGlobalTempTable(tableName); //check if this is a temp table before checking data dictionary

      if (td == null) //td null here means it is not a temporary table. Look for table in physical SESSION schema
        td = dd.getTableDescriptor(tableName, sd);

      if (td == null) //td null means tableName is not a temp table and it is not a physical table in SESSION schema
      {
        throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
      }

      if (td.getTableType() ==  TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
        dm.invalidateFor(td, DependencyManager.DROP_TABLE, lcc);
        tc.dropConglomerate(td.getHeapConglomerateId());
        lcc.dropDeclaredGlobalTempTable(tableName);
        return;
      }
    }

    /* Lock the table before we access the data dictionary
     * to prevent deadlocks.
     *
     * Note that for DROP TABLE replayed at Targets during REFRESH,
     * the conglomerateNumber will be 0. That's ok. During REFRESH,
     * we don't need to lock the conglomerate.
     */
    if ( conglomerateNumber != 0 ) { lockTableForDDL(tc, conglomerateNumber, true); }

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

    /* Get the table descriptor. */
    td = dd.getTableDescriptor(tableId);

    if (td == null)
    {
      throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
    }

    /* Get an exclusive table lock on the table. */
    long heapId = td.getHeapConglomerateId();
    lockTableForDDL(tc, heapId, true);

    /* Drop the triggers */
    GenericDescriptorList tdl = dd.getTriggerDescriptors(td);
    Enumeration descs = tdl.elements();
    while (descs.hasMoreElements())
    {
      TriggerDescriptor trd = (TriggerDescriptor) descs.nextElement();
            trd.drop(lcc);
    }

    /* Drop all defaults */
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    int           cdlSize = cdl.size();
   
    for (int index = 0; index < cdlSize; index++)
    {
      ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);

      // If column has a default we drop the default and
      // any dependencies
      if (cd.getDefaultInfo() != null)
      {
        DefaultDescriptor defaultDesc = cd.getDefaultDescriptor(dd);
        dm.clearDependencies(lcc, defaultDesc);
      }
    }

    /* Drop the columns */
    dd.dropAllColumnDescriptors(tableId, tc);

    /* Drop all table and column permission descriptors */
    dd.dropAllTableAndColPermDescriptors(tableId, tc);

    /* Drop the constraints */
    dropAllConstraintDescriptors(td, activation);

    /*
    ** Drop all the conglomerates.  Drop the heap last, because the
    ** store needs it for locking the indexes when they are dropped.
    */
    cds = td.getConglomerateDescriptors();

    long[] dropped = new long[cds.length - 1];
    int numDropped = 0;
    for (int index = 0; index < cds.length; index++)
    {
      ConglomerateDescriptor cd = cds[index];

      /* if it's for an index, since similar indexes share one
       * conglomerate, we only drop the conglomerate once
       */
      if (cd.getConglomerateNumber() != heapId)
      {
        long thisConglom = cd.getConglomerateNumber();

        int i;
        for (i = 0; i < numDropped; i++)
        {
          if (dropped[i] == thisConglom)
            break;
        }
        if (i == numDropped// not dropped
        {
          dropped[numDropped++] = thisConglom;
          tc.dropConglomerate(thisConglom);
          dd.dropStatisticsDescriptors(td.getUUID(), cd.getUUID(), tc);
        }
      }
    }

    /* 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.
     * We check for invalidation before we drop the table descriptor
     * since the table descriptor may be looked up as part of
     * decoding tuples in SYSDEPENDS.
     */

    dm.invalidateFor(td, DependencyManager.DROP_TABLE, lcc);

    /* Drop the table */
    dd.dropTableDescriptor(td, sd, tc);

    /* Drop the conglomerate descriptors */
 
View Full Code Here

    ConstraintDescriptorList       cdl;
    ConstraintDescriptor         fkcd;
    ConstraintDescriptorList       fkcdl;
    LanguageConnectionContext      lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();

    cdl = dd.getConstraintDescriptors(td);
   
    /*
    ** First go, don't drop unique or primary keys.
    ** This will ensure that self-referential constraints
    ** will work ok, even if not cascading.
     */
    /* The current element will be deleted underneath
     * the loop, so we only increment the counter when
     * skipping an element. (HACK!)
     */
    for(int index = 0; index < cdl.size(); )
    {
      cd = cdl.elementAt(index);
      if (cd instanceof ReferencedKeyConstraintDescriptor)
      {
        index++;
        continue;
      }

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

    /*
     ** Referenced keys (unique or pk) constraints only
    */
    /* The current element will be deleted underneath
     * the loop. (HACK!)
     */
    while (cdl.size() > 0)
    {
      cd = cdl.elementAt(0);
      if (SanityManager.DEBUG)
      {
        if (!(cd instanceof ReferencedKeyConstraintDescriptor))
        {
          SanityManager.THROWASSERT("Constraint descriptor not an instance of " +
          "ReferencedKeyConstraintDescriptor as expected.  Is a "+ cd.getClass().getName());
        }
      }

      /*
      ** Drop the referenced constraint (after we got
      ** the primary keys) now.  Do this prior to
      ** droping the referenced keys to avoid performing
      ** a lot of extra work updating the referencedcount
      ** field of sys.sysconstraints.
      **
      ** Pass in false to dropConstraintsAndIndex so it
      ** doesn't clear dependencies, we'll do that ourselves.
      */
      cd.drop(lcc, false);

      /*
      ** If we are going to cascade, get all the
      ** referencing foreign keys and zap them first.
      */
      if (cascade)
      {
        /*
        ** Go to the system tables to get the foreign keys
        ** to be safe
        */

        fkcdl = dd.getForeignKeys(cd.getUUID());

        /*
        ** For each FK that references this key, drop
        ** it.
        */
        for(int inner = 0; inner < fkcdl.size(); inner++)
        {
          fkcd = (ConstraintDescriptor) fkcdl.elementAt(inner);
          dm.invalidateFor(fkcd, DependencyManager.DROP_CONSTRAINT, lcc);
          fkcd.drop(lcc, true);
          activation.addWarning(
            StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED,
               fkcd.getConstraintName(),
              fkcd.getTableDescriptor().getName()));
        }
      }

      /*
      ** Now that we got rid of the fks (if we were cascading), it is
      ** ok to do an invalidate for.
      */
      dm.invalidateFor(cd, DependencyManager.DROP_CONSTRAINT, lcc);
      dm.clearDependencies(lcc, cd);
    }
  }
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

      return;
    }

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

    cf = lcc.getLanguageConnectionFactory().getClassFactory();

    /* Remember whether or not we are doing a create table */
    forCreateTable = activation.getForCreateTable();

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

    /* Table gets locked in AlterTableConstantAction */

    /*
    ** 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.
    */

    SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true);
   
    /* Try to get the TableDescriptor from
     * the Activation. We will go to the
     * DD if not there. (It should always be
     * there except when in a target.)
     */
    td = activation.getDDLTableDescriptor();

    if (td == null)
    {
      /* tableId will be non-null if adding a
       * constraint to an existing table.
       */
      if (tableId != null)
      {
        td = dd.getTableDescriptor(tableId);
      }
      else
      {
        td = dd.getTableDescriptor(tableName, sd);
      }

      if (td == null)
      {
        throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
      }
      activation.setDDLTableDescriptor(td);
    }

    /* Generate the UUID for the backing index.  This will become the
     * constraint's name, if no name was specified.
     */
    UUIDFactory uuidFactory = dd.getUUIDFactory();
       
    /* Create the index, if there's one for this constraint */
    if (indexAction != null)
    {
      if ( indexAction.getIndexName() == null )
      {
        /* Set the index name */
        backingIndexName =  uuidFactory.createUUID().toString();
        indexAction.setIndexName(backingIndexName);
      }
      else { backingIndexName = indexAction.getIndexName(); }


      /* Create the index */
      indexAction.executeConstantAction(activation);

      /* Get the conglomerate descriptor for the backing index */
      conglomDescs = td.getConglomerateDescriptors();

      for (int index = 0; index < conglomDescs.length; index++)
      {
        conglomDesc = conglomDescs[index];

        /* Check for conglomerate being an index first, since
         * name is null for heap.
         */
        if (conglomDesc.isIndex() &&
          backingIndexName.equals(conglomDesc.getConglomerateName()))
        {
          break;
        }
      }

      if (SanityManager.DEBUG)
      {
        SanityManager.ASSERT(conglomDesc != null,
          "conglomDesc is expected to be non-null after search for backing index");
        SanityManager.ASSERT(conglomDesc.isIndex(),
          "conglomDesc is expected to be indexable after search for backing index");
        SanityManager.ASSERT(conglomDesc.getConglomerateName().equals(backingIndexName),
         "conglomDesc name expected to be the same as backing index name after search for backing index");
      }

      indexId = conglomDesc.getUUID();
    }

    UUID constraintId = uuidFactory.createUUID();

    /* Now, lets create the constraint descriptor */
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    switch (constraintType)
    {
      case DataDictionary.PRIMARYKEY_CONSTRAINT:
        conDesc = ddg.newPrimaryKeyConstraintDescriptor(
                td, constraintName,
                false, //deferable,
                false, //initiallyDeferred,
                genColumnPositions(td, false), //int[],
                constraintId,
                indexId,
                sd,
                enabled,
                0        // referenceCount
                );
        dd.addConstraintDescriptor(conDesc, tc);
        break;

      case DataDictionary.UNIQUE_CONSTRAINT:
        conDesc = ddg.newUniqueConstraintDescriptor(
                td, constraintName,
                false, //deferable,
                false, //initiallyDeferred,
                genColumnPositions(td, false), //int[],
                constraintId,
                indexId,
                sd,
                enabled,
                0        // referenceCount
                );
        dd.addConstraintDescriptor(conDesc, tc);
        break;

      case DataDictionary.CHECK_CONSTRAINT:
        conDesc = ddg.newCheckConstraintDescriptor(
                td, constraintName,
                false, //deferable,
                false, //initiallyDeferred,
                constraintId,
                constraintText,
                new ReferencedColumnsDescriptorImpl(genColumnPositions(td, false)), //int[],
                sd,
                enabled
                );
        dd.addConstraintDescriptor(conDesc, tc);
        break;

      case DataDictionary.FOREIGNKEY_CONSTRAINT:
        ReferencedKeyConstraintDescriptor referencedConstraint = DDUtils.locateReferencedConstraint
          ( dd, td, constraintName, columnNames, otherConstraintInfo );
        DDUtils.validateReferentialActions(dd, td, constraintName, otherConstraintInfo,columnNames);
       
        conDesc = ddg.newForeignKeyConstraintDescriptor(
                td, constraintName,
                false, //deferable,
                false, //initiallyDeferred,
                genColumnPositions(td, false), //int[],
                constraintId,
                indexId,
                sd,
                referencedConstraint,
                enabled,
                otherConstraintInfo.getReferentialActionDeleteRule(),
                otherConstraintInfo.getReferentialActionUpdateRule()
                );

        // try to create the constraint first, because it
        // is expensive to do the bulk check, find obvious
        // errors first
        dd.addConstraintDescriptor(conDesc, tc);

        /* No need to do check if we're creating a
         * table.
         */
        if ( (! forCreateTable) &&
           dd.activeConstraint( conDesc ) )
        {
          validateFKConstraint(tc,
                     dd,
                     (ForeignKeyConstraintDescriptor)conDesc,
                     referencedConstraint,
                     ((CreateIndexConstantAction)indexAction).getIndexTemplateRow());
        }
       
        /* Create stored dependency on the referenced constraint */
        dm.addDependency(conDesc, referencedConstraint, lcc.getContextManager());
        //store constraint's dependency on REFERENCES privileges in the dependeny system
        storeConstraintDependenciesOnPrivileges(activation, conDesc, referencedConstraint.getTableId());       
        break;

      default:
        if (SanityManager.DEBUG)
        {
          SanityManager.THROWASSERT("contraintType (" + constraintType +
            ") has unexpected value");
        }
        break;
    }

    /* Create stored dependencies for each provider */
    if (providerInfo != null)
    {
      for (int ix = 0; ix < providerInfo.length; ix++)
      {
        Provider provider = null;
 
        /* We should always be able to find the Provider */
          provider = (Provider) providerInfo[ix].
                      getDependableFinder().
                        getDependable(dd,
                          providerInfo[ix].getObjectId());

        dm.addDependency(conDesc, provider, lcc.getContextManager());
      }
    }

    /* Finally, invalidate off of the table descriptor(s)
     * to ensure that any dependent statements get
     * re-compiled.
     */
    if (! forCreateTable)
    {
      dm.invalidateFor(td, DependencyManager.CREATE_CONSTRAINT, lcc);
    }
    if (constraintType == DataDictionary.FOREIGNKEY_CONSTRAINT)
    {
      if (SanityManager.DEBUG)
      {
        SanityManager.ASSERT(conDesc != null,
          "conDesc expected to be non-null");

        if (! (conDesc instanceof ForeignKeyConstraintDescriptor))
        {
          SanityManager.THROWASSERT(
            "conDesc expected to be instance of ForeignKeyConstraintDescriptor, not " +
            conDesc.getClass().getName());
        }
      }
      dm.invalidateFor(
        ((ForeignKeyConstraintDescriptor)conDesc).
          getReferencedConstraint().
            getTableDescriptor(),
        DependencyManager.CREATE_CONSTRAINT, lcc);
    }
View Full Code Here

                                      TableDescriptor td,
                                      boolean asBackgroundTask)
            throws StandardException {
        // Invalidate compiled statements accessing the table.
        DataDictionary dd = lcc.getDataDictionary();
        DependencyManager dm = dd.getDependencyManager();
        boolean inWrite = false;
        int retries = 0;
        while (true) {
            try {
                if (!inWrite) {
                    dd.startWriting(lcc);
                    inWrite = true;
                }
                dm.invalidateFor(
                        td, DependencyManager.UPDATE_STATISTICS, lcc);
                trace(1, "invalidation completed");
                break;
            } catch (StandardException se) {
                // Special handling when running as background task.
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

     */
    public void drop(LanguageConnectionContext lcc) throws StandardException {
       
        DataDictionary dd = getDataDictionary();
        TransactionController tc = lcc.getTransactionExecute();
        DependencyManager dm = dd.getDependencyManager();
       
       
        /* 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 (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(this, invalidationType, lcc);
       
        if (getAliasType() == AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
        {
            SchemaDescriptor sd = dd.getSchemaDescriptor(schemaID, tc);
           
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.