Search in sources :

Example 21 with ConstraintDescriptorList

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());
            }
        }
    }
}
Also used : CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) ForeignKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) ForeignKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor)

Example 22 with ConstraintDescriptorList

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);
}
Also used : SubConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) KeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor) SubKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor) CheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor) ForeignKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor) SubCheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor) RoleClosureIterator(org.apache.derby.iapi.sql.dictionary.RoleClosureIterator) Iterator(java.util.Iterator) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)

Example 23 with ConstraintDescriptorList

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;
}
Also used : SubKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 24 with ConstraintDescriptorList

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;
}
Also used : ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)

Aggregations

ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)24 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)15 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)10 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)7 ForeignKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 TransactionController (org.apache.derby.iapi.store.access.TransactionController)5 ArrayList (java.util.ArrayList)4 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)4 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)4 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)4 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)4 UUID (org.apache.derby.catalog.UUID)3 CheckConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor)3 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)3 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 KeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor)2 SubKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor)2