org.apache.torque.templates.transformer.om
Class OMColumnTransformer

java.lang.Object
  extended by org.apache.torque.templates.transformer.om.OMColumnTransformer

public class OMColumnTransformer
extends Object

Sets the class names and packages for the OM model. The id method attribute must already be set on the parent table element when this transformer is called.


Constructor Summary
OMColumnTransformer()
           
 
Method Summary
protected  void checkColumnNameExists(SourceElement columnElement)
          Checks that the name attribute exists on the column element.
protected  void checkElementName(SourceElement columnElement)
          Checks that the name of the column element is correct.
static Date getDefaultValueAsDate(String defaultValue)
          Parses the default value String as Date.
protected  String getDefaultValueWithDefaultSet(JavaType javaType, String defaultValue, boolean useDatabaseDefaultValue, SourceElement columnElement)
          Calculates the java default value of a column in case a default value is set.
protected  String getDefaultValueWithoutDefaultSet(JavaType javaType)
          Calculates the java default value of a column in case a default value is not set.
protected  JavaType getFieldJavaType(SourceElement columnElement, SchemaType schemaType)
          Returns the java type of the field representing a database column.
protected  void setAccessModifierAttributes(SourceElement columnElement)
          Sets the attributes getterAccessModifer and setterAccessModifer on the column element.
protected  void setAttributeDefaultValues(SourceElement columnElement)
          Sets default values for attributes of the column element if the attribute is not set.
protected  void setDefaultValueAttribute(SourceElement columnElement, JavaType javaType, ControllerState controllerState)
          Sets the defaultValue attribute of the column element if it is not already set.
protected  void setDomainAttributes(SourceElement columnElement, ControllerState controllerState)
           
protected  void setFieldNameAttribute(SourceElement columnElement)
          Sets the fieldName attribute of the column element if it is not already set.
protected  void setGetterNameAttribute(SourceElement columnElement, JavaType javaType, ControllerState controllerState)
          Sets the getterName attribute of the column element if it is not already set.
protected  void setJavaNameAttribute(SourceElement columnElement)
          Sets the javaName attribute of the column element if it is not already set.
protected  void setJavaTypeAttribute(SourceElement columnElement)
          Sets the javaType attribute of the column element if it is not already set and a default value is set.
protected  void setNumberTypeAttribute(SourceElement columnElement, JavaType javaType)
          Sets the numberType attribute of the column element if it is not already set.
protected  void setPeerColumnNameAttribute(SourceElement columnElement)
          Sets the peerColumnName attribute of the column element if it is not already set.
protected  void setPrimitiveTypeAttribute(SourceElement columnElement, JavaType javaType)
          Sets the primitiveType attribute of the column element if it is not already set.
protected  void setQualifiedColumnNameAttribute(SourceElement columnElement)
          Sets the qualifiedColumnName attribute of the column element if it is not already set.
protected  void setResultSetGetterAttribute(SourceElement columnElement, SchemaType schemaType)
          Sets the resultSetGetter attribute of the column element if it is not already set.
protected  void setSampleObjectAttribute(SourceElement columnElement, SchemaType schemaType)
          Sets the sampleObject attribute of the column element if it is not already set.
protected  void setSetterNameAttribute(SourceElement columnElement)
          Sets the setterName attribute of the column element if it is not already set.
protected  void setUseDatabaseDefaultValueAttribute(SourceElement columnElement)
          Sets the useDatabaseDefaultValue attribute of the column element to its default "false" if it is not already set.
 void transform(SourceElement columnElement, ControllerState controllerState, int columnPosition)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OMColumnTransformer

public OMColumnTransformer()
Method Detail

transform

public void transform(SourceElement columnElement,
                      ControllerState controllerState,
                      int columnPosition)
               throws SourceTransformerException
Throws:
SourceTransformerException

setJavaTypeAttribute

protected void setJavaTypeAttribute(SourceElement columnElement)
Sets the javaType attribute of the column element if it is not already set and a default value is set.

Parameters:
columnElement - the column element, not null.

setAttributeDefaultValues

protected void setAttributeDefaultValues(SourceElement columnElement)
Sets default values for attributes of the column element if the attribute is not set. The following attributes are checked: autoIncrement, protected, inheritance, required, primaryKey

Parameters:
columnElement - the column element, not null.

setDomainAttributes

protected void setDomainAttributes(SourceElement columnElement,
                                   ControllerState controllerState)
                            throws SourceTransformerException
Throws:
SourceTransformerException

setAccessModifierAttributes

protected void setAccessModifierAttributes(SourceElement columnElement)
Sets the attributes getterAccessModifer and setterAccessModifer on the column element.

Parameters:
columnElement - the column element, not null.

getFieldJavaType

protected JavaType getFieldJavaType(SourceElement columnElement,
                                    SchemaType schemaType)
                             throws SourceTransformerException
Returns the java type of the field representing a database column.

Parameters:
columnElement - the column element, not null.
schemaType - the schema type, not null.
Returns:
the java type of the column
Throws:
SourceTransformerException

checkElementName

protected void checkElementName(SourceElement columnElement)
Checks that the name of the column element is correct.

Parameters:
columnElement - the column element, not null.
Throws:
IllegalArgumentException - if the element name is wrong.

checkColumnNameExists

protected void checkColumnNameExists(SourceElement columnElement)
                              throws SourceTransformerException
Checks that the name attribute exists on the column element.

Parameters:
columnElement - the column element, not null.
Throws:
SourceTransformerException - if the name attribute does not exist.

setJavaNameAttribute

protected void setJavaNameAttribute(SourceElement columnElement)
Sets the javaName attribute of the column element if it is not already set.

Parameters:
columnElement - the column element, not null.

setFieldNameAttribute

protected void setFieldNameAttribute(SourceElement columnElement)
Sets the fieldName attribute of the column element if it is not already set. The javaName attribute of the column must be set.

Parameters:
columnElement - the column element, not null.

setPeerColumnNameAttribute

protected void setPeerColumnNameAttribute(SourceElement columnElement)
Sets the peerColumnName attribute of the column element if it is not already set.

Parameters:
columnElement - the column element, not null.

setQualifiedColumnNameAttribute

protected void setQualifiedColumnNameAttribute(SourceElement columnElement)
Sets the qualifiedColumnName attribute of the column element if it is not already set.

Parameters:
columnElement - the column element, not null.

setGetterNameAttribute

protected void setGetterNameAttribute(SourceElement columnElement,
                                      JavaType javaType,
                                      ControllerState controllerState)
Sets the getterName attribute of the column element if it is not already set. The fieldName attribute of the column element must already be set.

Parameters:
columnElement - the column element, not null.
javaType - the java type of the column, not null.
controllerState - the controller state, not null.

setSetterNameAttribute

protected void setSetterNameAttribute(SourceElement columnElement)
Sets the setterName attribute of the column element if it is not already set. The fieldName attribute of the column element must already be set.

Parameters:
columnElement - the column element, not null.

setPrimitiveTypeAttribute

protected void setPrimitiveTypeAttribute(SourceElement columnElement,
                                         JavaType javaType)
Sets the primitiveType attribute of the column element if it is not already set.

Parameters:
columnElement - the column element, not null.
javaType - the type of the java field corresponding to the column, not null.

setNumberTypeAttribute

protected void setNumberTypeAttribute(SourceElement columnElement,
                                      JavaType javaType)
Sets the numberType attribute of the column element if it is not already set.

Parameters:
columnElement - the column element, not null.
javaType - the type of the java field corresponding to the column, not null.

setDefaultValueAttribute

protected void setDefaultValueAttribute(SourceElement columnElement,
                                        JavaType javaType,
                                        ControllerState controllerState)
                                 throws SourceTransformerException
Sets the defaultValue attribute of the column element if it is not already set.

Parameters:
columnElement - the column element, not null.
javaType - the type of the java field corresponding to the column, not null.
controllerState - the ControllerState, not null.
Throws:
SourceTransformerException - if an unknown primitive type is encountered

getDefaultValueWithDefaultSet

protected String getDefaultValueWithDefaultSet(JavaType javaType,
                                               String defaultValue,
                                               boolean useDatabaseDefaultValue,
                                               SourceElement columnElement)
                                        throws SourceTransformerException
Calculates the java default value of a column in case a default value is set.

Parameters:
javaType - The java type of the column.
defaultValue - The default value from the schema.
useDatabaseDefaultValue - whether the database default value should be used.
columnElement - the current column element for which the default value should be calculated.
Returns:
The java default value.
Throws:
SourceTransformerException - if an illegal default value is used.

getDefaultValueAsDate

public static Date getDefaultValueAsDate(String defaultValue)
                                  throws SourceTransformerException
Parses the default value String as Date.

Parameters:
defaultValue - the String to parse.
Returns:
the parsed date.
Throws:
SourceTransformerException - if the date cannot be parsed.

getDefaultValueWithoutDefaultSet

protected String getDefaultValueWithoutDefaultSet(JavaType javaType)
                                           throws SourceTransformerException
Calculates the java default value of a column in case a default value is not set.

Parameters:
javaType - The java type of the column.
Returns:
The java default value.
Throws:
SourceTransformerException

setUseDatabaseDefaultValueAttribute

protected void setUseDatabaseDefaultValueAttribute(SourceElement columnElement)
Sets the useDatabaseDefaultValue attribute of the column element to its default "false" if it is not already set.

Parameters:
columnElement - the column element, not null.

setResultSetGetterAttribute

protected void setResultSetGetterAttribute(SourceElement columnElement,
                                           SchemaType schemaType)
Sets the resultSetGetter attribute of the column element if it is not already set. If the resultSetGetter is a string value, it is converted to a ResultSetGetter value.

Parameters:
columnElement - the column element, not null.
schemaType - the schema type of the column, not null.

setSampleObjectAttribute

protected void setSampleObjectAttribute(SourceElement columnElement,
                                        SchemaType schemaType)
Sets the sampleObject attribute of the column element if it is not already set.

Parameters:
columnElement - the column element, not null.
schemaType - the schema type of the column, not null.


Copyright © 2000-2013 The Apache Software Foundation. All Rights Reserved.