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

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


   */
  public void prepareToInvalidate(Provider p, int action,
          LanguageConnectionContext lcc)
    throws StandardException
  {
    DependencyManager dm = getDataDictionary().getDependencyManager();

    switch (action)
    {
      /*
      ** Currently, the only thing we are dependent
      ** on is an alias descriptor for an ANSI UDT.
      */
        default:

        throw StandardException.newException(SQLState.LANG_PROVIDER_HAS_DEPENDENT_TABLE,
                  dm.getActionString(action),
                  p.getObjectName(),
                  getQualifiedName());
    }
  }
View Full Code Here


    ** We should never get here, we should have barfed on
    ** prepareToInvalidate().
    */
    if (SanityManager.DEBUG)
    {
      DependencyManager dm;
 
      dm = getDataDictionary().getDependencyManager();

      SanityManager.THROWASSERT("makeInvalid("+
        dm.getActionString(action)+
        ") not expected to get called");
    }
  }
View Full Code Here

    lcc.autoincrementFlushCache(constants.targetUUID);

    // invalidate any prepared statements that
    // depended on this table (including this one)
    DependencyManager dm = dd.getDependencyManager();

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

   
    // Update all indexes
    if (constants.irgs.length > 0)
    {
View Full Code Here

      Activation activation, Dependent dependent, UUID refTableUUID)
  throws StandardException
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
   
    //If the Database Owner is creating this constraint, then no need to
    //collect any privilege dependencies because the Database Owner can  
    //access any objects without any restrictions
    if (!(lcc.getAuthorizationId().equals(dd.getAuthorizationDatabaseOwner())))
    {
      PermissionsDescriptor permDesc;
      //Now, it is time to add into dependency system, constraint's
      //dependency on REFERENCES privilege. If the REFERENCES privilege is
      //revoked from the constraint owner, the constraint will get
      //dropped automatically.
      List requiredPermissionsList = activation.getPreparedStatement().getRequiredPermissionsList();
      if (requiredPermissionsList != null && ! requiredPermissionsList.isEmpty())
      {
        for(Iterator iter = requiredPermissionsList.iterator();iter.hasNext();)
        {
          StatementPermission statPerm = (StatementPermission) iter.next();
          //First check if we are dealing with a Table or
          //Column level privilege. All the other privileges
          //are not required for a foreign key constraint.
          if (statPerm instanceof StatementTablePermission)
          {//It is a table/column level privilege
            StatementTablePermission statementTablePermission =
              (StatementTablePermission) statPerm;
            //Check if we are dealing with REFERENCES privilege.
            //If not, move on to the next privilege in the
            //required privileges list
            if (statementTablePermission.getPrivType() != Authorizer.REFERENCES_PRIV)
              continue;
            //Next check is this REFERENCES privilege is
            //on the same table as referenced by the foreign
            //key constraint? If not, move on to the next
            //privilege in the required privileges list
            if (!statementTablePermission.getTableUUID().equals(refTableUUID))
              continue;
          } else if (statPerm instanceof StatementSchemaPermission
              || statPerm instanceof StatementRoutinePermission)
            continue;

          //We know that we are working with a REFERENCES
          //privilege. Find all the PermissionDescriptors for
          //this privilege and make constraint depend on it
          //through dependency manager.
          //The REFERENCES privilege could be defined at the
          //table level or it could be defined at individual
          //column levels. In addition, individual column
          //REFERENCES privilege could be available at the
          //user level or PUBLIC level.
          permDesc = statPerm.getPermissionDescriptor(lcc.getAuthorizationId(), dd);       
          if (permDesc == null)
          {
            //No REFERENCES privilege exists for given
            //authorizer at table or column level.
            //REFERENCES privilege has to exist at at PUBLIC level
            permDesc = statPerm.getPermissionDescriptor(Authorizer.PUBLIC_AUTHORIZATION_ID, dd);
            if (!(permDesc.checkOwner(lcc.getAuthorizationId())))
              dm.addDependency(dependent, permDesc, lcc.getContextManager());
          } else
            //if the object on which permission is required is owned by the
            //same user as the current user, then no need to keep that
            //object's privilege dependency in the dependency system
          if (!(permDesc.checkOwner(lcc.getAuthorizationId())))
          {
            dm.addDependency(dependent, permDesc, lcc.getContextManager());
            if (permDesc instanceof ColPermsDescriptor)
            {
              //The if statement above means we found a
              //REFERENCES privilege at column level for
              //the given authorizer. If this privilege
              //doesn't cover all the column , then there
              //has to exisit REFERENCES for the remaining
              //columns at PUBLIC level. Get that permission
              //descriptor and save it in dependency system
              StatementColumnPermission statementColumnPermission = (StatementColumnPermission) statPerm;
              permDesc = statementColumnPermission.getPUBLIClevelColPermsDescriptor(lcc.getAuthorizationId(), dd);
              //Following if checks if some column level privileges
              //exist only at public level. If so, then the public
              //level column privilege dependency is added
              //into the dependency system
              if (permDesc != null)
                dm.addDependency(dependent, permDesc, lcc.getContextManager());                                            
            }
          }
          //We have found the REFERENCES privilege for all the
          //columns in foreign key constraint and we don't
          //need to go through the rest of the privileges
View Full Code Here

      Activation activation, Dependent dependent)
  throws StandardException
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
   
    //If the Database Owner is creating this view/triiger, then no need to 
    //collect any privilege dependencies because the Database Owner can 
    //access any objects without any restrictions
    if (!(lcc.getAuthorizationId().equals(dd.getAuthorizationDatabaseOwner())))
    {
      PermissionsDescriptor permDesc;
      List requiredPermissionsList = activation.getPreparedStatement().getRequiredPermissionsList();
      if (requiredPermissionsList != null && ! requiredPermissionsList.isEmpty())
      {
        for(Iterator iter = requiredPermissionsList.iterator();iter.hasNext();)
        {
          StatementPermission statPerm = (StatementPermission) iter.next();
          //The schema ownership permission just needs to be checked
          //at object creation time, to see if the object creator has
          //permissions to create the object in the specified schema.
          //But we don't need to add schema permission to list of
          //permissions that the object is dependent on once it is
          //created.
          if (statPerm instanceof StatementSchemaPermission)
            continue;
          //See if we can find the required privilege for given authorizer?
          permDesc = statPerm.getPermissionDescriptor(lcc.getAuthorizationId(), dd);       
          if (permDesc == null)//privilege not found for given authorizer
          {
            //The if condition above means that required privilege does
            //not exist at the user level. The privilege has to exist at
            //PUBLIC level.
            permDesc = statPerm.getPermissionDescriptor(Authorizer.PUBLIC_AUTHORIZATION_ID, dd);
            //If the user accessing the object is the owner of that
            //object, then no privilege tracking is needed for the
            //owner.
            if (!(permDesc.checkOwner(lcc.getAuthorizationId())))
              dm.addDependency(dependent, permDesc, lcc.getContextManager());
            continue;
          }
          //if the object on which permission is required is owned by the
          //same user as the current user, then no need to keep that
          //object's privilege dependency in the dependency system
          if (!(permDesc.checkOwner(lcc.getAuthorizationId())))
          {
            dm.addDependency(dependent, permDesc, lcc.getContextManager());                          
            if (permDesc instanceof ColPermsDescriptor)
            {
              //For a given table, the table owner can give privileges
              //on some columns at individual user level and privileges
              //on some columns at PUBLIC level. Hence, when looking for
              //column level privileges, we need to look both at user
              //level as well as PUBLIC level(only if user level column
              //privileges do not cover all the columns accessed by this
              //object). We have finished adding dependency for user level
              //columns, now we are checking if some required column
              //level privileges are at PUBLIC level.
              //A specific eg of a view
              //user1
              //create table t11(c11 int, c12 int);
              //grant select(c11) on t1 to user2;
              //grant select(c12) on t1 to PUBLIC;
              //user2
              //create view v1 as select c11 from user1.t11 where c12=2;
              //For the view above, there are 2 column level privilege
              //depencies, one for column c11 which exists directly
              //for user2 and one for column c12 which exists at PUBLIC level.
              StatementColumnPermission statementColumnPermission = (StatementColumnPermission) statPerm;
              permDesc = statementColumnPermission.getPUBLIClevelColPermsDescriptor(lcc.getAuthorizationId(), dd);
              //Following if checks if some column level privileges
              //exist only at public level. If so, then the public
              //level column privilege dependency of view is added
              //into dependency system.
              if (permDesc != null)
                dm.addDependency(dependent, permDesc, lcc.getContextManager());                          
            }
          }
        }
      }
     
View Full Code Here

    UUID              indexId = null;
    String            indexUUIDString;

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

    td = dd.getTableDescriptor(tableId);

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

    /* 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 tdSd = td.getSchemaDescriptor();
    SchemaDescriptor constraintSd =
      constraintSchemaName == null ? tdSd : dd.getSchemaDescriptor(constraintSchemaName, tc, true);


    /* Get the constraint descriptor for the index, along
     * with an exclusive row lock on the row in sys.sysconstraints
     * in order to ensure that no one else compiles against the
     * index.
     */
    if (constraintName == null// this means "alter table drop primary key"
      conDesc = dd.getConstraintDescriptors(td).getPrimaryKey();
    else
      conDesc = dd.getConstraintDescriptorByName(td, constraintSd, constraintName, true);

    // Error if constraint doesn't exist
    if (conDesc == null)
    {
      String errorName = constraintName == null ? "PRIMARY KEY" :
                (constraintSd.getSchemaName() + "."+ constraintName);

      throw StandardException.newException(SQLState.LANG_DROP_NON_EXISTENT_CONSTRAINT,
            errorName,
            td.getQualifiedName());
    }
        switch( verifyType)
        {
        case DataDictionary.UNIQUE_CONSTRAINT:
            if( conDesc.getConstraintType() != verifyType)
                throw StandardException.newException(SQLState.LANG_DROP_CONSTRAINT_TYPE,
                                                     constraintName, "UNIQUE");
            break;

        case DataDictionary.CHECK_CONSTRAINT:
            if( conDesc.getConstraintType() != verifyType)
                throw StandardException.newException(SQLState.LANG_DROP_CONSTRAINT_TYPE,
                                                     constraintName, "CHECK");
            break;

        case DataDictionary.FOREIGNKEY_CONSTRAINT:
            if( conDesc.getConstraintType() != verifyType)
                throw StandardException.newException(SQLState.LANG_DROP_CONSTRAINT_TYPE,
                                                     constraintName, "FOREIGN KEY");
            break;
        }

    boolean cascadeOnRefKey = (cascade &&
            conDesc instanceof ReferencedKeyConstraintDescriptor);
    if (!cascadeOnRefKey)
    {
      dm.invalidateFor(conDesc, DependencyManager.DROP_CONSTRAINT, lcc);
    }

    /*
    ** If we had a primary/unique key and it is drop cascade, 
    ** drop all the referencing keys now.  We MUST do this AFTER
    ** dropping the referenced key because otherwise we would
    ** be repeatedly changing the reference count of the referenced
    ** key and generating unnecessary I/O.
    */
        conDesc.drop(lcc, !cascadeOnRefKey);

    if (cascadeOnRefKey)
    {
      ForeignKeyConstraintDescriptor fkcd;
      ReferencedKeyConstraintDescriptor cd;
      ConstraintDescriptorList cdl;

      cd = (ReferencedKeyConstraintDescriptor)conDesc;
      cdl = cd.getForeignKeyConstraints(ReferencedKeyConstraintDescriptor.ALL);
      int cdlSize = cdl.size();

      for(int index = 0; index < cdlSize; index++)
      {
        fkcd = (ForeignKeyConstraintDescriptor) cdl.elementAt(index);
        dm.invalidateFor(fkcd, DependencyManager.DROP_CONSTRAINT, lcc);
        fkcd.drop(lcc, true);
      }
 
      /*
      ** We told dropConstraintAndIndex not to
      ** remove our dependencies, so send an invalidate,
      ** and drop the dependencies.
      */
      dm.invalidateFor(conDesc, DependencyManager.DROP_CONSTRAINT, lcc);
      dm.clearDependencies(lcc, conDesc);
    }
  }
View Full Code Here

    long            sortId;
    int              maxBaseColumnPosition = -1;

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

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

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


    /* Get the table descriptor. */
    /* See if we can get the TableDescriptor
     * from the Activation.  (Will be there
     * for backing indexes.)
     */
    td = activation.getDDLTableDescriptor();

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

    if (td == null)
    {
      throw StandardException.newException(SQLState.LANG_CREATE_INDEX_NO_TABLE,
            indexName, tableName);
    }

    if (td.getTableType() == TableDescriptor.SYSTEM_TABLE_TYPE)
    {
      throw StandardException.newException(SQLState.LANG_CREATE_SYSTEM_INDEX_ATTEMPTED,
            indexName, tableName);
    }

    /* Get a shared table lock on the table. We need to lock table before
     * invalidate dependents, otherwise, we may interfere with the
     * compilation/re-compilation of DML/DDL.  See beetle 4325 and $WS/
     * docs/language/SolutionsToConcurrencyIssues.txt (point f).
     */
    lockTableForDDL(tc, td.getHeapConglomerateId(), false);

    // invalidate any prepared statements that
    // depended on this table (including this one)
    if (! forCreateTable)
    {
      dm.invalidateFor(td, DependencyManager.CREATE_INDEX, lcc);
    }

    // Translate the base column names to column positions
    baseColumnPositions = new int[columnNames.length];
    for (int i = 0; i < columnNames.length; i++)
View Full Code Here

    TableDescriptor td;
    UUID tableID;

    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.
View Full Code Here

    ConstraintDescriptorList constraintDescriptorList;
    ConstraintDescriptor constraintDescriptor;

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

    /* look for foreign key dependency on the table. If found any,
    use dependency manager to pass the rename action to the
    dependents. */
    constraintDescriptorList = dd.getConstraintDescriptors(td);
    for(int index=0; index<constraintDescriptorList.size(); index++)
    {
      constraintDescriptor = constraintDescriptorList.elementAt(index);
      if (constraintDescriptor instanceof ReferencedKeyConstraintDescriptor)
        dm.invalidateFor(constraintDescriptor, DependencyManager.RENAME, lcc);
    }

    // Drop the table
    dd.dropTableDescriptor(td, sd, tc);
    // Change the table name of the table descriptor
View Full Code Here

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