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

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


   */
  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) {
        e.setNestedException(topLevelStandardException);
        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

    }

    /* Clean up any dependencies */
    if (dependencies != null)
    {
      DependencyManager dmgr = lcc.getDataDictionary().getDependencyManager();

      for (Iterator iterator = dependencies.iterator(); iterator.hasNext(); )
      {
        Dependency dy = (Dependency) iterator.next();
        dmgr.clearInMemoryDependency(dy);
      }

      dependencies = null;
    }

View Full Code Here

    SPSDescriptor        whenspsd = null;
    SPSDescriptor        actionspsd;

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

    /*
    ** Indicate that we are about to modify the data dictionary.
    **
    ** We tell the data dictionary we're done writing at the end of
    ** the transaction.
    */
    dd.startWriting(lcc);

    SchemaDescriptor triggerSd = getSchemaDescriptorForCreate(dd, activation, triggerSchemaName);

    if (spsCompSchemaId == null) {
      SchemaDescriptor def = lcc.getDefaultSchema();
      if (def.getUUID() == null) {
        // Descriptor for default schema is stale,
        // look it up in the dictionary
        def = dd.getSchemaDescriptor(def.getDescriptorName(), tc,
                       false);
      }
      spsCompSchemaId = def.getUUID();
    }
    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(spsCompSchemaId != null,
                 "spsCompSchemaId is null");
    }

    String tabName;
    if (triggerTable != null)
    {
      triggerTableId = triggerTable.getUUID();
      tabName = triggerTable.getName();
    }
    else
      tabName = "with UUID " + triggerTableId;

    /* We need to get table descriptor again.  We simply can't trust the
     * one we got at compile time, the lock on system table was released
     * when compile was done, and the table might well have been dropped.
     */
    triggerTable = dd.getTableDescriptor(triggerTableId);
    if (triggerTable == null)
    {
      throw StandardException.newException(
                SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION,
                tabName);
    }
    /* Lock the table for DDL.  Otherwise during our execution, the table
     * might be changed, even dropped.  Beetle 4269
     */
    lockTableForDDL(tc, triggerTable.getHeapConglomerateId(), true);
    /* get triggerTable again for correctness, in case it's changed before
     * the lock is aquired
     */
    triggerTable = dd.getTableDescriptor(triggerTableId);
    if (triggerTable == null)
    {
      throw StandardException.newException(
                SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION,
                tabName);
    }

    /*
    ** Send an invalidate on the table from which
    ** the triggering event emanates.  This it
    ** to make sure that DML statements on this table
    ** will be recompiled.  Do this before we create
    ** our trigger spses lest we invalidate them just
    ** after creating them.
    */
    dm.invalidateFor(triggerTable, DependencyManager.CREATE_TRIGGER, lcc);

    /*
    ** Lets get our trigger id up front, we'll use it when
     ** we create our spses.
    */
    UUID tmpTriggerId = dd.getUUIDFactory().createUUID();

    actionSPSId = (actionSPSId == null) ?
      dd.getUUIDFactory().createUUID() : actionSPSId;
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();

    /*
    ** Create the trigger descriptor first so the trigger action
    ** compilation can pick up the relevant trigger especially in
    ** the case of self triggering.
    */
    TriggerDescriptor triggerd =
        ddg.newTriggerDescriptor(
                  triggerSd,
                  tmpTriggerId,
                  triggerName,
                  eventMask,
                  isBefore,
                  isRow,
                  isEnabled,
                  triggerTable,
                  whenspsd == null ? null : whenspsd.getUUID(),
                  actionSPSId,
                  creationTimestamp == null ? new Timestamp(System.currentTimeMillis()) : creationTimestamp,
                  referencedCols,
                  originalActionText,
                  referencingOld,
                  referencingNew,
                  oldReferencingName,
                  newReferencingName);


    dd.addDescriptor(triggerd, triggerSd,
                DataDictionary.SYSTRIGGERS_CATALOG_NUM, false,
                tc);


    /* 
    ** If we have a WHEN action we create it now.
    */
    if (whenText != null)
    {
      whenspsd = createSPS(lcc, ddg, dd, tc, tmpTriggerId, triggerSd,
            whenSPSId, spsCompSchemaId, whenText, true, triggerTable);
    }

    /*
    ** Create the trigger action
    */
    actionspsd = createSPS(lcc, ddg, dd, tc, tmpTriggerId, triggerSd,
            actionSPSId, spsCompSchemaId, actionText, false, triggerTable);
   
    /*
    ** Make underlying spses dependent on the trigger.
    */
    if (whenspsd != null)
    {
      dm.addDependency(triggerd, whenspsd, lcc.getContextManager());
    }
    dm.addDependency(triggerd, actionspsd, lcc.getContextManager());
    dm.addDependency(triggerd, triggerTable, lcc.getContextManager());
    dm.addDependency(actionspsd, triggerTable, lcc.getContextManager());
    //store trigger's dependency on various privileges in the dependeny system
    storeViewTriggerDependenciesOnPrivileges(activation, triggerd);   
  }
View Full Code Here

    ColumnDescriptor      columnDescriptor;
    ViewDescriptor        vd;

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

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

    SchemaDescriptor sd = DDLConstantAction.getSchemaDescriptorForCreate(dd, activation, schemaName);

    /* Create a new table descriptor.
     * (Pass in row locking, even though meaningless for views.)
     */
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    td = ddg.newTableDescriptor(tableName,
                  sd,
                  tableType,
                  TableDescriptor.ROW_LOCK_GRANULARITY);

    dd.addDescriptor(td, sd, DataDictionary.SYSTABLES_CATALOG_NUM, false, tc);
    toid = td.getUUID();

    // for each column, stuff system.column
    ColumnDescriptor[] cdlArray = new ColumnDescriptor[columnInfo.length];
    int index = 1;
    for (int ix = 0; ix < columnInfo.length; ix++)
    {
      columnDescriptor = new ColumnDescriptor(
                           columnInfo[ix].name,
                   index++,
                   columnInfo[ix].dataType,
                   columnInfo[ix].defaultValue,
                   columnInfo[ix].defaultInfo,
                   td,
                   (UUID) null,
                   columnInfo[ix].autoincStart,
                   columnInfo[ix].autoincInc
                 );
      cdlArray[ix] = columnDescriptor;
    }

    dd.addDescriptorArray(cdlArray, td,
                DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);

    // add columns to the column descriptor list.
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    for (int i = 0; i < cdlArray.length; i++)
      cdl.add(cdlArray[i]);

    /* Get and add a view descriptor */
    vd = ddg.newViewDescriptor(toid, tableName, viewText,
                  checkOption,
                  (compSchemaId == null) ?
                    lcc.getDefaultSchema().getUUID() :
                    compSchemaId);

    for (int ix = 0; ix < providerInfo.length; ix++)
    {
      /* We should always be able to find the Provider */
      try
      {
        Provider provider = (Provider) providerInfo[ix].
                    getDependableFinder().
                      getDependable(
                        providerInfo[ix].getObjectId());
        if (provider == null//see beetle 4444
        {
          throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "OBJECT", providerInfo[ix].getObjectId());
        }
        dm.addDependency(vd, provider, lcc.getContextManager());
      }
      catch(java.sql.SQLException te)
      {
        // we should allow timeout to be thrown
        throw StandardException.plainWrapException(te);
View Full Code Here

      compilingStatement = true;
    }

    try {

      DependencyManager dm = lcc.getDataDictionary().getDependencyManager();

      if (!alreadyInvalid)
      {
        dm.invalidateFor(this, action, lcc);
      }

      /* Clear out the old dependencies on this statement as we
       * will build the new set during the reprepare in makeValid().
       */
      dm.clearDependencies(lcc, this);

      /*
      ** If we are invalidating an EXECUTE STATEMENT because of a stale
      ** plan, we also need to invalidate the stored prepared statement.
      */
 
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();
      DropTriggerConstantAction.dropTriggerDescriptor(lcc, dm, dd, tc, trd, activation)
    }

    /* 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);
      DropConstraintConstantAction.dropConstraintAndIndex(dm, td, dd, cd,
            tc, 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.
      */
      DropConstraintConstantAction.dropConstraintAndIndex(dm, td, dd, cd,
            tc, 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);
          DropConstraintConstantAction.dropConstraintAndIndex(
              dm, fkcd.getTableDescriptor(), dd, fkcd,
              tc, 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

    TableDescriptor td;
    ViewDescriptor vd;

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

    /*
    ** Inform the data dictionary that we are about to write to it.
    ** There are several calls to data dictionary "get" methods here
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

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.