Package org.apache.derby.iapi.sql.dictionary

Examples of org.apache.derby.iapi.sql.dictionary.DataDictionary


    ColumnDescriptor columnDescriptor = null;
    int columnPosition = 0;
    ConstraintDescriptorList constraintDescriptorList;
    ConstraintDescriptor constraintDescriptor;
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();

    /* get the column descriptor for column to be renamed and
     * using it's position in the table, set the referenced
     * column map of the table indicating which column is being
     * renamed. Dependency Manager uses this to find out the
     * dependents on the column.
     */
    columnDescriptor = td.getColumnDescriptor(oldObjectName);
    columnPosition = columnDescriptor.getPosition();
    FormatableBitSet toRename = new FormatableBitSet(td.getColumnDescriptorList().size() + 1);
    toRename.set(columnPosition);
    td.setReferencedColumnMap(toRename);
   
    dm.invalidateFor(td, DependencyManager.RENAME, lcc);

    //look for foreign key dependency on the column.
    constraintDescriptorList = dd.getConstraintDescriptors(td);
    for(int index=0; index<constraintDescriptorList.size(); index++)
    {
      constraintDescriptor = constraintDescriptorList.elementAt(index);
      int[] referencedColumns = constraintDescriptor.getReferencedColumns();
      int numRefCols = referencedColumns.length;
      for (int j = 0; j < numRefCols; j++)
      {
        if ((referencedColumns[j] == columnPosition) &&
          (constraintDescriptor instanceof ReferencedKeyConstraintDescriptor))
          dm.invalidateFor(constraintDescriptor, DependencyManager.RENAME, lcc);
      }
    }

    // Drop the column
    dd.dropColumnDescriptor(td.getUUID(), oldObjectName, tc);
    columnDescriptor.setColumnName(newObjectName);
    dd.addDescriptor(columnDescriptor, td,
             DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);

    //Need to do following to reload the cache so that table
    //descriptor now has new column name
    td = dd.getTableDescriptor(td.getObjectID());
  }
View Full Code Here


  (
           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)
      throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND_DURING_EXECUTION,
      oldObjectName);

    /* Drop the index descriptor */
    dd.dropConglomerateDescriptor(conglomerateDescriptor, tc);
    // Change the index name of the index descriptor
    conglomerateDescriptor.setConglomerateName(newObjectName);
    // add the index descriptor with new name
    dd.addDescriptor(conglomerateDescriptor, sd,
             DataDictionary.SYSCONGLOMERATES_CATALOG_NUM, false, tc);
  }
View Full Code Here

   */
  public void  executeConstantAction( Activation activation )
            throws StandardException
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();

    /*
    ** 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 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);
View Full Code Here

  {
    TableDescriptor td;
    ViewDescriptor vd;

    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();

    /*
    ** 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.  We're responsible for raising
     * the error if it isn't found
     */
    td = dd.getTableDescriptor(tableName, sd);

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

    /* Verify that TableDescriptor represents a view */
    if (td.getTableType() != TableDescriptor.VIEW_TYPE)
    {
      throw StandardException.newException(SQLState.LANG_DROP_VIEW_ON_NON_VIEW, fullTableName);
    }

    vd = dd.getViewDescriptor(td);

    vd.drop(lcc, sd, td);
  }
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

                  boolean grant,
                  List grantees)
    throws StandardException
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    String currentUser = lcc.getAuthorizationId();
    TransactionController tc = lcc.getTransactionExecute();
    SchemaDescriptor sd = td.getSchemaDescriptor();
   
    // Check that the current user has permission to grant the privileges.
    checkOwnership( currentUser, td, sd, dd, lcc, grant);
   
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();

    TablePermsDescriptor tablePermsDesc =
      ddg.newTablePermsDescriptor( td,
                     getPermString( SELECT_ACTION, false),
                     getPermString( DELETE_ACTION, false),
                     getPermString( INSERT_ACTION, false),
                     getPermString( UPDATE_ACTION, false),
                     getPermString( REFERENCES_ACTION, false),
                     getPermString( TRIGGER_ACTION, false),
                     currentUser);
     
    ColPermsDescriptor[] colPermsDescs = new ColPermsDescriptor[ columnBitSets.length];
    for( int i = 0; i < columnBitSets.length; i++)
    {
      if( columnBitSets[i] != null ||
        // If it is a revoke and no column list is specified then revoke all column permissions.
        // A null column bitSet in a ColPermsDescriptor indicates that all the column permissions
        // should be removed.
        (!grant) && hasColumnPermissions(i) && actionAllowed[i]
        )
      {
        colPermsDescs[i] = ddg.newColPermsDescriptor( td,
                                getActionString(i, false),
                                columnBitSets[i],
                                currentUser);
      }
    }


    dd.startWriting(lcc);
    // Add or remove the privileges to/from the SYS.SYSTABLEPERMS and SYS.SYSCOLPERMS tables
    for( Iterator itr = grantees.iterator(); itr.hasNext();)
    {
      // Keep track to see if any privileges are revoked by a revoke
      // statement. If a privilege is not revoked, we need to raise a
      // warning. For table privileges, we do not check if privilege for
      // a specific action has been revoked or not. Also, we do not check
      // privileges for specific columns. If at least one privilege has
      // been revoked, we do not raise a warning. This has to be refined
      // further to check for specific actions/columns and raise warning
      // if any privilege has not been revoked.
      boolean privileges_revoked = false;
           
      String grantee = (String) itr.next();
      if( tablePermsDesc != null)
      {
        if (dd.addRemovePermissionsDescriptor( grant, tablePermsDesc, grantee, tc))
        {
          privileges_revoked = true;
          dd.getDependencyManager().invalidateFor
            (tablePermsDesc,
             DependencyManager.REVOKE_PRIVILEGE, lcc);

          // When revoking a privilege from a Table we need to
          // invalidate all GPSs refering to it. But GPSs aren't
          // Dependents of TablePermsDescr, but of the
          // TableDescriptor itself, so we must send
          // INTERNAL_RECOMPILE_REQUEST to the TableDescriptor's
          // Dependents.
          dd.getDependencyManager().invalidateFor
            (td, DependencyManager.INTERNAL_RECOMPILE_REQUEST, lcc);
        }
      }
      for( int i = 0; i < columnBitSets.length; i++)
      {
        if( colPermsDescs[i] != null)
        {
          if (dd.addRemovePermissionsDescriptor( grant, colPermsDescs[i], grantee, tc))
          {
            privileges_revoked = true;
            dd.getDependencyManager().invalidateFor(colPermsDescs[i], DependencyManager.REVOKE_PRIVILEGE, lcc);
          }
        }
      }
     
      addWarningIfPrivilegeNotRevoked(activation, grant, privileges_revoked, grantee);
View Full Code Here

    TableDescriptor td;
    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 */
    dd.dropAllConglomerateDescriptors(td, tc);

    /* Drop the store element at last, to prevent dangling reference
     * for open cursor, beetle 4393.
     */
    tc.dropConglomerate(heapId);
 
View Full Code Here

    ConstraintDescriptor        cd;
    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.
        */
 
View Full Code Here

    LanguageConnectionContext lcc       = ConnectionUtil.getCurrentLCC();
    TransactionController     tc        = lcc.getTransactionExecute();

    try
        {
            DataDictionary data_dictionary = lcc.getDataDictionary();
            SchemaDescriptor sd =
                data_dictionary.getSchemaDescriptor(schema, tc, true);
            TableDescriptor  td =
                data_dictionary.getTableDescriptor(tablename, sd, tc);

            if (td != null && td.getTableType() == TableDescriptor.VTI_TYPE)
            {
                return;
            }
View Full Code Here

        ** Tell the data dictionary that we are about to do
        ** a bunch of "get" operations that must be consistent with
        ** each other.
        */
       
        DataDictionary dataDictionary = lcc.getDataDictionary();

        int ddMode = dataDictionary == null ? 0 : dataDictionary.startReading(lcc);

        try
        {
          // start a nested transaction -- all locks acquired by bind
          // and optimize will be released when we end the nested
          // transaction.
          lcc.beginNestedTransaction(true);

          qt.bindStatement();
          bindTime = getCurrentTimeMillis(lcc);

                    // Call user-written tree-printer if it exists
                    walkAST( lcc, qt, ASTVisitor.AFTER_BIND);

          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON("DumpBindTree"))
            {
              SanityManager.GET_DEBUG_STREAM().print(
                "\n\n============BIND===========\n\n");
              qt.treePrint();
              lcc.getPrintedObjectsMap().clear();
            }

            if (SanityManager.DEBUG_ON("StopAfterBinding")) {
              throw StandardException.newException(SQLState.LANG_STOP_AFTER_BINDING);
            }
          }

          //Derby424 - In order to avoid caching select statements referencing
          // any SESSION schema objects (including statements referencing views
          // in SESSION schema), we need to do the SESSION schema object check
          // here. 
          //a specific eg for statement referencing a view in SESSION schema
          //CREATE TABLE t28A (c28 int)
          //INSERT INTO t28A VALUES (280),(281)
          //CREATE VIEW SESSION.t28v1 as select * from t28A
          //SELECT * from SESSION.t28v1 should show contents of view and we
          // should not cache this statement because a user can later define
          // a global temporary table with the same name as the view name.
          //Following demonstrates that
          //DECLARE GLOBAL TEMPORARY TABLE SESSION.t28v1(c21 int, c22 int) not
          //     logged
          //INSERT INTO SESSION.t28v1 VALUES (280,1),(281,2)
          //SELECT * from SESSION.t28v1 should show contents of global temporary
          //table and not the view.  Since this select statement was not cached
          // earlier, it will be compiled again and will go to global temporary
          // table to fetch data. This plan will not be cached either because
          // select statement is using SESSION schema object.
          //
          //Following if statement makes sure that if the statement is
          // referencing SESSION schema objects, then we do not want to cache it.
          // We will remove the entry that was made into the cache for
          //this statement at the beginning of the compile phase.
          //The reason we do this check here rather than later in the compile
          // phase is because for a view, later on, we loose the information that
          // it was referencing SESSION schema because the reference
          //view gets replaced with the actual view definition. Right after
          // binding, we still have the information on the view and that is why
          // we do the check here.
          if (preparedStmt.referencesSessionSchema(qt)) {
            if (foundInCache)
              ((GenericLanguageConnectionContext)lcc).removeStatement(this);
          }
         
          qt.optimizeStatement();

          optimizeTime = getCurrentTimeMillis(lcc);

                    // Call user-written tree-printer if it exists
                    walkAST( lcc, qt, ASTVisitor.AFTER_OPTIMIZE);

          // Statement logging if lcc.getLogStatementText() is true
          if (istream != null)
          {
            String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
            istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                          xactId +
                          "), " +
                          LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                          "), " +
                          LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                          "), " +
                          LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                          "), End compiling prepared statement: " +
                          getSource() +
                          " :End prepared statement");
          }
        }

        catch (StandardException se)
        {
          lcc.commitNestedTransaction();

          // Statement logging if lcc.getLogStatementText() is true
          if (istream != null)
          {
            String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
            istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                          xactId +
                          "), " +
                          LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                          "), " +
                          LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                          "), " +
                          LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                          "), Error compiling prepared statement: " +
                          getSource() +
                          " :End prepared statement");
          }
          throw se;
        }

        finally
        {
          /* Tell the data dictionary that we are done reading */
          if (dataDictionary != null)
          dataDictionary.doneReading(ddMode, lcc);
        }

        /* we need to move the commit of nested sub-transaction
         * after we mark PS valid, during compilation, we might need
         * to get some lock to synchronize with another thread's DDL
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.dictionary.DataDictionary

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.