Search in sources :

Example 1 with Dependent

use of org.apache.derby.iapi.sql.depend.Dependent in project derby by apache.

the class BasicDependencyManager method coreInvalidateFor.

/**
 * A version of invalidateFor that does not provide synchronization among
 * invalidators.
 *
 * @param p the provider
 * @param action the action causing the invalidation
 * @param lcc language connection context
 *
 * @throws StandardException if something goes wrong
 */
private void coreInvalidateFor(Provider p, int action, LanguageConnectionContext lcc) throws StandardException {
    List<Dependency> list = getDependents(p);
    if (list.isEmpty()) {
        return;
    }
    // affectedCols is passed in from table descriptor provider to indicate
    // which columns it cares; subsetCols is affectedCols' intersection
    // with column bit map found in the provider of SYSDEPENDS line to
    // find out which columns really matter.  If SYSDEPENDS line's
    // dependent is view (or maybe others), provider is table, yet it
    // doesn't have column bit map because the view was created in a
    // previous version of server which doesn't support column dependency,
    // and we really want it to have (such as in drop column), in any case
    // if we passed in table descriptor to this function with a bit map,
    // we really need this, we generate the bitmaps on the fly and update
    // SYSDEPENDS
    // 
    // Note: Since the "previous version of server" mentioned above must
    // be a version that predates Derby, and we don't support upgrade from
    // those versions, we no longer have code to generate the column
    // dependency list on the fly. Instead, an assert has been added to
    // verify that we always have a column bitmap in SYSDEPENDS if the
    // affectedCols bitmap is non-null.
    FormatableBitSet affectedCols = null, subsetCols = null;
    if (p instanceof TableDescriptor) {
        affectedCols = ((TableDescriptor) p).getReferencedColumnMap();
        if (affectedCols != null)
            subsetCols = new FormatableBitSet(affectedCols.getLength());
    }
    {
        StandardException noInvalidate = null;
        // entries from this list.
        for (int ei = list.size() - 1; ei >= 0; ei--) {
            if (ei >= list.size())
                continue;
            Dependency dependency = list.get(ei);
            Dependent dep = dependency.getDependent();
            if (affectedCols != null) {
                TableDescriptor td = (TableDescriptor) dependency.getProvider();
                FormatableBitSet providingCols = td.getReferencedColumnMap();
                if (providingCols == null) {
                    if (dep instanceof ViewDescriptor) {
                        // this code was removed as part of DERBY-6169.
                        if (SanityManager.DEBUG) {
                            SanityManager.THROWASSERT("Expected view to " + "have referenced column bitmap");
                        }
                    } else
                        // if dep instanceof ViewDescriptor
                        ((TableDescriptor) p).setReferencedColumnMap(null);
                } else // if providingCols == null
                {
                    subsetCols.copyFrom(affectedCols);
                    subsetCols.and(providingCols);
                    if (subsetCols.anySetBit() == -1)
                        continue;
                    ((TableDescriptor) p).setReferencedColumnMap(subsetCols);
                }
            }
            // generate a list of invalidations that fail.
            try {
                dep.prepareToInvalidate(p, action, lcc);
            } catch (StandardException sqle) {
                if (noInvalidate == null) {
                    noInvalidate = sqle;
                } else {
                    try {
                        sqle.initCause(noInvalidate);
                        noInvalidate = sqle;
                    } catch (IllegalStateException ise) {
                    // We weren't able to chain the exceptions. That's
                    // OK, since we always have the first exception we
                    // caught. Just skip the current exception.
                    }
                }
            }
            if (noInvalidate == null) {
                if (affectedCols != null)
                    ((TableDescriptor) p).setReferencedColumnMap(affectedCols);
                // REVISIT: future impl will want to mark the individual
                // dependency as invalid as well as the dependent...
                dep.makeInvalid(action, lcc);
            }
        }
        if (noInvalidate != null)
            throw noInvalidate;
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) Dependency(org.apache.derby.iapi.sql.depend.Dependency) Dependent(org.apache.derby.iapi.sql.depend.Dependent) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor)

Example 2 with Dependent

use of org.apache.derby.iapi.sql.depend.Dependent in project derby by apache.

the class BasicDependencyManager method getDependencyDescriptorList.

/**
 * Turn a list of DependencyDescriptors into a list of Dependencies.
 *
 * @param storedList	The List of DependencyDescriptors representing
 *						stored dependencies.
 * @param providerForList The provider if this list is being created
 *                        for a list of dependents. Null otherwise.
 *
 * @return List		The converted List
 *
 * @exception StandardException thrown if something goes wrong
 */
private List<Dependency> getDependencyDescriptorList(List<DependencyDescriptor> storedList, Provider providerForList) throws StandardException {
    List<Dependency> retval = new ArrayList<Dependency>();
    if (!storedList.isEmpty()) {
        /* For each DependencyDescriptor, we need to instantiate
			 * object descriptors of the appropriate type for both
			 * the dependent and provider, create a Dependency with
			 * that Dependent and Provider and substitute the Dependency
			 * back into the same place in the List
			 * so that the call gets an enumerations of Dependencys.
			 */
        for (DependencyDescriptor depDesc : storedList) {
            Dependent tempD;
            Provider tempP;
            DependableFinder finder = depDesc.getDependentFinder();
            tempD = (Dependent) finder.getDependable(dd, depDesc.getUUID());
            if (providerForList != null) {
                // Use the provider being passed in.
                tempP = providerForList;
                // Sanity check the object identifiers match.
                if (SanityManager.DEBUG) {
                    if (!tempP.getObjectID().equals(depDesc.getProviderID())) {
                        SanityManager.THROWASSERT("mismatch providers");
                    }
                }
            } else {
                finder = depDesc.getProviderFinder();
                tempP = (Provider) finder.getDependable(dd, depDesc.getProviderID());
            }
            retval.add(new BasicDependency(tempD, tempP));
        }
    }
    return retval;
}
Also used : DependableFinder(org.apache.derby.catalog.DependableFinder) DependencyDescriptor(org.apache.derby.iapi.sql.dictionary.DependencyDescriptor) ArrayList(java.util.ArrayList) Dependency(org.apache.derby.iapi.sql.depend.Dependency) Dependent(org.apache.derby.iapi.sql.depend.Dependent) Provider(org.apache.derby.iapi.sql.depend.Provider)

Aggregations

Dependency (org.apache.derby.iapi.sql.depend.Dependency)2 Dependent (org.apache.derby.iapi.sql.depend.Dependent)2 ArrayList (java.util.ArrayList)1 DependableFinder (org.apache.derby.catalog.DependableFinder)1 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)1 Provider (org.apache.derby.iapi.sql.depend.Provider)1 DependencyDescriptor (org.apache.derby.iapi.sql.dictionary.DependencyDescriptor)1 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)1 ViewDescriptor (org.apache.derby.iapi.sql.dictionary.ViewDescriptor)1 StandardException (org.apache.derby.shared.common.error.StandardException)1