Java Doc for DependencyManager.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » iapi » sql » depend » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.iapi.sql.depend 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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

All known Subclasses:   org.apache.derby.impl.sql.depend.BasicDependencyManager,
DependencyManager
public interface DependencyManager (Code)
Dependency Manager Interface

The dependency manager tracks needs that dependents have of providers. This is a general purpose interface which is associated with a DataDictinary object; infact the dependencymanager is really the datadictionary keeping track of dependcies between objects that it handles (descriptors) as well as prepared statements.

The primary example of this is a prepared statement's needs of schema objects such as tables.

Dependencies are used so that we can determine when we need to recompile a statement; compiled statements depend on schema objects like tables and constraints, and may no longer be executable when those tables or constraints are altered. For example, consider an insert statement.

An insert statement is likely to have dependencies on the table it inserts into, any tables it selects from (including subqueries), the authorities it uses to do this, and any constraints or triggers it needs to check.

A prepared insert statement has a dependency on the target table of the insert. When it is compiled, that dependency is registered from the prepared statement on the data dictionary entry for the table. This dependency is added to the prepared statement's dependency list, which is also accessible from an overall dependency pool.

A DDL statement will mark invalid any prepared statement that depends on the schema object the DDL statement is altering or dropping. We tend to want to track at the table level rather than the column or constraint level, so that we are not overburdened with dependencies. This does mean that we may invalidate when in fact we do not need to; for example, adding a column to a table may not actually cause an insert statement compiled for that table to stop working; but our level of granularity may force us to invalidate the insert because it has to invalidate all statements that depend on the table due to some of them actually no longer being valid. It is up to the user of the dependency system at what granularity to track dependencies, where to hang them, and how to identify when objects become invalid. The dependency system is basically supplying the ability to find out who is interested in knowing about other, distinct operations. The primary user is the language system, and its primary use is for invalidating prepared statements when DDL occurs.

The insert will recompile itself when its next execution is requested (not when it is invalidated). We don't want it to recompile when the DDL is issued, as that would increase the time of execution of the DDL command unacceptably. Note that the DDL command is also allowed to proceed even if it would make the statement no longer compilable. It can be useful to have a way to recompile invalid statements during idle time in the system, but our first implementation will simply recompile at the next execution.

The start of a recompile will release the connection to all dependencies when it releases the activation class and generates a new one.

The Dependency Manager is capable of storing dependencies to ensure that other D.M.s can see them and invalidate them appropriately. The dependencies in memory only the current D.M. can see; the stored dependencies are visible to other D.M.s once the transaction in which they were stored is committed.

REVISIT: Given that statements are compiled in a separate top-transaction from their execution, we may need/want some intermediate memory storage that makes the dependencies visible to all D.M.s in the system, without requiring that they be stored.

To ensure that dependencies are cleaned up when a statement is undone, the compiler context needs to keep track of what dependent it was creating dependencies for, and if it is informed of a statement exception that causes it to throw out the statement it was compiling, it should also call the dependency manager to have the dependencies removed.

Several expansions of the basic interface may be desirable:

  • to note a type of dependency, and to invalidate or perform an invalidation action based on dependency type
  • to note a type of invalidation, so the revalidation could actually take some action other than recompilation, such as simply ensuring the provider objects still existed.
  • to control the order of invalidation, so that if (for example) the invalidation action actually includes the revalidation attempt, revalidation is not attempted until all invalidations have occurred.
  • to get a list of dependencies that a Dependent or a Provider has (this is included in the above, although the basic system does not need to expose the list).
  • to find out which of the dependencies for a dependent were marked invalid.

To provide a simple interface that satisfies the basic need, and yet supply more advanced functionality as well, we will present the simple functionality as defaults and provide ways to specify the more advanced functionality.

 interface Dependent {
 boolean isValid();
 InvalidType getInvalidType(); // returns what it sees
 // as the "most important"
 // of its invalid types.
 void makeInvalid( );
 void makeInvalid( DependencyType dt, InvalidType it );
 void makeValid();
 }
 interface Provider() {
 }
 interface Dependency() {
 Provider getProvider();
 Dependent getDependent();
 DependencyType getDependencyType();
 boolean isValid();
 InvalidType getInvalidType(); // returns what it sees
 // as the "most important"
 // of its invalid types.
 }
 interface DependencyManager() {
 void addDependency(Dependent d, Provider p, ContextManager cm);
 void invalidateFor(Provider p);
 void invalidateFor(Provider p, DependencyType dt, InvalidType it);
 void clearDependencies(Dependent d);
 void clearDependencies(Dependent d, DependencyType dt);
 Enumeration getProviders (Dependent d);
 Enumeration getProviders (Dependent d, DependencyType dt);
 Enumeration getInvalidDependencies (Dependent d, 
 DependencyType dt, InvalidType it);
 Enumeration getDependents (Provider p);
 Enumeration getDependents (Provider p, DependencyType dt);
 Enumeration getInvalidDependencies (Provider p, 
 DependencyType dt, InvalidType it);
 }
 

The simplest things for DependencyType and InvalidType to be are integer id's or strings, rather than complex objects.

In terms of ensuring that no makeInvalid calls are made until we have identified all objects that could be, so that the calls will be made from "leaf" invalid objects (those not in turn relied on by other dependents) to dependent objects upon which others depend, the dependency manager will need to maintain an internal queue of dependencies and make the calls once it has completes its analysis of the dependencies of which it is aware. Since it is much simpler and potentially faster for makeInvalid calls to be made as soon as the dependents are identified, separate implementations may be called for, or separate interfaces to trigger the different styles of invalidation.

In terms of separate interfaces, the DependencyManager might have two methods,

 void makeInvalidImmediate();
 void makeInvalidOrdered();
 
or a flag on the makeInvalid method to choose the style to use.

In terms of separate implementations, the ImmediateInvalidate manager might have simpler internal structures for tracking dependencies than the OrderedInvalidate manager.

The language system doesn't tend to suffer from this ordering problem, as it tends to handle the impact of invalidation by simply deferring recompilation until the next execution. So, a prepared statement might be invalidated several times by a transaction that contains several DDL operations, and only recompiled once, at its next execution. This is sufficient for the common use of a system, where DDL changes tend to be infrequent and clustered.

There could be ways to push this "ordering problem" out of the dependency system, but since it knows when it starts and when it finished finding all of the invalidating actions, it is likely the best home for this.

One other problem that could arise is multiple invalidations occurring one after another. The above design of the dependency system can really only react to each invalidation request as a unit, not to multiple invalidation requests.

Another extension that might be desired is for the dependency manager to provide for cascading invalidations -- that is, if it finds and marks one Dependent object as invalid, if that object can also be a provider, to look for its dependent objects and cascade the dependency on to them. This can be a way to address the multiple-invalidation request need, if it should arise. The simplest way to do this is to always cascade the same invalidation type; otherwise, dependents need to be able to say what a certain type of invalidation type gets changed to when it is handed on.

The basic language system does not need support for cascaded dependencies -- statements do not depend on other statements in a way that involves the dependency system.

I do not know if it would be worthwhile to consider using the dependency manager to aid in the implementation of the SQL DROP statements or not. Past implementations of database systems have not used the dependency system to implement this functionality, but have instead hard-coded the lookups like so:

 in DropTable:
 scan the TableAuthority table looking for authorities on
 this table; drop any that are found.
 scan the ColumnAuthority table looking for authorities on
 this table; drop any that are found.
 scan the View table looking for views on
 this table; drop any that are found.
 scan the Column table looking for rows for columns of
 this table; drop any that are found.
 scan the Constraint table looking for rows for constraints of
 this table; drop any that are found.
 scan the Index table looking for rows for indexes of
 this table; drop the indexes, and any rows that are found.
 drop the table's conglomerate
 drop the table's row in the Table table.
 

The direct approach such as that outlined in the example will probably be quicker and is definitely "known technology" over the use of a dependency system in this area.



Field Summary
final public static  intALTER_TABLE
    
final public static  intBULK_INSERT
    
final public static  intCHANGED_CURSOR
    
final public static  intCOMPILE_FAILED
    
final public static  intCOMPRESS_TABLE
    
final public static  intCREATE_CONSTRAINT
    
final public static  intCREATE_INDEX
    
final public static  intCREATE_TRIGGER
    
final public static  intCREATE_VIEW
    
final public static  intDROP_COLUMN
    
final public static  intDROP_CONSTRAINT
    
final public static  intDROP_INDEX
    
final public static  intDROP_JAR
    
final public static  intDROP_METHOD_ALIAS
    
final public static  intDROP_SCHEMA
    
final public static  intDROP_SPS
    
final public static  intDROP_STATISTICS
    
final public static  intDROP_SYNONYM
    
final public static  intDROP_TABLE
    
final public static  intDROP_TRIGGER
    
final public static  intDROP_VIEW
    
final public static  intINTERNAL_RECOMPILE_REQUEST
    
final public static  intMAX_ACTION_CODE
     Extensions to this interface may use action codes > MAX_ACTION_CODE without fear of clashing with action codes in this base interface.
final public static  intMODIFY_COLUMN_DEFAULT
    
final public static  intPREPARED_STATEMENT_RELEASE
    
final public static  intRENAME
    
final public static  intRENAME_INDEX
    
final public static  intREPLACE_JAR
    
final public static  intREVOKE_PRIVILEGE
    
final public static  intREVOKE_PRIVILEGE_RESTRICT
    
final public static  intROLLBACK
    
final public static  intSET_CONSTRAINTS_DISABLE
    
final public static  intSET_CONSTRAINTS_ENABLE
    
final public static  intSET_TRIGGERS_DISABLE
    
final public static  intSET_TRIGGERS_ENABLE
    
final public static  intTRUNCATE_TABLE
    
final public static  intUPDATE_STATISTICS
    
final public static  intUSER_RECOMPILE_REQUEST
    


Method Summary
 voidaddDependency(Dependent d, Provider p, ContextManager cm)
     adds a dependency from the dependent on the provider.
public  voidclearColumnInfoInProviders(ProviderList pl)
     Clear the in memory column bit map information in any table descriptor provider in a provider list.
 voidclearDependencies(LanguageConnectionContext lcc, Dependent d)
     Erases all of the dependencies the dependent has, be they valid or invalid, of any dependency type.
public  voidclearDependencies(LanguageConnectionContext lcc, Dependent d, TransactionController tc)
     Erases all of the dependencies the dependent has, be they valid or invalid, of any dependency type.
public  voidclearInMemoryDependency(Dependency dy)
     Clear the specified in memory dependency.
public  voidcopyDependencies(Dependent copy_From, Dependent copyTo, boolean persistentOnly, ContextManager cm)
     Copy dependencies from one dependent to another.
public  voidcopyDependencies(Dependent copy_From, Dependent copyTo, boolean persistentOnly, ContextManager cm, TransactionController tc)
     Copy dependencies from one dependent to another.
public  intcountDependencies()
     Count the number of active dependencies, both stored and in memory, in the system.
public  StringdumpDependencies()
     Dump out debugging info on all of the dependencies currently within the system.
 StringgetActionString(int action)
     Returns a string representation of the SQL action, hence no need to internationalize, which is causing the invokation of the Dependency Manager.
public  ProviderInfo[]getPersistentProviderInfos(Dependent dependent)
     Get a new array of ProviderInfos representing all the persistent providers for the given dependent.
public  ProviderInfo[]getPersistentProviderInfos(ProviderList pl)
     Get a new array of ProviderInfos representing all the persistent providers from the given list of providers.
 voidinvalidateFor(Provider p, int action, LanguageConnectionContext lcc)
     mark all dependencies on the named provider as invalid. When invalidation types show up, this will use the default invalidation type.

Field Detail
ALTER_TABLE
final public static int ALTER_TABLE(Code)



BULK_INSERT
final public static int BULK_INSERT(Code)



CHANGED_CURSOR
final public static int CHANGED_CURSOR(Code)



COMPILE_FAILED
final public static int COMPILE_FAILED(Code)



COMPRESS_TABLE
final public static int COMPRESS_TABLE(Code)



CREATE_CONSTRAINT
final public static int CREATE_CONSTRAINT(Code)



CREATE_INDEX
final public static int CREATE_INDEX(Code)



CREATE_TRIGGER
final public static int CREATE_TRIGGER(Code)



CREATE_VIEW
final public static int CREATE_VIEW(Code)



DROP_COLUMN
final public static int DROP_COLUMN(Code)



DROP_CONSTRAINT
final public static int DROP_CONSTRAINT(Code)



DROP_INDEX
final public static int DROP_INDEX(Code)



DROP_JAR
final public static int DROP_JAR(Code)



DROP_METHOD_ALIAS
final public static int DROP_METHOD_ALIAS(Code)



DROP_SCHEMA
final public static int DROP_SCHEMA(Code)



DROP_SPS
final public static int DROP_SPS(Code)



DROP_STATISTICS
final public static int DROP_STATISTICS(Code)



DROP_SYNONYM
final public static int DROP_SYNONYM(Code)



DROP_TABLE
final public static int DROP_TABLE(Code)



DROP_TRIGGER
final public static int DROP_TRIGGER(Code)



DROP_VIEW
final public static int DROP_VIEW(Code)



INTERNAL_RECOMPILE_REQUEST
final public static int INTERNAL_RECOMPILE_REQUEST(Code)



MAX_ACTION_CODE
final public static int MAX_ACTION_CODE(Code)
Extensions to this interface may use action codes > MAX_ACTION_CODE without fear of clashing with action codes in this base interface.



MODIFY_COLUMN_DEFAULT
final public static int MODIFY_COLUMN_DEFAULT(Code)



PREPARED_STATEMENT_RELEASE
final public static int PREPARED_STATEMENT_RELEASE(Code)



RENAME
final public static int RENAME(Code)



RENAME_INDEX
final public static int RENAME_INDEX(Code)



REPLACE_JAR
final public static int REPLACE_JAR(Code)



REVOKE_PRIVILEGE
final public static int REVOKE_PRIVILEGE(Code)



REVOKE_PRIVILEGE_RESTRICT
final public static int REVOKE_PRIVILEGE_RESTRICT(Code)



ROLLBACK
final public static int ROLLBACK(Code)



SET_CONSTRAINTS_DISABLE
final public static int SET_CONSTRAINTS_DISABLE(Code)



SET_CONSTRAINTS_ENABLE
final public static int SET_CONSTRAINTS_ENABLE(Code)



SET_TRIGGERS_DISABLE
final public static int SET_TRIGGERS_DISABLE(Code)



SET_TRIGGERS_ENABLE
final public static int SET_TRIGGERS_ENABLE(Code)



TRUNCATE_TABLE
final public static int TRUNCATE_TABLE(Code)



UPDATE_STATISTICS
final public static int UPDATE_STATISTICS(Code)



USER_RECOMPILE_REQUEST
final public static int USER_RECOMPILE_REQUEST(Code)





Method Detail
addDependency
void addDependency(Dependent d, Provider p, ContextManager cm) throws StandardException(Code)
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 - the dependent
Parameters:
  p - the provider
Parameters:
  cm - Current ContextManager
exception:
  StandardException - thrown if something goes wrong




clearColumnInfoInProviders
public void clearColumnInfoInProviders(ProviderList pl) throws StandardException(Code)
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.
exception:
  StandardException - Thrown on error.



clearDependencies
void clearDependencies(LanguageConnectionContext lcc, Dependent d) throws StandardException(Code)
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 - Compiler state
Parameters:
  d - the dependent
exception:
  StandardException - Thrown on failure




clearDependencies
public void clearDependencies(LanguageConnectionContext lcc, Dependent d, TransactionController tc) throws StandardException(Code)
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 - Compiler state
Parameters:
  d - the dependent
Parameters:
  tc - transaction controller
exception:
  StandardException - Thrown on failure




clearInMemoryDependency
public void clearInMemoryDependency(Dependency dy)(Code)
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.) This method will handle Dependency's that have already been removed from the DependencyManager.



copyDependencies
public void copyDependencies(Dependent copy_From, Dependent copyTo, boolean persistentOnly, ContextManager cm) throws StandardException(Code)
Copy dependencies from one dependent to another.
Parameters:
  copy_From - the dependent to copy from
Parameters:
  copyTo - the dependent to copy to
Parameters:
  persistentOnly - only copy persistent dependencies
Parameters:
  cm - Current ContextManager
exception:
  StandardException - Thrown on error.



copyDependencies
public void copyDependencies(Dependent copy_From, Dependent copyTo, boolean persistentOnly, ContextManager cm, TransactionController tc) throws StandardException(Code)
Copy dependencies from one dependent to another.
Parameters:
  copy_From - the dependent to copy from
Parameters:
  copyTo - the dependent to copy to
Parameters:
  persistentOnly - only copy persistent dependencies
Parameters:
  cm - Current ContextManager
Parameters:
  tc - Transaction Controller
exception:
  StandardException - Thrown on error.



countDependencies
public int countDependencies() throws StandardException(Code)
Count the number of active dependencies, both stored and in memory, in the system. int The number of active dependencies in the system.
exception:
  StandardException - thrown if something goes wrong



dumpDependencies
public String dumpDependencies() throws StandardException, java.sql.SQLException(Code)
Dump out debugging info on all of the dependencies currently within the system. String Debugging info on the dependencies.(null if SanityManger.DEBUG is false)
exception:
  StandardException - thrown if something goes wrong
exception:
  java.sql.SQLException - thrown if something goes wrong



getActionString
String getActionString(int action)(Code)
Returns a string representation of the SQL action, hence no need to internationalize, which is causing the invokation of the Dependency Manager.
Parameters:
  action - The action String The String representation



getPersistentProviderInfos
public ProviderInfo[] getPersistentProviderInfos(Dependent dependent) throws StandardException(Code)
Get a new array of ProviderInfos representing all the persistent providers for the given dependent.
exception:
  StandardException - Thrown on error.



getPersistentProviderInfos
public ProviderInfo[] getPersistentProviderInfos(ProviderList pl) throws StandardException(Code)
Get a new array of ProviderInfos representing all the persistent providers from the given list of providers.
exception:
  StandardException - Thrown on error.



invalidateFor
void invalidateFor(Provider p, int action, LanguageConnectionContext lcc) throws StandardException(Code)
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 DependencyStatementException if the invalidation should be disallowed.
Parameters:
  p - the provider
Parameters:
  action - The action causing the invalidate
Parameters:
  lcc - The LanguageConnectionContext
exception:
  StandardException - thrown if unable to make it invalid




www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.