org.apache.ojb.broker.metadata
Class DescriptorRepository

java.lang.Object
  extended by org.apache.ojb.broker.metadata.DescriptorBase
      extended by org.apache.ojb.broker.metadata.DescriptorRepository
All Implemented Interfaces:
Serializable, IsolationLevels, AttributeContainer, RepositoryElements, XmlCapable

public final class DescriptorRepository
extends DescriptorBase
implements Serializable, XmlCapable, IsolationLevels

The repository containing all object mapping and manipulation information of all used persistent objects.
Note: Be careful when use references of this class or caching instances of this class, because instances could become invalid (see MetadataManager).

Version:
$Id: DescriptorRepository.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $
Author:
Thomas Mahler, Leandro Rodrigo Saad Cruz
See Also:
Serialized Form

Field Summary
private  int defaultIsolationLevel
          the default isolation level used for this repository
private  HashMap descriptorTable
          This table holds all known Mapping descriptions.
private  Map extentTable
          We need a lot the extent, to which a class belongs (@see DescriptorRepository#getExtentClass).
private  Logger log
           
private  Map m_allConcreteSubClass
           
private  Map m_firstConcreteClassMap
           
private  Map m_multiMappedTableMap
           
private  Map m_topLevelClassTable
           
(package private) static long serialVersionUID
           
private  Map superClassMultipleJoinedTablesMap
           
private static String VERSION
          The version identifier of the Repository.
 
Fields inherited from interface org.apache.ojb.broker.metadata.RepositoryElements
_NEXT, ACCEPT_LOCKS, ACCESS, ATTRIBUTE, ATTRIBUTE_NAME, ATTRIBUTE_VALUE, AUTO_DELETE, AUTO_INCREMENT, AUTO_RETRIEVE, AUTO_UPDATE, BATCH_MODE, CASCADE_LINK_STR, CASCADE_NONE_STR, CASCADE_OBJECT_STR, CLASS_DESCRIPTOR, CLASS_EXTENT, CLASS_NAME, CLASS_PROXY, CLASS_REF, COLLECTION_CLASS, COLLECTION_DESCRIPTOR, COLUMN_NAME, CON_LOG_ABANDONED, CON_MAX_ACTIVE, CON_MAX_IDLE, CON_MAX_WAIT, CON_MIN_EVICTABLE_IDLE_TIME_MILLIS, CON_NUM_TESTS_PER_EVICTION_RUN, CON_REMOVE_ABANDONED, CON_REMOVE_ABANDONED_TIMEOUT, CON_TEST_ON_BORROW, CON_TEST_ON_RETURN, CON_TEST_WHILE_IDLE, CON_TIME_BETWEEN_EVICTION_RUNS_MILLIS, CON_WHEN_EXHAUSTED_ACTION, CONNECTION_FACTORY, CONNECTION_POOL, CONSTANT_ARGUMENT, DATASOURCE_NAME, DBMS_NAME, DEFAULT_CONNECTION, DELETE_PROCEDURE, DOCUMENTATION, DRIVER_NAME, EAGER_RELEASE, EXTENDS, FACTORY_CLASS, FACTORY_METHOD, FIELD_CONVERSION, FIELD_DESCRIPTOR, FIELD_ID_REF, FIELD_NAME, FIELD_REF, FK_POINTING_TO_ITEMS_CLASS, FK_POINTING_TO_THIS_CLASS, FOREIGN_KEY, ID, IGNORE_AUTOCOMMIT_EXCEPTION, INCLUDE_ALL_FIELDS, INCLUDE_PK_FIELDS_ONLY, INDEX_COLUMN, INDEX_DESCRIPTOR, INDEXED, INDIRECTION_TABLE, INITIALIZATION_METHOD, INSERT_PROCEDURE, INVERSE_FK, ISOLATION_LEVEL, ITEMS_CLASS, JCD_ALIAS, JDBC_CONNECTION_DESCRIPTOR, JDBC_LEVEL, JDBC_TYPE, LENGTH, LOCKING, MAPPING_REPOSITORY, NAME, NULLABLE, OBJECT_CACHE, ORDERBY, OTM_DEPENDENT, PRECISION, PRIMARY_KEY, PROXY_PREFETCHING_LIMIT, PROXY_REFERENCE, QUERY_CUSTOMIZER, REFERENCE_DESCRIPTOR, REFERENCED_CLASS, REFRESH, REPOSITORY_VERSION, RETURN, RETURN_FIELD_REF, ROW_READER, RUNTIME_ARGUMENT, SCALE, SCHEMA_NAME, SEQUENCE_MANAGER, SEQUENCE_MANAGER_CLASS, SEQUENCE_NAME, SORT, TABLE_NAME, TAG_ACCESS, TAG_ACCESS_ANONYMOUS, TAG_ACCESS_READONLY, TAG_ACCESS_READWRITE, TAG_SUPER, UNIQUE, UPDATE_LOCK, UPDATE_PROCEDURE, URL_DBALIAS, URL_PROTOCOL, URL_SUBPROTOCOL, USE_AUTOCOMMIT, USER_NAME, USER_PASSWD, VALIDATION_QUERY, VALUE
 
Fields inherited from interface org.apache.ojb.broker.locking.IsolationLevels
IL_DEFAULT, IL_NONE, IL_OPTIMISTIC, IL_READ_COMMITTED, IL_READ_UNCOMMITTED, IL_REPEATABLE_READ, IL_SERIALIZABLE, LITERAL_IL_NONE, LITERAL_IL_OPTIMISTIC, LITERAL_IL_READ_COMMITTED, LITERAL_IL_READ_UNCOMMITTED, LITERAL_IL_REPEATABLE_READ, LITERAL_IL_SERIALIZABLE
 
Constructor Summary
DescriptorRepository()
          Constructor declaration
 
Method Summary
(package private)  void addExtent(String classname, ClassDescriptor cld)
          Add a pair of extent/classdescriptor to the extentTable to gain speed while retrieval of extents.
private  void changeDescriptorEvent()
           
private  void createResultSubClassesMultipleJoinedTables(List result, ClassDescriptor cld, boolean wholeTree)
          Add all sub-classes using multiple joined tables feature for specified class.
protected  void deregisterSuperClassMultipleJoinedTables(ClassDescriptor cld)
          Internal used! Deregister sub-classes of specified class when mapping to multiple joined tables is used.
private  ClassDescriptor discoverDescriptor(Class clazz)
          Internal method for recursivly searching for a class descriptor that avoids class loading when we already have a class object.
protected  ClassDescriptor discoverDescriptor(String className)
          Starts by looking to see if the className is already mapped specifically to the descritpor repository.
protected  void finalize()
           
 ClassDescriptor findFirstConcreteClass(ClassDescriptor cld)
          Return the first found concrete class ClassDescriptor.
 Collection getAllConcreteSubclassDescriptors(ClassDescriptor aCld)
          Utility method to discover all concrete subclasses of a given super class.
private  FieldDescriptor[] getAllMappedColumns(List classDescriptors)
           
private  List getClassesMappedToSameTable(ClassDescriptor targetCld)
           
 int getDefaultIsolationLevel()
          Returns the defaultIsolationLevel.
 ClassDescriptor getDescriptorFor(Class c)
          lookup a ClassDescriptor in the internal Hashtable
 ClassDescriptor getDescriptorFor(String strClassName)
          lookup a ClassDescriptor in the internal Hashtable
 Map getDescriptorTable()
           
 FieldDescriptor[] getFieldDescriptorsForMultiMappedTable(ClassDescriptor targetCld)
           
protected  String getIsolationLevelAsString()
          returns IsolationLevel literal as matching to the corresponding id
 Class[] getSubClassesMultipleJoinedTables(ClassDescriptor cld, boolean wholeTree)
          Return sub-classes of the specified class using the "super"-Reference concept.
 Class getTopLevelClass(Class clazz)
          Returns the top level (extent) class to which the given class belongs.
static String getVersion()
           
 boolean hasDescriptorFor(Class c)
          Checks if repository contains given class.
 Iterator iterator()
          Returns an iterator over all managed ClassDescriptor.
 void put(Class c, ClassDescriptor cld)
          Add a ClassDescriptor to the internal Hashtable
Set the Repository for ClassDescriptor
 void put(String classname, ClassDescriptor cld)
          Add a ClassDescriptor to the internal Hashtable
Set the Repository for ClassDescriptor
protected  void registerSuperClassMultipleJoinedTables(ClassDescriptor cld)
          Internal used! Register sub-classes of specified class when mapping class to multiple joined tables is used.
 void remove(Class clazz)
           
 void remove(String className)
           
(package private)  void removeExtent(String classname)
          Remove a pair of extent/classdescriptor from the extentTable.
 void setClassDescriptor(ClassDescriptor cld)
          Convenience for put(Class c, ClassDescriptor cld)
 void setDefaultIsolationLevel(int defaultIsolationLevel)
          Sets the defaultIsolationLevel.
 String toString()
          returns a string representation
 String toXML()
          returns the XML marshalled version of this instance.
 
Methods inherited from class org.apache.ojb.broker.metadata.DescriptorBase
addAttribute, getAttribute, getAttribute, getAttributeNames, getAttributes
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

log

private Logger log

VERSION

private static final String VERSION
The version identifier of the Repository. Used to validate repository.xml against the dtd.

See Also:
Constant Field Values

defaultIsolationLevel

private int defaultIsolationLevel
the default isolation level used for this repository


descriptorTable

private final HashMap descriptorTable
This table holds all known Mapping descriptions. Key values are the respective Class objects


extentTable

private Map extentTable
We need a lot the extent, to which a class belongs (@see DescriptorRepository#getExtentClass). To speed up the costy evaluation, we use this tiny hash map.


superClassMultipleJoinedTablesMap

private Map superClassMultipleJoinedTablesMap

m_multiMappedTableMap

private transient Map m_multiMappedTableMap

m_topLevelClassTable

private transient Map m_topLevelClassTable

m_firstConcreteClassMap

private transient Map m_firstConcreteClassMap

m_allConcreteSubClass

private transient Map m_allConcreteSubClass
Constructor Detail

DescriptorRepository

public DescriptorRepository()
                     throws PersistenceBrokerException
Constructor declaration

Throws:
PersistenceBrokerException
Method Detail

getVersion

public static String getVersion()

addExtent

void addExtent(String classname,
               ClassDescriptor cld)
Add a pair of extent/classdescriptor to the extentTable to gain speed while retrieval of extents.

Parameters:
classname - the name of the extent itself
cld - the class descriptor, where it belongs to

removeExtent

void removeExtent(String classname)
Remove a pair of extent/classdescriptor from the extentTable.

Parameters:
classname - the name of the extent itself

getTopLevelClass

public Class getTopLevelClass(Class clazz)
                       throws ClassNotPersistenceCapableException
Returns the top level (extent) class to which the given class belongs. This may be a (abstract) base-class, an interface or the given class itself if given class is not defined as an extent in other class descriptors.

Throws:
ClassNotPersistenceCapableException - if clazz is not persistence capable, i.e. if clazz is not defined in the DescriptorRepository.

getFieldDescriptorsForMultiMappedTable

public FieldDescriptor[] getFieldDescriptorsForMultiMappedTable(ClassDescriptor targetCld)
Returns:
all field descriptors for a class that belongs to a set of classes mapped to the same table, otherwise the select queries produced won't contain the necessary information to materialize extents mapped to the same class.

getAllMappedColumns

private FieldDescriptor[] getAllMappedColumns(List classDescriptors)

getClassesMappedToSameTable

private List getClassesMappedToSameTable(ClassDescriptor targetCld)

getDescriptorTable

public Map getDescriptorTable()

findFirstConcreteClass

public ClassDescriptor findFirstConcreteClass(ClassDescriptor cld)
Return the first found concrete class ClassDescriptor. This means a class which is not an interface or an abstract class. If given class descriptor is a concrete class, given class descriptor was returned. If no concrete class can be found null will be returned.


getAllConcreteSubclassDescriptors

public Collection getAllConcreteSubclassDescriptors(ClassDescriptor aCld)
Utility method to discover all concrete subclasses of a given super class.
This method was introduced in order to get Extent Aware Iterators.

Returns:
a Collection of ClassDescriptor objects

hasDescriptorFor

public boolean hasDescriptorFor(Class c)
Checks if repository contains given class.


getDescriptorFor

public ClassDescriptor getDescriptorFor(String strClassName)
                                 throws ClassNotPersistenceCapableException
lookup a ClassDescriptor in the internal Hashtable

Parameters:
strClassName - a fully qualified class name as it is returned by Class.getName().
Throws:
ClassNotPersistenceCapableException

getDescriptorFor

public ClassDescriptor getDescriptorFor(Class c)
                                 throws ClassNotPersistenceCapableException
lookup a ClassDescriptor in the internal Hashtable

Throws:
ClassNotPersistenceCapableException

setClassDescriptor

public void setClassDescriptor(ClassDescriptor cld)
Convenience for put(Class c, ClassDescriptor cld)


put

public void put(Class c,
                ClassDescriptor cld)
Add a ClassDescriptor to the internal Hashtable
Set the Repository for ClassDescriptor


put

public void put(String classname,
                ClassDescriptor cld)
Add a ClassDescriptor to the internal Hashtable
Set the Repository for ClassDescriptor


remove

public void remove(String className)

remove

public void remove(Class clazz)

changeDescriptorEvent

private void changeDescriptorEvent()

iterator

public Iterator iterator()
Returns an iterator over all managed ClassDescriptor.


getDefaultIsolationLevel

public int getDefaultIsolationLevel()
Returns the defaultIsolationLevel.

Returns:
int

setDefaultIsolationLevel

public void setDefaultIsolationLevel(int defaultIsolationLevel)
Sets the defaultIsolationLevel.

Parameters:
defaultIsolationLevel - The defaultIsolationLevel to set

toString

public String toString()
returns a string representation

Overrides:
toString in class DescriptorBase

toXML

public String toXML()
Description copied from interface: XmlCapable
returns the XML marshalled version of this instance.

Specified by:
toXML in interface XmlCapable
Returns:
the XML String representing this object.

getIsolationLevelAsString

protected String getIsolationLevelAsString()
returns IsolationLevel literal as matching to the corresponding id

Returns:
the IsolationLevel literal

discoverDescriptor

protected ClassDescriptor discoverDescriptor(String className)
Starts by looking to see if the className is already mapped specifically to the descritpor repository. If the className is not specifically mapped we look at the className's parent class for a mapping. We do this until the parent class is of the type java.lang.Object. If no mapping was found, null is returned. Mappings successfuly discovered through inheritence are added to the internal table of class descriptors to improve performance on subsequent requests for those classes.
author Scott T. Weaver

Parameters:
className - name of class whose descriptor we need to find.
Returns:
ClassDescriptor for className or null if no ClassDescriptor could be located.

discoverDescriptor

private ClassDescriptor discoverDescriptor(Class clazz)
Internal method for recursivly searching for a class descriptor that avoids class loading when we already have a class object.

Parameters:
clazz - The class whose descriptor we need to find
Returns:
ClassDescriptor for clazz or null if no ClassDescriptor could be located.

registerSuperClassMultipleJoinedTables

protected void registerSuperClassMultipleJoinedTables(ClassDescriptor cld)
Internal used! Register sub-classes of specified class when mapping class to multiple joined tables is used. Normally this method is called by the ClassDescriptor itself.

Parameters:
cld - The ClassDescriptor of the class to register.

deregisterSuperClassMultipleJoinedTables

protected void deregisterSuperClassMultipleJoinedTables(ClassDescriptor cld)
Internal used! Deregister sub-classes of specified class when mapping to multiple joined tables is used. Normally this method is called when remove(Class) a class.

Parameters:
cld - The ClassDescriptor of the class to register.

getSubClassesMultipleJoinedTables

public Class[] getSubClassesMultipleJoinedTables(ClassDescriptor cld,
                                                 boolean wholeTree)
Return sub-classes of the specified class using the "super"-Reference concept.

Parameters:
cld - The ClassDescriptor of the class to search for sub-classes.
wholeTree - If set true, the whole sub-class tree of the specified class will be returned. If false only the direct sub-classes of the specified class will be returned.
Returns:
An array of sub-classes for the specified class.

createResultSubClassesMultipleJoinedTables

private void createResultSubClassesMultipleJoinedTables(List result,
                                                        ClassDescriptor cld,
                                                        boolean wholeTree)
Add all sub-classes using multiple joined tables feature for specified class.

Parameters:
result - The list to add results.
cld - The ClassDescriptor of the class to search for sub-classes.
wholeTree - If set true, the whole sub-class tree of the specified class will be returned. If false only the direct sub-classes of the specified class will be returned.

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable


Copyright © 2007-2012 The Kuali Foundation. All Rights Reserved.