org.objectweb.jorm.mapper.rdb.metainfo
Class RdbClassMapping

java.lang.Object
  extended byorg.objectweb.jorm.metainfo.lib.BasicMetaObject
      extended byorg.objectweb.jorm.metainfo.lib.BasicMappingStructure
          extended byorg.objectweb.jorm.metainfo.lib.BasicCommonClassMapping
              extended byorg.objectweb.jorm.metainfo.lib.BasicClassMapping
                  extended byorg.objectweb.jorm.mapper.rdb.metainfo.RdbClassMapping
All Implemented Interfaces:
ClassMapping, CommonClassMapping, Loggable, MappingStructure, MetaObject, java.io.Serializable
Direct Known Subclasses:
RdbClassMultiMapping

public class RdbClassMapping
extends BasicClassMapping

This class defines information on the mapping of a class to relational structures In the case of inheritance, one must defines how the mapping definitions are inherited, and how to distinguish instances of the class to instances of super or sub classes. Following the partitionning schemes in relational database we defines three ways to inherit the mapping of its parent. In the case of multi-inheritance, all combinations are valid. One can map new fields relative to class A to new columns or tables (to-extended or to-added rules) while the resulting stuctures being completely redefined relatively to the ones of another class B (to-new rule). One class can also inherits with a to-added or to-extended rule from class A and also with a to-added or to-exended rule from another class B provided they map their id the same way, which implies that they have the same main table. One limitation is relative to the "abscractness" of the classes. In fact, the inheritance rules are those of Java. That is, a class cannot inherit from more than one concrete class (the 'extends' keyword is limited to only one class). Note that Jorm support abstract classes inheriting from concrete classes, even though this has no sense from a persistance point of view. The reason is that Jorm is used to map Java classes to persistant ones, that Java authorizes abstract classes deriving from concrete classes by defining new abstract methods. Even though methods are not translated in a persistance point of view since they do not represent fields (exception made of accessors), we need to represent the abstract classes since there may exist references of this abstract class.

See Also:
Serialized Form

Field Summary
static java.lang.String MAP_NEW_FIELDS_TO_ADDED_STRUCTURES
          Specifies that the structures and the mapping of the parent is inherited, new structures are added (i.e. new tables are added) and the some of new fields are mapped to this new structures.
static java.lang.String MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES
          Specifies that the structures and the mapping of the parent is inherited, the structures are extended (i.e. new columns are defined in existing tables) and the new fields are mapped to this extension.
static java.lang.String REMAP_FIELDS_TO_NEW_STRUCTURES
          Specifies that neither the structures nor the mapping is inherited, structures are completely redefined (i.e. new tables are defined) and ALL the fields (defined in the class or previously defined in super classes are remapped to this new structures.
 
Fields inherited from class org.objectweb.jorm.metainfo.lib.BasicClassMapping
parentClassMappings
 
Fields inherited from class org.objectweb.jorm.metainfo.lib.BasicMappingStructure
linkedMO
 
Fields inherited from class org.objectweb.jorm.metainfo.lib.BasicMetaObject
debug, logger, loggerFactory, parent
 
Constructor Summary
RdbClassMapping(java.lang.String ruleName, MetaObject linkedMO, MetaObject parent)
          Builds a new BasicRdbClassMapping object.
 
Method Summary
 void addImplicitDependencies()
          The creation of tables cannot be done until all columns are known and those columns can be defined in the super and subclasses with wich there is a 'to-extended' or a 'to-added' inheritance rule.
 ParentClassMapping createImplicitParentClassMapping(Class superClass)
          Creates a implicit parent class mapping.
 RdbFilter createRdbFilter()
           
 RdbInheritanceQuery createRdbInheritanceQuery()
           
 RdbTable createRdbTable(java.lang.String tableName)
           
 java.util.Set getAddedOrExtendedParentClassMapping()
          Returns the parent class mappings having an extened or added inheritance rule.
 java.util.List getAllPrimitiveElementMappings()
          Returns the list of PEM of the current class and its super classes.
protected  java.util.Collection getChildren()
           
 RdbTable getMainRdbTable()
           
 void getMainRdbTableOld(java.util.ArrayList res)
          Get the main table (tables ??).
 Expression getMappingFilterFromNamingFilter()
           
 Expression getMappingFilterFromNamingFilter(NamingFilterKeyProvider nfkp)
           
 java.util.Set getParentClassMapping(java.util.Set inheritanceRules)
          Returns the parent class mappings having a inheritance rule in a set of inheritance rules.
 PrimitiveElementMapping getPrimitiveElementMapping(java.lang.String fieldName, boolean searchInSuper)
          Get the primitive element mapping corresponding to a field name by searching recursively in the super classes until it is found (if requested)
 RdbFilter getRdbFilter()
           
 RdbInheritanceQuery getRdbInheritanceQuery()
           
 RdbTable getRdbTable()
           
 boolean hasUnmappedPrimitiveElements(java.util.Collection pes)
          Check if any (hidden) field defined in the class (or its supers) has a defined mapping (defined in the class mapping or in it supers)
 boolean inheritsStructures()
           
 boolean inheritsStructures(ParentClassMapping pcm)
           
 
Methods inherited from class org.objectweb.jorm.metainfo.lib.BasicClassMapping
addParentClassMapping, addReferenceMapping, createParentClassMapping, createReferenceMapping, getJormClass, getParentClassMapping, getParentClassMappings, getReferenceMapping, getReferenceMappings, iterateParentClassMappings, iterateReferenceMappings
 
Methods inherited from class org.objectweb.jorm.metainfo.lib.BasicCommonClassMapping
addDependency, addPrimitiveElementMapping, addPrimitiveElementMapping, createIdentifierMapping, getDependencies, getIdentifierMapping, getPrimitiveElementMapping, getPrimitiveElementMappings, getRuleName, primitiveElementMappingsIterator, removeDependency, setIdentifierMapping, setRuleName
 
Methods inherited from class org.objectweb.jorm.metainfo.lib.BasicMappingStructure
getLinkedMO, getMapperName, getProjectName, setLinkedMO
 
Methods inherited from class org.objectweb.jorm.metainfo.lib.BasicMetaObject
getLogger, getLoggerFactory, getManager, getParent, setLogger, setLoggerFactory, setLoggingOnChild, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.jorm.metainfo.api.CommonClassMapping
addDependency, addPrimitiveElementMapping, addPrimitiveElementMapping, createIdentifierMapping, getDependencies, getIdentifierMapping, getPrimitiveElementMapping, getPrimitiveElementMappings, getRuleName, primitiveElementMappingsIterator, removeDependency, setIdentifierMapping, setRuleName
 
Methods inherited from interface org.objectweb.jorm.metainfo.api.MappingStructure
getLinkedMO, getMapperName, getProjectName, setLinkedMO
 
Methods inherited from interface org.objectweb.jorm.metainfo.api.MetaObject
getParent, setParent
 

Field Detail

MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES

public static final java.lang.String MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES
Specifies that the structures and the mapping of the parent is inherited, the structures are extended (i.e. new columns are defined in existing tables) and the new fields are mapped to this extension. This merely corresponds to a 'filtered' case but can cover the case of concrete classes where a filter can be defined, and the case of abstract classes where only the mapping is extended and no filter is defined. This implies that concrete classes having this inheritance rule MUST define a filter. Note that when no parent class mapping is defined, a default one is created with this rule, with no new mapping and no filters. That is, the mapping and structures are inherited as is, unchanged. This prevent us from defining a new 'unchanged' rule.

See Also:
Constant Field Values

MAP_NEW_FIELDS_TO_ADDED_STRUCTURES

public static final java.lang.String MAP_NEW_FIELDS_TO_ADDED_STRUCTURES
Specifies that the structures and the mapping of the parent is inherited, new structures are added (i.e. new tables are added) and the some of new fields are mapped to this new structures. Note that this rule 'extends' the previous one, that is, some of the new fields may be mapped to new columns of inherited tables This merely corresponds to a 'vertical' case supporting the definition of a filter (for efficiency reasons).

See Also:
Constant Field Values

REMAP_FIELDS_TO_NEW_STRUCTURES

public static final java.lang.String REMAP_FIELDS_TO_NEW_STRUCTURES
Specifies that neither the structures nor the mapping is inherited, structures are completely redefined (i.e. new tables are defined) and ALL the fields (defined in the class or previously defined in super classes are remapped to this new structures. This merely corresponds to a 'horizontal' case.

See Also:
Constant Field Values
Constructor Detail

RdbClassMapping

public RdbClassMapping(java.lang.String ruleName,
                       MetaObject linkedMO,
                       MetaObject parent)
Builds a new BasicRdbClassMapping object. This object contains the mapping structure of the class it refers to. The parent object is a Mapping object that contains the mapper name.

Parameters:
ruleName - the name of the rule used to map the class, linkedMo the Class object referenced by the current object, parent the parent of the current object.
Method Detail

getAllPrimitiveElementMappings

public java.util.List getAllPrimitiveElementMappings()
Description copied from interface: CommonClassMapping
Returns the list of PEM of the current class and its super classes. The list is ordered by field names.

Specified by:
getAllPrimitiveElementMappings in interface CommonClassMapping
Overrides:
getAllPrimitiveElementMappings in class BasicCommonClassMapping

createRdbTable

public RdbTable createRdbTable(java.lang.String tableName)

getRdbTable

public RdbTable getRdbTable()

getMainRdbTableOld

public void getMainRdbTableOld(java.util.ArrayList res)
Get the main table (tables ??). OL: Gets the RdbTable meta-objects relative to the main tables of ancestors while it is the same main table (which is the case with 'extended' and 'added' inheritance rules)

Parameters:
res - the list of RdbTable meta-object in ancestors relative to the the main table of the class

getMainRdbTable

public RdbTable getMainRdbTable()

createRdbFilter

public RdbFilter createRdbFilter()

getRdbFilter

public RdbFilter getRdbFilter()

getRdbInheritanceQuery

public RdbInheritanceQuery getRdbInheritanceQuery()

createRdbInheritanceQuery

public RdbInheritanceQuery createRdbInheritanceQuery()

getMappingFilterFromNamingFilter

public Expression getMappingFilterFromNamingFilter()
                                            throws ExpressionException
Throws:
ExpressionException

getMappingFilterFromNamingFilter

public Expression getMappingFilterFromNamingFilter(NamingFilterKeyProvider nfkp)
                                            throws ExpressionException
Throws:
ExpressionException

getChildren

protected java.util.Collection getChildren()
Overrides:
getChildren in class BasicClassMapping

createImplicitParentClassMapping

public ParentClassMapping createImplicitParentClassMapping(Class superClass)
Description copied from interface: ClassMapping
Creates a implicit parent class mapping. This method is called to create parent class mapping to super classes for which there is no parent class mapping defined, which means that an implicit inheritance rule of mapping should be applied. For example, with the rdb mapper, this implicit rule is to inherit all the mappings defined in the super class.

Parameters:
superClass - the super class that will be referenced by this parent class mapping
Returns:
a parent class mapping with in implicit rule to the super class

addImplicitDependencies

public void addImplicitDependencies()
The creation of tables cannot be done until all columns are known and those columns can be defined in the super and subclasses with wich there is a 'to-extended' or a 'to-added' inheritance rule.


hasUnmappedPrimitiveElements

public boolean hasUnmappedPrimitiveElements(java.util.Collection pes)
Check if any (hidden) field defined in the class (or its supers) has a defined mapping (defined in the class mapping or in it supers)

Returns:
true if there is at least one (hidden) field whch is unmapped

getParentClassMapping

public java.util.Set getParentClassMapping(java.util.Set inheritanceRules)
Returns the parent class mappings having a inheritance rule in a set of inheritance rules.

Parameters:
inheritanceRules - the set of inheritance rule names
Returns:
the parent class mappings

getAddedOrExtendedParentClassMapping

public java.util.Set getAddedOrExtendedParentClassMapping()
Returns the parent class mappings having an extened or added inheritance rule.

Returns:
the parent class mappings having an extened or added inheritance rule.

inheritsStructures

public boolean inheritsStructures(ParentClassMapping pcm)

inheritsStructures

public boolean inheritsStructures()

getPrimitiveElementMapping

public PrimitiveElementMapping getPrimitiveElementMapping(java.lang.String fieldName,
                                                          boolean searchInSuper)
Description copied from interface: ClassMapping
Get the primitive element mapping corresponding to a field name by searching recursively in the super classes until it is found (if requested)

Parameters:
fieldName - the name of the field of which the primitive element mapping must be returned
searchInSuper - if true search recursively in super classes
Returns:
the primitive element mapping if found, null otherwise