* @exception StandardException Thrown on failure
*/
public void executeConstantAction( Activation activation )
throws StandardException
{
ConstraintDescriptor cd;
TableDescriptor td;
ConstraintDescriptorList tmpCdl;
boolean enforceThisConstraint;
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
DependencyManager dm = dd.getDependencyManager();
TransactionController tc = lcc.getTransactionExecute();
tmpCdl = getConstraintDescriptorList(dd);
int[] enabledCol = new int[1];
enabledCol[0] = ConstraintDescriptor.SYSCONSTRAINTS_STATE_FIELD;
/*
** 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);
/*
** Callback to rep subclass
*/
publishToTargets(activation);
boolean skipFKs = false;
/*
** If the constraint list is empty, then we are getting
** all constraints. In this case, don't bother going
** after referencing keys (foreign keys) when we are
** disabling a referenced key (pk or unique key) since
** we know we'll hit it eventually.
*/
if (tmpCdl == null)
{
skipFKs = true;
tmpCdl = dd.getConstraintDescriptors((TableDescriptor)null);
}
Hashtable checkConstraintTables = null;
int cdlSize = tmpCdl.size();
for (int index = 0; index < cdlSize; index++)
{
cd = tmpCdl.elementAt(index);
/*
** We are careful to enable this constraint before trying
** to enable constraints that reference it. Similarly,
** we disabled constraints that reference us before we
** disable ourselves, to make sure everything works ok.
*/
if (unconditionallyEnforce)
{
enforceThisConstraint = true;
}
else
{
enforceThisConstraint = (enable && !cd.isEnabled());
}
if (enforceThisConstraint)
{
if (cd instanceof ForeignKeyConstraintDescriptor)
{
validateFKConstraint((ForeignKeyConstraintDescriptor)cd, dd, tc, lcc.getContextManager());
}
/*
** For check constraints, we build up a list of check constriants
** by table descriptor. Once we have collected them all, we
** execute them in a single query per table descriptor.
*/
else if (cd instanceof CheckConstraintDescriptor)
{
td = cd.getTableDescriptor();
if (checkConstraintTables == null)
{
checkConstraintTables = new Hashtable(10);
}
ConstraintDescriptorList tabCdl = (ConstraintDescriptorList)
checkConstraintTables.get(td.getUUID());
if (tabCdl == null)
{
tabCdl = new ConstraintDescriptorList();
checkConstraintTables.put(td.getUUID(), tabCdl);
}
tabCdl.add(cd);
}
/*
** If we are enabling a constraint, we need to issue
** the invalidation on the underlying table rather than
** the constraint we are enabling. This is because
** stmts that were compiled against a disabled constraint
** have no depedency on that disabled constriant.
*/
dm.invalidateFor(cd.getTableDescriptor(),
DependencyManager.SET_CONSTRAINTS_ENABLE, lcc);
cd.setEnabled();
dd.updateConstraintDescriptor(cd,
cd.getUUID(),
enabledCol,
tc);
}
/*
** If we are dealing with a referenced constraint, then
** we find all of the constraints that reference this constraint.
** Turn them on/off based on what we are doing to this
** constraint.
*/
if (!skipFKs &&
(cd instanceof ReferencedKeyConstraintDescriptor))
{
ForeignKeyConstraintDescriptor fkcd;
ReferencedKeyConstraintDescriptor refcd;
ConstraintDescriptorList fkcdl;
refcd = (ReferencedKeyConstraintDescriptor)cd;
fkcdl = refcd.getForeignKeyConstraints(ReferencedKeyConstraintDescriptor.ALL);
int fkcdlSize = fkcdl.size();
for (int inner = 0; inner < fkcdlSize; inner++)
{
fkcd = (ForeignKeyConstraintDescriptor) fkcdl.elementAt(inner);
if (enable && !fkcd.isEnabled())
{
dm.invalidateFor(fkcd.getTableDescriptor(),
DependencyManager.SET_CONSTRAINTS_ENABLE, lcc);
validateFKConstraint(fkcd, dd, tc, lcc.getContextManager());
fkcd.setEnabled();
dd.updateConstraintDescriptor(fkcd,
fkcd.getUUID(),
enabledCol,
tc);
}
else if (!enable && fkcd.isEnabled())
{
dm.invalidateFor(fkcd, DependencyManager.SET_CONSTRAINTS_DISABLE,
lcc);
fkcd.setDisabled();
dd.updateConstraintDescriptor(fkcd,
fkcd.getUUID(),
enabledCol,
tc);
}
}
}
if (!enable && cd.isEnabled())
{
dm.invalidateFor(cd, DependencyManager.SET_CONSTRAINTS_DISABLE,
lcc);
cd.setDisabled();
dd.updateConstraintDescriptor(cd,
cd.getUUID(),
enabledCol,
tc);
}
}