Class BasicDependencyManager

  • All Implemented Interfaces:
    DependencyManager

    public class BasicDependencyManager
    extends java.lang.Object
    implements DependencyManager
    The dependency manager tracks needs that dependents have of providers.

    A dependency can be either persistent or non-persistent. Persistent dependencies are stored in the data dictionary, and non-persistent dependencies are stored within the dependency manager itself (in memory).

    Synchronization: The need for synchronization is different depending on whether the dependency is an in-memory dependency or a stored dependency. When accessing and modifying in-memory dependencies, Java synchronization must be used (specifically, we synchronize on this). When accessing and modifying stored dependencies, which are stored in the data dictionary, we expect that the locking protocols will provide the synchronization needed. Note that stored dependencies should not be accessed while holding the monitor of this, as this may result in deadlocks. So far the need for synchronization across both in-memory and stored dependencies hasn't occurred.

    • Field Detail

      • dd

        private final DataDictionary dd
        DataDictionary for this database.
      • dependents

        private final java.util.Map<UUID,​java.util.List<Dependency>> dependents
        Map of in-memory dependencies for Dependents. In-memory means that one or both of the Dependent or Provider are non-persistent (isPersistent() returns false). Key is the UUID of the Dependent (from getObjectID()). Value is a List containing Dependency objects, each of whihc links the same Dependent to a Provider. Dependency objects in the List are unique.
      • providers

        private final java.util.Map<UUID,​java.util.List<Dependency>> providers
        Map of in-memory dependencies for Providers. In-memory means that one or both of the Dependent or Provider are non-persistent (isPersistent() returns false). Key is the UUID of the Provider (from getObjectID()). Value is a List containing Dependency objects, each of which links the same Provider to a Dependent. Dependency objects in the List are unique.
      • EMPTY_PROVIDER_INFO

        private static final ProviderInfo[] EMPTY_PROVIDER_INFO
    • Constructor Detail

      • BasicDependencyManager

        public BasicDependencyManager​(DataDictionary dd)
    • Method Detail

      • addDependency

        public void addDependency​(Dependent d,
                                  Provider p,
                                  ContextManager cm)
                           throws StandardException
        adds a dependency from the dependent on the provider. This will be considered to be the default type of dependency, when dependency types show up.

        Implementations of addDependency should be fast -- performing alot of extra actions to add a dependency would be a detriment.

        Specified by:
        addDependency in interface DependencyManager
        Parameters:
        d - the dependent
        p - the provider
        cm - Current ContextManager
        Throws:
        StandardException - thrown if something goes wrong
      • addDependency

        private void addDependency​(Dependent d,
                                   Provider p,
                                   ContextManager cm,
                                   TransactionController tc)
                            throws StandardException
        Adds the dependency to the data dictionary or the in-memory dependency map.

        The action taken is detmermined by whether the dependent and/or the provider are persistent.

        Parameters:
        d - the dependent
        p - the provider
        cm - context manager
        tc - transaction controller, used to determine if any transactional operations should be attempted carried out in a nested transaction. If tc is null, the user transaction is used.
        Throws:
        StandardException - if adding the dependency fails
      • invalidateFor

        public void invalidateFor​(Provider p,
                                  int action,
                                  LanguageConnectionContext lcc)
                           throws StandardException
        mark all dependencies on the named provider as invalid. When invalidation types show up, this will use the default invalidation type. The dependencies will still exist once they are marked invalid; clearDependencies should be used to remove dependencies that a dependent has or provider gives.

        Implementations of this can take a little time, but are not really expected to recompile things against any changes made to the provider that caused the invalidation. The dependency system makes no guarantees about the state of the provider -- implementations can call this before or after actually changing the provider to its new state.

        Implementations should throw StandardException if the invalidation should be disallowed.

        Specified by:
        invalidateFor in interface DependencyManager
        Parameters:
        p - the provider
        action - The action causing the invalidate
        lcc - The LanguageConnectionContext
        Throws:
        StandardException - thrown if unable to make it invalid
      • coreInvalidateFor

        private void coreInvalidateFor​(Provider p,
                                       int action,
                                       LanguageConnectionContext lcc)
                                throws StandardException
        A version of invalidateFor that does not provide synchronization among invalidators.
        Parameters:
        p - the provider
        action - the action causing the invalidation
        lcc - language connection context
        Throws:
        StandardException - if something goes wrong
      • clearDependencies

        public void clearDependencies​(LanguageConnectionContext lcc,
                                      Dependent d)
                               throws StandardException
        Erases all of the dependencies the dependent has, be they valid or invalid, of any dependency type. This action is usually performed as the first step in revalidating a dependent; it first erases all the old dependencies, then revalidates itself generating a list of new dependencies, and then marks itself valid if all its new dependencies are valid.

        There might be a future want to clear all dependencies for a particular provider, e.g. when destroying the provider. However, at present, they are assumed to stick around and it is the responsibility of the dependent to erase them when revalidating against the new version of the provider.

        clearDependencies will delete dependencies if they are stored; the delete is finalized at the next commit.

        Specified by:
        clearDependencies in interface DependencyManager
        Parameters:
        d - the dependent
        lcc - Compiler state
        Throws:
        StandardException - Thrown on failure
      • clearDependencies

        public void clearDependencies​(LanguageConnectionContext lcc,
                                      Dependent d,
                                      TransactionController tc)
                               throws StandardException
        Description copied from interface: DependencyManager
        Erases all of the dependencies the dependent has, be they valid or invalid, of any dependency type. This action is usually performed as the first step in revalidating a dependent; it first erases all the old dependencies, then revalidates itself generating a list of new dependencies, and then marks itself valid if all its new dependencies are valid.

        There might be a future want to clear all dependencies for a particular provider, e.g. when destroying the provider. However, at present, they are assumed to stick around and it is the responsibility of the dependent to erase them when revalidating against the new version of the provider.

        clearDependencies will delete dependencies if they are stored; the delete is finalized at the next commit.

        Specified by:
        clearDependencies in interface DependencyManager
        Parameters:
        lcc - Compiler state
        d - the dependent
        tc - transaction controller
        Throws:
        StandardException - Thrown on failure
      • clearInMemoryDependency

        public void clearInMemoryDependency​(Dependency dy)
        Clear the specified in memory dependency. This is useful for clean-up when an exception occurs. (We clear all in-memory dependencies added in the current StatementContext.)
        Specified by:
        clearInMemoryDependency in interface DependencyManager
      • getActionString

        public java.lang.String getActionString​(int action)
        Returns a string representation of the SQL action, hence no need to internationalize, which is causing the invokation of the Dependency Manager.
        Specified by:
        getActionString in interface DependencyManager
        Parameters:
        action - The action
        Returns:
        String The String representation
      • countDependencies

        public int countDependencies()
                              throws StandardException
        Count the number of active dependencies, both stored and in memory, in the system.
        Specified by:
        countDependencies in interface DependencyManager
        Returns:
        int The number of active dependencies in the system.
        Throws:
        StandardException - thrown if something goes wrong
      • addDependencyToTable

        private boolean addDependencyToTable​(java.util.Map<UUID,​java.util.List<Dependency>> table,
                                             UUID key,
                                             Dependency dy)
        Add a new dependency to the specified table if it does not already exist in that table.
        Returns:
        boolean Whether or not the dependency get added.
      • clearProviderDependency

        private void clearProviderDependency​(UUID p,
                                             Dependency d)
        removes a dependency for a given provider. assumes that the dependent removal is being dealt with elsewhere. Won't assume that the dependent only appears once in the list.
      • getDependencyDescriptorList

        private java.util.List<Dependency> getDependencyDescriptorList​(java.util.List<DependencyDescriptor> storedList,
                                                                       Provider providerForList)
                                                                throws StandardException
        Turn a list of DependencyDescriptors into a list of Dependencies.
        Parameters:
        storedList - The List of DependencyDescriptors representing stored dependencies.
        providerForList - The provider if this list is being created for a list of dependents. Null otherwise.
        Returns:
        List The converted List
        Throws:
        StandardException - thrown if something goes wrong
      • getLanguageConnectionContext

        private LanguageConnectionContext getLanguageConnectionContext​(ContextManager cm)
        Returns the LanguageConnectionContext to use.
        Parameters:
        cm - Current ContextManager
        Returns:
        LanguageConnectionContext The LanguageConnectionContext to use.
      • getProviders

        private java.util.List<Provider> getProviders​(Dependent d)
                                               throws StandardException
        Returns a list of all providers that this dependent has (even invalid ones). Includes all dependency types.
        Parameters:
        d - the dependent
        Returns:
        A list of providers (possibly empty).
        Throws:
        StandardException - thrown if something goes wrong
      • getDependents

        private java.util.List<Dependency> getDependents​(Provider p)
                                                  throws StandardException
        Returns an enumeration of all dependencies that this provider is supporting for any dependent at all (even invalid ones). Includes all dependency types.
        Parameters:
        p - the provider
        Returns:
        A list of dependents (possibly empty).
        Throws:
        StandardException - if something goes wrong