org.apache.derby.impl.sql.depend
Class BasicDependencyManager

java.lang.Object
  extended by org.apache.derby.impl.sql.depend.BasicDependencyManager
All Implemented Interfaces:
DependencyManager

public class BasicDependencyManager
extends java.lang.Object
implements DependencyManager

The dependency manager tracks needs that dependents have of providers.


Field Summary
private  DataDictionary dd
          DataDictionary for this database.
private  java.util.Hashtable dependents
          Map of in-memory dependencies for Dependents.
private static ProviderInfo[] EMPTY_PROVIDER_INFO
           
private  java.util.Hashtable providers
          Map of in-memory dependencies for Providers.
 
Fields inherited from interface org.apache.derby.iapi.sql.depend.DependencyManager
ALTER_TABLE, BULK_INSERT, CHANGED_CURSOR, COMPILE_FAILED, COMPRESS_TABLE, CREATE_CONSTRAINT, CREATE_INDEX, CREATE_TRIGGER, CREATE_VIEW, DROP_COLUMN, DROP_COLUMN_RESTRICT, DROP_CONSTRAINT, DROP_INDEX, DROP_JAR, DROP_METHOD_ALIAS, DROP_SCHEMA, DROP_SEQUENCE, DROP_SPS, DROP_STATISTICS, DROP_SYNONYM, DROP_TABLE, DROP_TRIGGER, DROP_UDT, DROP_VIEW, INTERNAL_RECOMPILE_REQUEST, MAX_ACTION_CODE, MODIFY_COLUMN_DEFAULT, PREPARED_STATEMENT_RELEASE, RECHECK_PRIVILEGES, RENAME, RENAME_INDEX, REPLACE_JAR, REVOKE_PRIVILEGE, REVOKE_PRIVILEGE_RESTRICT, REVOKE_ROLE, ROLLBACK, SET_CONSTRAINTS_DISABLE, SET_CONSTRAINTS_ENABLE, SET_TRIGGERS_DISABLE, SET_TRIGGERS_ENABLE, TRUNCATE_TABLE, UPDATE_STATISTICS, USER_RECOMPILE_REQUEST
 
Constructor Summary
BasicDependencyManager(DataDictionary dd)
           
 
Method Summary
 void addDependency(Dependent d, Provider p, ContextManager cm)
          adds a dependency from the dependent on the provider.
private  void addDependency(Dependent d, Provider p, ContextManager cm, TransactionController tc)
           
private  boolean addDependencyToTable(java.util.Hashtable table, java.lang.Object key, Dependency dy)
          Add a new dependency to the specified table if it does not already exist in that table.
private  void bubbleSort(UUID[] uuids)
          Do a bubble sort on the given array of UUIDs.
 void clearColumnInfoInProviders(ProviderList pl)
          Clear the in memory column bit map information in any table descriptor provider in a provider list.
 void clearDependencies(LanguageConnectionContext lcc, Dependent d)
          Erases all of the dependencies the dependent has, be they valid or invalid, of any dependency type.
 void clearDependencies(LanguageConnectionContext lcc, Dependent d, TransactionController tc)
          Erases all of the dependencies the dependent has, be they valid or invalid, of any dependency type.
 void clearInMemoryDependency(Dependency dy)
          Clear the specified in memory dependency.
protected  void clearProviderDependency(UUID p, Dependency d)
          removes a dependency for a given provider. assumes that the dependent removal is being dealt with elsewhere.
 void copyDependencies(Dependent copy_From, Dependent copyTo, boolean persistentOnly, ContextManager cm)
          Copy dependencies from one dependent to another.
 void copyDependencies(Dependent copy_From, Dependent copyTo, boolean persistentOnly, ContextManager cm, TransactionController tc)
          Copy dependencies from one dependent to another.
private  void coreInvalidateFor(Provider p, int action, LanguageConnectionContext lcc)
          A version of invalidateFor that does not provide synchronization among invalidators.
 int countDependencies()
          Count the number of active dependencies, both stored and in memory, in the system.
private  void dropDependency(LanguageConnectionContext lcc, Dependent d, Provider p)
          drops a single dependency
 java.lang.String dumpDependencies()
          Dump out debugging info on all of the dependencies currently within the system.
 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.
private  java.util.List getDependencyDescriptorList(java.util.List storedList, Provider providerForList)
          Replace the DependencyDescriptors in an List with Dependencys.
private  java.util.List getDependents(Provider p)
          Returns an enumeration of all dependencies that this provider is supporting for any dependent at all (even invalid ones).
private  LanguageConnectionContext getLanguageConnectionContext(ContextManager cm)
          Returns the LanguageConnectionContext to use.
 ProviderInfo[] getPersistentProviderInfos(Dependent dependent)
          Get a new array of ProviderInfos representing all the persistent providers for the given dependent.
 ProviderInfo[] getPersistentProviderInfos(ProviderList pl)
          Get a new array of ProviderInfos representing all the persistent providers from the given list of providers.
private  java.util.List getProviders(Dependent d)
          Returns an enumeration of all dependencies that this dependent has with any provider (even invalid ones).
 void invalidateFor(Provider p, int action, LanguageConnectionContext lcc)
          mark all dependencies on the named provider as invalid.
private static java.util.List newSList()
           
private static java.util.List newSList(java.util.List list)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dd

private final DataDictionary dd
DataDictionary for this database.


dependents

private final java.util.Hashtable 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.Hashtable 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
Throws:
StandardException

dropDependency

private void dropDependency(LanguageConnectionContext lcc,
                            Dependent d,
                            Provider p)
                     throws StandardException
drops a single dependency

Parameters:
d - the dependent
p - the provider
Throws:
StandardException - thrown if something goes wrong

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. If parameter "forSync" is true, it also provides synchronization on the dependents. Currently, this means synchronizing on the prepared statements, which might be being executed on other threads.

Parameters:
p - provider
action - The action causing the invalidate
lcc - Language connection context
Throws:
StandardException - Thrown on error.

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

getPersistentProviderInfos

public ProviderInfo[] getPersistentProviderInfos(Dependent dependent)
                                          throws StandardException
Description copied from interface: DependencyManager
Get a new array of ProviderInfos representing all the persistent providers for the given dependent.

Specified by:
getPersistentProviderInfos in interface DependencyManager
Throws:
StandardException - Thrown on error
See Also:
DependencyManager.getPersistentProviderInfos(org.apache.derby.iapi.sql.depend.Dependent)

getPersistentProviderInfos

public ProviderInfo[] getPersistentProviderInfos(ProviderList pl)
                                          throws StandardException
Description copied from interface: DependencyManager
Get a new array of ProviderInfos representing all the persistent providers from the given list of providers.

Specified by:
getPersistentProviderInfos in interface DependencyManager
Throws:
StandardException - Thrown on error
See Also:
DependencyManager.getPersistentProviderInfos(org.apache.derby.iapi.sql.depend.Dependent)

clearColumnInfoInProviders

public void clearColumnInfoInProviders(ProviderList pl)
                                throws StandardException
Description copied from interface: DependencyManager
Clear the in memory column bit map information in any table descriptor provider in a provider list. This function needs to be called before the table descriptor is reused as provider in column dependency. For example, this happens in "create publication" statement with target-only DDL where more than one views are defined and they all reference one table.

Specified by:
clearColumnInfoInProviders in interface DependencyManager
Parameters:
pl - provider list
Throws:
StandardException - Thrown on error
See Also:
DependencyManager.clearColumnInfoInProviders(org.apache.derby.iapi.sql.depend.ProviderList)

copyDependencies

public void copyDependencies(Dependent copy_From,
                             Dependent copyTo,
                             boolean persistentOnly,
                             ContextManager cm)
                      throws StandardException
Copy dependencies from one dependent to another.

Specified by:
copyDependencies in interface DependencyManager
Parameters:
copy_From - the dependent to copy from
copyTo - the dependent to copy to
persistentOnly - only copy persistent dependencies
cm - Current ContextManager
Throws:
StandardException - Thrown on error.

copyDependencies

public void copyDependencies(Dependent copy_From,
                             Dependent copyTo,
                             boolean persistentOnly,
                             ContextManager cm,
                             TransactionController tc)
                      throws StandardException
Description copied from interface: DependencyManager
Copy dependencies from one dependent to another.

Specified by:
copyDependencies in interface DependencyManager
Parameters:
copy_From - the dependent to copy from
copyTo - the dependent to copy to
persistentOnly - only copy persistent dependencies
cm - Current ContextManager
tc - Transaction Controller
Throws:
StandardException - Thrown on error.

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

dumpDependencies

public java.lang.String dumpDependencies()
                                  throws StandardException,
                                         java.sql.SQLException
Dump out debugging info on all of the dependencies currently within the system.

Specified by:
dumpDependencies in interface DependencyManager
Returns:
String Debugging info on the dependencies. (null if SanityManger.DEBUG is false)
Throws:
StandardException - thrown if something goes wrong
java.sql.SQLException - thrown if something goes wrong

addDependencyToTable

private boolean addDependencyToTable(java.util.Hashtable table,
                                     java.lang.Object 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

protected 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 getDependencyDescriptorList(java.util.List storedList,
                                                   Provider providerForList)
                                            throws StandardException
Replace the DependencyDescriptors in an List with Dependencys.

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.

bubbleSort

private void bubbleSort(UUID[] uuids)
Do a bubble sort on the given array of UUIDs. This sorts by the String values of the UUIDs. It's slow, but it doesn't matter because this is only for testing and debugging. Sorting by UUID.toString() always gives the same order because, within a single boot of the system, UUIDs are distinguished only by a sequence number.

Parameters:
uuids - The array of UUIDs to sort.

getProviders

private java.util.List getProviders(Dependent d)
                             throws StandardException
Returns an enumeration of all dependencies that this dependent has with any provider (even invalid ones). Includes all dependency types.

Parameters:
d - the dependent
Throws:
StandardException - thrown if something goes wrong

getDependents

private java.util.List 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
Throws:
StandardException - thrown if something goes wrong

newSList

private static java.util.List newSList()

newSList

private static java.util.List newSList(java.util.List list)

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.