use of org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList 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.ConstraintDescriptorList in project derby by apache.
the class DataDictionaryImpl method dropAllConstraintDescriptors.
/**
* Drops all ConstraintDescriptors from the data dictionary
* that are associated with the given table,
*
* @param table The table from which to drop all
* constraint descriptors
* @param tc The TransactionController
*
* @exception StandardException Thrown on error
*/
public void dropAllConstraintDescriptors(TableDescriptor table, TransactionController tc) throws StandardException {
ConstraintDescriptorList cdl = getConstraintDescriptors(table);
// Walk the table's CDL and drop each ConstraintDescriptor.
for (Iterator iterator = cdl.iterator(); iterator.hasNext(); ) {
ConstraintDescriptor cd = (ConstraintDescriptor) iterator.next();
dropConstraintDescriptor(cd, tc);
}
/*
** Null out the table's constraint descriptor list. NOTE: This is
** not really necessary at the time of this writing (11/3/97), because
** we do not cache data dictionary objects while DDL is going on,
** but in the future it might be necessary.
*/
table.setConstraintDescriptorList(null);
}
use of org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList in project derby by apache.
the class DataDictionaryImpl method getForeignKeys.
/**
* Return a list of foreign keys constraints referencing
* this constraint. Returns both enforced and not enforced
* foreign keys.
*
* @param constraintId The id of the referenced constraint
*
* @return list of constraints, empty of there are none
*
* @exception StandardException Thrown on error
*/
public ConstraintDescriptorList getForeignKeys(UUID constraintId) throws StandardException {
TabInfoImpl ti = getNonCoreTI(SYSFOREIGNKEYS_CATALOG_NUM);
List<SubKeyConstraintDescriptor> fkList = newSList();
// Use constraintIDOrderable in both start and stop positions for scan
DataValueDescriptor constraintIDOrderable = getIDValueAsCHAR(constraintId);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
keyRow.setColumn(1, constraintIDOrderable);
getDescriptorViaIndex(SYSFOREIGNKEYSRowFactory.SYSFOREIGNKEYS_INDEX2_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, fkList, SubKeyConstraintDescriptor.class, false);
TableDescriptor td;
ConstraintDescriptorList cdl = new ConstraintDescriptorList();
for (SubKeyConstraintDescriptor cd : fkList) {
td = getConstraintTableDescriptor(cd.getUUID());
cdl.add(getConstraintDescriptors(td).getConstraintDescriptorById(cd.getUUID()));
}
return cdl;
}
use of org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList in project derby by apache.
the class DataDictionaryImpl method getConstraintDescriptors.
/**
* Load up the constraint descriptor list for this table
* descriptor and return it. If the descriptor list
* is already loaded up, it is retuned without further
* ado. If no table descriptor is passed in, then all
* constraint descriptors are retrieved. Note that in
* this case, the constraint descriptor objects may be
* duplicates of constraint descriptors that are hung
* off of the table descriptor cache.
*
* @param td The table descriptor. If null,
* all constraint descriptors are returned.
*
* @return The ConstraintDescriptorList for the table
*
* @exception StandardException Thrown on failure
*/
public ConstraintDescriptorList getConstraintDescriptors(TableDescriptor td) throws StandardException {
ConstraintDescriptorList cdl;
if (td == null) {
return getAllConstraintDescriptors();
}
/* RESOLVE - need to look at multi-user aspects of hanging constraint
* descriptor list off of table descriptor when we restore the cache.
*/
/* Build the TableDescriptor's CDL if it is currently empty */
cdl = td.getConstraintDescriptorList();
/*
** Synchronize the building of the CDL. The CDL itself is created
** empty when the TD is created, so there is no need to synchronize
** the getting of the CDL.
*/
synchronized (cdl) {
if (!cdl.getScanned()) {
getConstraintDescriptorsScan(td, false);
}
}
return cdl;
}
Aggregations