org.castor.ddlgen
Class MappingHelper

java.lang.Object
  extended by org.castor.ddlgen.MappingHelper

public final class MappingHelper
extends java.lang.Object

This class handles all common tasks for manipulating Mapping document.

Since:
1.1
Version:
$Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
Author:
Le Duc Bao, Ralf Joachim

Constructor Summary
MappingHelper()
           
 
Method Summary
 org.exolab.castor.mapping.xml.ClassMapping getClassMappingByName(java.lang.String name)
          Return the ClassMapping which associated with parameter name.
 java.lang.String[] getClassMappingIdentity(org.exolab.castor.mapping.xml.ClassMapping cm)
          The identity definitions at class and field are alternative syntax.
 java.lang.String[] getClassMappingSqlIdentity(org.exolab.castor.mapping.xml.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(org.exolab.castor.mapping.xml.ClassMapping cm, org.exolab.castor.mapping.xml.FieldMapping fm)
          Check if given FieldMapping is an identity at given ClassMapping.
 boolean isUseFieldIdentity(org.exolab.castor.mapping.xml.ClassMapping cm)
          Check if identities of given ClassMapping are defined at its FieldMappings.
 java.lang.String[] resolveTypeReferenceForIds(org.exolab.castor.mapping.xml.ClassMapping cm)
          Collect sql type of all identities for a ClassMapping.
 java.lang.String[] resolveTypeReferenceForIds(java.lang.String className)
          Collect sql type of all identities for class with given name.
 void setMapping(Mapping mapping)
          set mapping document.
 void setTypeMapper(TypeMapper typeMapper)
          Set type mapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MappingHelper

public MappingHelper()
Method Detail

getMapping

public Mapping getMapping()
Get mapping document.

Returns:
Mapping document.

setMapping

public void setMapping(Mapping mapping)
set mapping document.

Parameters:
mapping - Mapping document.

getTypeMapper

public TypeMapper getTypeMapper()
Get type mapper.

Returns:
Type mapper.

setTypeMapper

public void setTypeMapper(TypeMapper typeMapper)
Set type mapper.

Parameters:
typeMapper - Type mapper.

getClassMappingByName

public org.exolab.castor.mapping.xml.ClassMapping getClassMappingByName(java.lang.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.

resolveTypeReferenceForIds

public java.lang.String[] resolveTypeReferenceForIds(java.lang.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 java.lang.String[] resolveTypeReferenceForIds(org.exolab.castor.mapping.xml.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.

isUseFieldIdentity

public boolean isUseFieldIdentity(org.exolab.castor.mapping.xml.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.

isIdentity

public boolean isIdentity(org.exolab.castor.mapping.xml.ClassMapping cm,
                          org.exolab.castor.mapping.xml.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.

getClassMappingSqlIdentity

public java.lang.String[] getClassMappingSqlIdentity(org.exolab.castor.mapping.xml.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.

getClassMappingIdentity

public java.lang.String[] getClassMappingIdentity(org.exolab.castor.mapping.xml.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.


Copyright © 2011. All Rights Reserved.