private void dropAllConstraintDescriptors(TableDescriptor td, Activation activation)
throws StandardException
{
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.
*/
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(),