Class MappingHelper

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

public final class MappingHelper extends 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 Details

    • MappingHelper

      public MappingHelper()
  • Method Details

    • 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 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.