org.castor.ddlgen

Class MappingHelper


public final class MappingHelper
extends java.lang.Object

This class handles all common tasks for manipulating Mapping document.
Version:
$Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
Authors:
Le Duc Bao
Ralf Joachim
Since:
1.1

Method Summary

ClassMapping
getClassMappingByName(String name)
Return the ClassMapping which associated with parameter name.
String[]
getClassMappingIdentity(ClassMapping cm)
The identity definitions at class and field are alternative syntax.
String[]
getClassMappingSqlIdentity(ClassMapping cm, boolean ext)
The identity definitions at class and field are alternative syntax.
Mapping
getMapping()
Get mapping document.
TypeMapper
getTypeMapper()
Get type mapper.
boolean
isIdentity(ClassMapping cm, FieldMapping fm)
Check if given FieldMapping is an identity at given ClassMapping.
boolean
isUseFieldIdentity(ClassMapping cm)
Check if identities of given ClassMapping are defined at its FieldMappings.
String[]
resolveTypeReferenceForIds(String className)
Collect sql type of all identities for class with given name.
String[]
resolveTypeReferenceForIds(ClassMapping cm)
Collect sql type of all identities for a ClassMapping.
void
setMapping(Mapping mapping)
set mapping document.
void
setTypeMapper(TypeMapper typeMapper)
Set type mapper.

Method Details

getClassMappingByName

public ClassMapping getClassMappingByName(String name)
Return the ClassMapping which associated with parameter name.
Parameters:
name - Name of class to get ClassMapping of.
Returns:
ClassMapping of the named class or null if no such ClassMapping was found.

getClassMappingIdentity

public String[] getClassMappingIdentity(ClassMapping cm)
The identity definitions at class and field are alternative syntax. If both are specified the one at field should take precedence over the class one. In other words if both are specified the one at class will be ignored.
Parameters:
cm - ClassMapping to get identity names of.
Returns:
Array of identity names of given ClassMapping.

getClassMappingSqlIdentity

public String[] getClassMappingSqlIdentity(ClassMapping cm,
                                           boolean ext)
The identity definitions at class and field are alternative syntax. If both are specified the one at field should take precedence over the class one. In other words if both are specified the one at class will be ignored.
Parameters:
cm - ClassMapping to get sql names of identities of.
ext - Recursivly search for identities in extended ClassMappings.
Returns:
Array of sql names of identities of given ClassMapping.

getMapping

public Mapping getMapping()
Get mapping document.
Returns:
Mapping document.

getTypeMapper

public TypeMapper getTypeMapper()
Get type mapper.
Returns:
Type mapper.

isIdentity

public boolean isIdentity(ClassMapping cm,
                          FieldMapping fm)
Check if given FieldMapping is an identity at given ClassMapping.
 <class name="myapp.ProductGroup" identity="id">
     <field name="id" type="integer" >
         <sql name="id1 id2" type="integer"/>
     </field>
 </class>
 
Parameters:
cm - ClassMapping.
fm - FieldMapping.
Returns:
true if FieldMapping is an identity at ClassMapping.

isUseFieldIdentity

public boolean isUseFieldIdentity(ClassMapping cm)
Check if identities of given ClassMapping are defined at its FieldMappings.
Parameters:
cm - ClassMapping to check for identity definitions at FieldMapping.
Returns:
true if identities are defined at fieldMapping.

resolveTypeReferenceForIds

public String[] resolveTypeReferenceForIds(String className)
            throws GeneratorException
Collect sql type of all identities for class with given name. It also takes care on multiple column identities and extended classes.
 <mapping>
   <class name="myapp.OtherProductGroup" >
     <map-to table="other_prod_group" xml="group" />
     <field name="id" type="integer" identity="true">
       <sql name="id" type="integer"/>
     </field>
   </class>
 
   <class name="myapp.ProductGroup" identity="id">
     <map-to table="prod_group" xml="group" />
     <field name="id" type="myapp.OtherProductGroup" >
       <sql name="prod_id" />
     </field>
   </class>
 
   <class name="myapp.Product" identity="id">
     <field name="group" type="myapp.ProductGroup">
       <sql name="group_id" />
     </field>
   </class>
 </mapping>     
 
Parameters:
className - Name of class to get type of identities of.
Returns:
Array of sql types of all identities.
Throws:
GeneratorException - If failed to resolve sql type of identities.

resolveTypeReferenceForIds

public String[] resolveTypeReferenceForIds(ClassMapping cm)
            throws GeneratorException
Collect sql type of all identities for a ClassMapping. It also takes care on multiple column identities and extended classes.
Parameters:
cm - ClassMapping to get type of identities of.
Returns:
Array of sql types of all identities.
Throws:
GeneratorException - If failed to resolve sql type of identities.

setMapping

public void setMapping(Mapping mapping)
set mapping document.
Parameters:
mapping - Mapping document.

setTypeMapper

public void setTypeMapper(TypeMapper typeMapper)
Set type mapper.
Parameters:
typeMapper - Type mapper.

Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com