Top Description Fields Constructors Methods
org.apache.derby.impl.sql.depend

public Class BasicDependencyManager

extends Object
implements DependencyManager
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.depend.DependencyManager
Imports
java.util.ArrayList, .Enumeration, .HashMap, .Iterator, .List, .ListIterator, .Map, org.apache.derby.catalog.DependableFinder, .UUID, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, .StatementContext, org.apache.derby.iapi.sql.depend.Dependency, .DependencyManager, .Dependent, .Provider, .ProviderInfo, .ProviderList, org.apache.derby.iapi.sql.dictionary.DataDictionary, .DependencyDescriptor, .TableDescriptor, .ViewDescriptor, org.apache.derby.iapi.store.access.TransactionController

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 Summary

Modifier and TypeField and Description
private final DataDictionary
dd

DataDictionary for this database.

private final Map<UUID, List<Dependency>>
dependents

Map of in-memory dependencies for Dependents.

private static final ProviderInfo[]
private final Map<UUID, List<Dependency>>
providers

Map of in-memory dependencies for Providers.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addDependency(Dependent
the dependent
d
,
Provider
the provider
p
,
ContextManager
Current ContextManager
cm
)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.addDependency.

adds a dependency from the dependent on the provider.

private void
addDependency(Dependent
the dependent
d
,
Provider
the provider
p
,
ContextManager
context manager
cm
,
TransactionController
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.
tc
)

Adds the dependency to the data dictionary or the in-memory dependency map.

private boolean

Returns:

boolean Whether or not the dependency get added.
addDependencyToTable
(Map<UUID, List<Dependency>> table, UUID key, Dependency dy)

Add a new dependency to the specified table if it does not already exist in that table.

private synchronized void
addInMemoryDependency(Dependent
the dependent
d
,
Provider
the provider
p
,
ContextManager
context manager
cm
)

Adds the dependency as an in-memory dependency.

private void
addStoredDependency(Dependent
the dependent
d
,
Provider
the provider
p
,
ContextManager
context manager
cm
,
TransactionController
transaction controller (may be null)
tc
)

Adds the dependency as a stored dependency.

public void
clearColumnInfoInProviders(ProviderList
provider list
pl
)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.clearColumnInfoInProviders.

Clear the in memory column bit map information in any table descriptor provider in a provider list.

public void
clearDependencies(LanguageConnectionContext
Compiler state
lcc
,
Dependent
the dependent
d
)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.clearDependencies.

Erases all of the dependencies the dependent has, be they valid or invalid, of any dependency type.

public void
clearDependencies(LanguageConnectionContext
Compiler state
lcc
,
Dependent
the dependent
d
,
TransactionController
transaction controller
tc
)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.clearDependencies.

Erases all of the dependencies the dependent has, be they valid or invalid, of any dependency type.

public synchronized void
private void
clearProviderDependency(UUID p, Dependency d)

removes a dependency for a given provider.

public void
copyDependencies(Dependent
the dependent to copy from
copy_From
,
Dependent
the dependent to copy to
copyTo
,
boolean
only copy persistent dependencies
persistentOnly
,
ContextManager
Current ContextManager
cm
)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.copyDependencies.

Copy dependencies from one dependent to another.

public void
copyDependencies(Dependent
the dependent to copy from
copy_From
,
Dependent
the dependent to copy to
copyTo
,
boolean
only copy persistent dependencies
persistentOnly
,
ContextManager
Current ContextManager
cm
,
TransactionController
Transaction Controller
tc
)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.copyDependencies.

Copy dependencies from one dependent to another.

private void
coreInvalidateFor(Provider
the provider
p
,
int
the action causing the invalidation
action
,
LanguageConnectionContext
language connection context
lcc
)

A version of invalidateFor that does not provide synchronization among invalidators.

public int

Returns:

int The number of active dependencies in the system.
countDependencies
()

Implements org.apache.derby.iapi.sql.depend.DependencyManager.countDependencies.

Count the number of active dependencies, both stored and in memory, in the system.

private void
dropDependency(LanguageConnectionContext lcc, Dependent
the dependent
d
,
Provider
the provider
p
)

drops a single dependency

public String

Returns:

String The String representation
getActionString
(int
The action
action
)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.getActionString.

Returns a string representation of the SQL action, hence no need to internationalize, which is causing the invokation of the Dependency Manager.

private List<Dependency>

Returns:

List The converted List
getDependencyDescriptorList
(List<DependencyDescriptor>
The List of DependencyDescriptors representing stored dependencies.
storedList
,
Provider
The provider if this list is being created for a list of dependents. Null otherwise.
providerForList
)

Turn a list of DependencyDescriptors into a list of Dependencies.

private List<Dependency>

Returns:

A list of dependents (possibly empty).
getDependents
(Provider
the provider
p
)

Returns an enumeration of all dependencies that this provider is supporting for any dependent at all (even invalid ones).

private LanguageConnectionContext

Returns:

LanguageConnectionContext The LanguageConnectionContext to use.
getLanguageConnectionContext
(ContextManager
Current ContextManager
cm
)

Returns the LanguageConnectionContext to use.

public ProviderInfo[]
getPersistentProviderInfos(Dependent dependent)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.getPersistentProviderInfos.

Get a new array of ProviderInfos representing all the persistent providers for the given dependent.

public ProviderInfo[]
getPersistentProviderInfos(ProviderList pl)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.getPersistentProviderInfos.

Get a new array of ProviderInfos representing all the persistent providers from the given list of providers.

private List<Provider>

Returns:

A list of providers (possibly empty).
getProviders
(Dependent
the dependent
d
)

Returns a list of all providers that this dependent has (even invalid ones).

public void
invalidateFor(Provider
the provider
p
,
int
The action causing the invalidate
action
,
LanguageConnectionContext
The LanguageConnectionContext
lcc
)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.invalidateFor.

mark all dependencies on the named provider as invalid.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ddback to summary
private final DataDictionary dd

DataDictionary for this database.

dependentsback to summary
private final Map<UUID, 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.

EMPTY_PROVIDER_INFOback to summary
private static final ProviderInfo[] EMPTY_PROVIDER_INFO
providersback to summary
private final Map<UUID, 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.

Constructor Detail

BasicDependencyManagerback to summary
public BasicDependencyManager(DataDictionary dd)

Method Detail

addDependencyback to summary
public void addDependency(Dependent d, Provider p, ContextManager cm) throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.addDependency.

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.

Parameters
d:Dependent

the dependent

p:Provider

the provider

cm:ContextManager

Doc from org.apache.derby.iapi.sql.depend.DependencyManager.addDependency.

Current ContextManager

Exceptions
StandardException:
thrown if something goes wrong
addDependencyback to summary
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:Dependent

the dependent

p:Provider

the provider

cm:ContextManager

context manager

tc:TransactionController

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.

Exceptions
StandardException:
if adding the dependency fails
addDependencyToTableback to summary
private boolean addDependencyToTable(Map<UUID, 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

boolean Whether or not the dependency get added.

addInMemoryDependencyback to summary
private synchronized void addInMemoryDependency(Dependent d, Provider p, ContextManager cm) throws StandardException

Adds the dependency as an in-memory dependency.

Parameters
d:Dependent

the dependent

p:Provider

the provider

cm:ContextManager

context manager

Exceptions
StandardException:
if adding the dependency fails
See Also
addStoredDependency
addStoredDependencyback to summary
private void addStoredDependency(Dependent d, Provider p, ContextManager cm, TransactionController tc) throws StandardException

Adds the dependency as a stored dependency.

We expect that transactional locking (in the data dictionary) is enough to protect us from concurrent changes when adding stored dependencies. Adding synchronization here and accessing the data dictionary (which is transactional) may cause deadlocks.

Parameters
d:Dependent

the dependent

p:Provider

the provider

cm:ContextManager

context manager

tc:TransactionController

transaction controller (may be null)

Exceptions
StandardException:
if adding the dependency fails
See Also
addInMemoryDependency
clearColumnInfoInProvidersback to summary
public void clearColumnInfoInProviders(ProviderList pl) throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.clearColumnInfoInProviders.

Doc from org.apache.derby.iapi.sql.depend.DependencyManager.clearColumnInfoInProviders.

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.

Parameters
pl:ProviderList

provider list

Exceptions
StandardException:
Thrown on error
See Also
DependencyManager#clearColumnInfoInProviders
clearDependenciesback to summary
public void clearDependencies(LanguageConnectionContext lcc, Dependent d) throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.clearDependencies.

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.

Parameters
lcc:LanguageConnectionContext

Doc from org.apache.derby.iapi.sql.depend.DependencyManager.clearDependencies.

Compiler state

d:Dependent

the dependent

Exceptions
StandardException:
Thrown on failure
clearDependenciesback to summary
public void clearDependencies(LanguageConnectionContext lcc, Dependent d, TransactionController tc) throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.clearDependencies.

Doc from org.apache.derby.iapi.sql.depend.DependencyManager.clearDependencies.

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.

Parameters
lcc:LanguageConnectionContext

Compiler state

d:Dependent

the dependent

tc:TransactionController

transaction controller

Exceptions
StandardException:
Thrown on failure
clearInMemoryDependencyback to summary
public synchronized void clearInMemoryDependency(Dependency dy)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.clearInMemoryDependency.

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.)

clearProviderDependencyback to summary
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.

copyDependenciesback to summary
public void copyDependencies(Dependent copy_From, Dependent copyTo, boolean persistentOnly, ContextManager cm) throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.copyDependencies.

Copy dependencies from one dependent to another.

Parameters
copy_From:Dependent

the dependent to copy from

copyTo:Dependent

the dependent to copy to

persistentOnly:boolean

only copy persistent dependencies

cm:ContextManager

Current ContextManager

Exceptions
StandardException:
Thrown on error.
copyDependenciesback to summary
public void copyDependencies(Dependent copy_From, Dependent copyTo, boolean persistentOnly, ContextManager cm, TransactionController tc) throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.copyDependencies.

Doc from org.apache.derby.iapi.sql.depend.DependencyManager.copyDependencies.

Copy dependencies from one dependent to another.

Parameters
copy_From:Dependent

the dependent to copy from

copyTo:Dependent

the dependent to copy to

persistentOnly:boolean

only copy persistent dependencies

cm:ContextManager

Current ContextManager

tc:TransactionController

Transaction Controller

Exceptions
StandardException:
Thrown on error.
coreInvalidateForback to summary
private void coreInvalidateFor(Provider p, int action, LanguageConnectionContext lcc) throws StandardException

A version of invalidateFor that does not provide synchronization among invalidators.

Parameters
p:Provider

the provider

action:int

the action causing the invalidation

lcc:LanguageConnectionContext

language connection context

Exceptions
StandardException:
if something goes wrong
countDependenciesback to summary
public int countDependencies() throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.countDependencies.

Count the number of active dependencies, both stored and in memory, in the system.

Returns:int

int The number of active dependencies in the system.

Exceptions
StandardException:
thrown if something goes wrong
dropDependencyback to summary
private void dropDependency(LanguageConnectionContext lcc, Dependent d, Provider p) throws StandardException

drops a single dependency

Parameters
d:Dependent

the dependent

p:Provider

the provider

Exceptions
StandardException:
thrown if something goes wrong
getActionStringback to summary
public String getActionString(int action)

Implements org.apache.derby.iapi.sql.depend.DependencyManager.getActionString.

Returns a string representation of the SQL action, hence no need to internationalize, which is causing the invokation of the Dependency Manager.

Parameters
action:int

The action

Returns:String

String The String representation

getDependencyDescriptorListback to summary
private List<Dependency> getDependencyDescriptorList(List<DependencyDescriptor> storedList, Provider providerForList) throws StandardException

Turn a list of DependencyDescriptors into a list of Dependencies.

Parameters
storedList:List<DependencyDescriptor>

The List of DependencyDescriptors representing stored dependencies.

providerForList:Provider

The provider if this list is being created for a list of dependents. Null otherwise.

Returns:List<Dependency>

List The converted List

Exceptions
StandardException:
thrown if something goes wrong
getDependentsback to summary
private 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:Provider

the provider

Returns:List<Dependency>

A list of dependents (possibly empty).

Exceptions
StandardException:
if something goes wrong
getLanguageConnectionContextback to summary
private LanguageConnectionContext getLanguageConnectionContext(ContextManager cm)

Returns the LanguageConnectionContext to use.

Parameters
cm:ContextManager

Current ContextManager

Returns:LanguageConnectionContext

LanguageConnectionContext The LanguageConnectionContext to use.

getPersistentProviderInfosback to summary
public ProviderInfo[] getPersistentProviderInfos(Dependent dependent) throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.getPersistentProviderInfos.

Doc from org.apache.derby.iapi.sql.depend.DependencyManager.getPersistentProviderInfos.

Get a new array of ProviderInfos representing all the persistent providers for the given dependent.

Exceptions
StandardException:
Thrown on error
See Also
DependencyManager#getPersistentProviderInfos
getPersistentProviderInfosback to summary
public ProviderInfo[] getPersistentProviderInfos(ProviderList pl) throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.getPersistentProviderInfos.

Doc from org.apache.derby.iapi.sql.depend.DependencyManager.getPersistentProviderInfos.

Get a new array of ProviderInfos representing all the persistent providers from the given list of providers.

Exceptions
StandardException:
Thrown on error
See Also
DependencyManager#getPersistentProviderInfos
getProvidersback to summary
private 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:Dependent

the dependent

Returns:List<Provider>

A list of providers (possibly empty).

Exceptions
StandardException:
thrown if something goes wrong
invalidateForback to summary
public void invalidateFor(Provider p, int action, LanguageConnectionContext lcc) throws StandardException

Implements org.apache.derby.iapi.sql.depend.DependencyManager.invalidateFor.

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.

Parameters
p:Provider

the provider

action:int

The action causing the invalidate

lcc:LanguageConnectionContext

Doc from org.apache.derby.iapi.sql.depend.DependencyManager.invalidateFor.

The LanguageConnectionContext

Exceptions
StandardException:
thrown if unable to make it invalid