use of org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor in project derby by apache.
the class DMLModStatementNode method createConstraintDependencies.
/**
* Get all of our dependents due to a constraint.
*
* Makes the calling object (usually a Statement) dependent on all the constraints.
*
* @param dd The data dictionary
* @param cdl The constraint descriptor list
* @param dependent Parent object that will depend on all the constraints
* that we look up. If this argument is null, then we
* use the default dependent (the statement being compiled).
*
* @exception StandardException Thrown on failure
*/
private void createConstraintDependencies(DataDictionary dd, ConstraintDescriptorList cdl, Dependent dependent) throws StandardException {
CompilerContext compilerContext = getCompilerContext();
int cdlSize = cdl.size();
for (int index = 0; index < cdlSize; index++) {
ConstraintDescriptor cd = cdl.elementAt(index);
/*
** The dependent now depends on this constraint.
** the default dependent is the statement
** being compiled.
*/
if (dependent == null) {
compilerContext.createDependency(cd);
} else {
compilerContext.createDependency(dependent, cd);
}
/*
** We are also dependent on all referencing keys --
** if one of them is deleted, we'll have to recompile.
** Also, if there is a BULK_INSERT on the table
** we are going to scan to validate the constraint,
** the index number will change, so we'll add a
** dependency on all tables we will scan.
*/
if (cd instanceof ReferencedKeyConstraintDescriptor) {
ConstraintDescriptorList fkcdl = dd.getActiveConstraintDescriptors(((ReferencedKeyConstraintDescriptor) cd).getForeignKeyConstraints(ConstraintDescriptor.ENABLED));
int fklSize = fkcdl.size();
for (int inner = 0; inner < fklSize; inner++) {
ConstraintDescriptor fkcd = fkcdl.elementAt(inner);
if (dependent == null) {
compilerContext.createDependency(fkcd);
compilerContext.createDependency(fkcd.getTableDescriptor());
} else {
compilerContext.createDependency(dependent, fkcd);
compilerContext.createDependency(dependent, fkcd.getTableDescriptor());
}
}
} else if (cd instanceof ForeignKeyConstraintDescriptor) {
ForeignKeyConstraintDescriptor fkcd = (ForeignKeyConstraintDescriptor) cd;
if (dependent == null) {
compilerContext.createDependency(fkcd.getReferencedConstraint().getTableDescriptor());
} else {
compilerContext.createDependency(dependent, fkcd.getReferencedConstraint().getTableDescriptor());
}
}
}
}
use of org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor in project derby by apache.
the class DataDictionaryImpl method addSubKeyConstraint.
/**
* Add the matching row to syskeys when adding a unique or primary key constraint
*
* @param descriptor The KeyConstraintDescriptor for the constraint.
* @param tc The TransactionController
*
* @exception StandardException Thrown on failure
*/
private void addSubKeyConstraint(KeyConstraintDescriptor descriptor, TransactionController tc) throws StandardException {
ExecRow row;
TabInfoImpl ti;
/*
** Foreign keys get a row in SYSFOREIGNKEYS, and
** all others get a row in SYSKEYS.
*/
if (descriptor.getConstraintType() == DataDictionary.FOREIGNKEY_CONSTRAINT) {
ForeignKeyConstraintDescriptor fkDescriptor = (ForeignKeyConstraintDescriptor) descriptor;
if (SanityManager.DEBUG) {
if (!(descriptor instanceof ForeignKeyConstraintDescriptor)) {
SanityManager.THROWASSERT("descriptor not an fk descriptor, is " + descriptor.getClass().getName());
}
}
ti = getNonCoreTI(SYSFOREIGNKEYS_CATALOG_NUM);
SYSFOREIGNKEYSRowFactory fkkeysRF = (SYSFOREIGNKEYSRowFactory) ti.getCatalogRowFactory();
row = fkkeysRF.makeRow(fkDescriptor, null);
/*
** Now we need to bump the reference count of the
** constraint that this FK references
*/
ReferencedKeyConstraintDescriptor refDescriptor = fkDescriptor.getReferencedConstraint();
refDescriptor.incrementReferenceCount();
int[] colsToSet = new int[1];
colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_REFERENCECOUNT;
updateConstraintDescriptor(refDescriptor, refDescriptor.getUUID(), colsToSet, tc);
} else {
ti = getNonCoreTI(SYSKEYS_CATALOG_NUM);
SYSKEYSRowFactory keysRF = (SYSKEYSRowFactory) ti.getCatalogRowFactory();
// build the row to be stuffed into SYSKEYS
row = keysRF.makeRow(descriptor, null);
}
// insert row into catalog and all its indices
ti.insertRow(row, tc);
}
Aggregations