Search in sources :

Example 6 with DependencyManager

use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.

the class TriggerDescriptor method drop.

public void drop(LanguageConnectionContext lcc) throws StandardException {
    DataDictionary dd = getDataDictionary();
    DependencyManager dm = getDataDictionary().getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();
    dm.invalidateFor(this, DependencyManager.DROP_TRIGGER, lcc);
    // Drop the trigger
    dd.dropTriggerDescriptor(this, tc);
    // Clear the dependencies for the trigger
    dm.clearDependencies(lcc, this);
    // Drop the spses
    SPSDescriptor spsd = dd.getSPSDescriptor(this.getActionId());
    // there shouldn't be any dependencies, but in case
    // there are, lets clear them
    dm.invalidateFor(spsd, DependencyManager.DROP_TRIGGER, lcc);
    dm.clearDependencies(lcc, spsd);
    dd.dropSPSDescriptor(spsd, tc);
    if (getWhenClauseId() != null) {
        spsd = dd.getSPSDescriptor(getWhenClauseId());
        dm.invalidateFor(spsd, DependencyManager.DROP_TRIGGER, lcc);
        dm.clearDependencies(lcc, spsd);
        dd.dropSPSDescriptor(spsd, tc);
    }
}
Also used : DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 7 with DependencyManager

use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.

the class TriggerDescriptor method makeInvalid.

/**
 * Mark the dependent as invalid (due to at least one of
 * its dependencies being invalid).  Always an error
 * for a trigger -- should never have gotten here.
 *
 * @param 	lcc the language connection context
 * @param	action	The action causing the invalidation
 *
 * @exception StandardException thrown if called in sanity mode
 */
public void makeInvalid(int action, LanguageConnectionContext lcc) throws StandardException {
    switch(action) {
        // invalidate this trigger descriptor
        case DependencyManager.USER_RECOMPILE_REQUEST:
            DependencyManager dm = getDataDictionary().getDependencyManager();
            dm.invalidateFor(this, DependencyManager.PREPARED_STATEMENT_RELEASE, lcc);
            break;
        // Ditto for revoking a role conferring a privilege.
        case DependencyManager.REVOKE_PRIVILEGE:
        case DependencyManager.REVOKE_ROLE:
            drop(lcc);
            lcc.getLastActivation().addWarning(StandardException.newWarning(SQLState.LANG_TRIGGER_DROPPED, this.getObjectName()));
            break;
        default:
            break;
    }
}
Also used : DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager)

Example 8 with DependencyManager

use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.

the class DefaultDescriptor method prepareToInvalidate.

/**
 * Prepare to mark the dependent as invalid (due to at least one of
 * its dependencies being invalid).
 *
 * @param action	The action causing the invalidation
 * @param p		the provider
 *
 * @exception StandardException thrown if unable to make it invalid
 */
public void prepareToInvalidate(Provider p, int action, LanguageConnectionContext lcc) throws StandardException {
    DependencyManager dm = getDataDictionary().getDependencyManager();
    switch(action) {
        /*
			** Currently, the only thing we are depenedent
			** on is an alias.
			*/
        default:
            DataDictionary dd = getDataDictionary();
            ColumnDescriptor cd = dd.getColumnDescriptorByDefaultId(defaultUUID);
            TableDescriptor td = dd.getTableDescriptor(cd.getReferencingUUID());
            throw StandardException.newException(SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT, dm.getActionString(action), p.getObjectName(), "DEFAULT", td.getQualifiedName() + "." + cd.getColumnName());
    }
}
Also used : DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager)

Example 9 with DependencyManager

use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.

the class ConstraintDescriptor method makeInvalid.

/**
 * Mark the dependent as invalid (due to at least one of
 * its dependencies being invalid).  Always an error
 * for a constraint -- should never have gotten here.
 *
 * @param	action	The action causing the invalidation
 *
 * @exception StandardException thrown if called in sanity mode
 */
public void makeInvalid(int action, LanguageConnectionContext lcc) throws StandardException {
    // Let's handle REVOKE_PRIVILEGE and REVOKE_ROLE first
    if (action == DependencyManager.REVOKE_PRIVILEGE || action == DependencyManager.REVOKE_ROLE) {
        // At this point (Derby 10.2), only a FOREIGN KEY key constraint can
        // depend on a privilege. None of the other constraint types
        // can be dependent on a privilege becuse those constraint types
        // can not reference a table/routine.
        ConglomerateDescriptor newBackingConglomCD = drop(lcc, true);
        // 
        // Invalidate every statement which depends on the table.
        // This causes us to follow the same code path which we pursue
        // when the CHECK constraint is dropped explicitly.
        // 
        getDataDictionary().getDependencyManager().invalidateFor(table, DependencyManager.ALTER_TABLE, lcc);
        lcc.getLastActivation().addWarning(StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED, getConstraintName(), getTableDescriptor().getName()));
        if (newBackingConglomCD != null) {
            /* Since foreign keys can never be unique, and since
				 * we only (currently) share conglomerates if two
				 * constraints/indexes have identical columns, dropping
				 * a foreign key should not necessitate the creation of
				 * another physical conglomerate.  That will change if
				 * DERBY-2204 is implemented, but for now we don't expect
				 * it to happen...
				 */
            if (SanityManager.DEBUG) {
                SanityManager.THROWASSERT("Dropped shared conglomerate due to a REVOKE " + "and found that a new conglomerate was needed " + "to replace it...but that shouldn't happen!");
            }
        }
        return;
    }
    /*
		** Now, handle SET_CONSTRAINTS/TRIGGERS
		*/
    if ((action != DependencyManager.SET_CONSTRAINTS_DISABLE) && (action != DependencyManager.SET_CONSTRAINTS_ENABLE) && (action != DependencyManager.SET_TRIGGERS_ENABLE) && (action != DependencyManager.SET_TRIGGERS_DISABLE) && (action != DependencyManager.INTERNAL_RECOMPILE_REQUEST) && (action != DependencyManager.RECHECK_PRIVILEGES) && (action != DependencyManager.RENAME)) {
        /* 
			** 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");
        }
    }
}
Also used : DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager)

Example 10 with DependencyManager

use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.

the class ConstraintDescriptor method drop.

/**
 * Drop the constraint.  Clears dependencies, drops
 * the backing index and removes the constraint
 * from the list on the table descriptor.  Does NOT
 * do an dm.invalidateFor()
 *
 * @return If the backing conglomerate for this constraint
 *  was a) dropped and b) shared by other constraints/indexes,
 *  then this method will return a ConglomerateDescriptor that
 *  describes what a new backing conglomerate must look like
 *  to stay "sharable" across the remaining constraints/indexes.
 *  It is then up to the caller to create a corresponding
 *  conglomerate.  We don't create the conglomerate here
 *  because depending on who called us, it might not make
 *  sense to create it--ex. if we get here because of a DROP
 *  TABLE, the DropTable action doesn't need to create a
 *  new backing conglomerate since the table (and all of
 *  its constraints/indexes) are going to disappear anyway.
 */
public ConglomerateDescriptor drop(LanguageConnectionContext lcc, boolean clearDependencies) throws StandardException {
    DataDictionary dd = getDataDictionary();
    TransactionController tc = lcc.getTransactionExecute();
    if (clearDependencies) {
        DependencyManager dm = dd.getDependencyManager();
        dm.clearDependencies(lcc, this);
    }
    /* Drop the constraint.
         * NOTE: This must occur before dropping any backing index, since
         * a user is not allowed to drop a backing index without dropping
         * the constraint.
         */
    dd.dropConstraintDescriptor(this, tc);
    /* Drop the index, if there's one for this constraint.
         * NOTE: There will always be an indexAction. We don't
         * force the constraint to exist at bind time, so we always
         * generate one.
         */
    ConglomerateDescriptor newBackingConglomCD = null;
    if (hasBackingIndex()) {
        // it may have duplicates, and we drop a backing index
        // Bug 4307
        // We need to get the conglomerate descriptors from the
        // dd in case we dropped other constraints in a cascade operation.
        ConglomerateDescriptor[] conglomDescs = dd.getConglomerateDescriptors(getConglomerateId());
        // information since they point to the same physical index.
        for (ConglomerateDescriptor cd : conglomDescs) {
            if (cd.isConstraint()) {
                newBackingConglomCD = cd.drop(lcc, table);
                break;
            }
        }
    }
    table.removeConstraintDescriptor(this);
    return newBackingConglomCD;
}
Also used : DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Aggregations

DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)55 TransactionController (org.apache.derby.iapi.store.access.TransactionController)23 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)22 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)20 UUID (org.apache.derby.catalog.UUID)11 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)11 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)8 ContextManager (org.apache.derby.iapi.services.context.ContextManager)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)7 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)7 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)7 ProviderInfo (org.apache.derby.iapi.sql.depend.ProviderInfo)6 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)6 Provider (org.apache.derby.iapi.sql.depend.Provider)5 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)5 ProviderList (org.apache.derby.iapi.sql.depend.ProviderList)4 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)4 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)4 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)3 ForeignKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor)3