## ============================================================================ ## Filename : DataObjectTemplate.vm ## Note(s) : This template is used to generate a DataObject class based on a ## database table/view. ## ## Note: The generated code is dependent on the ThinkUI framework. ## Please refer to the SQL Client documentation for details. ## ## Copyright (c) 2007-2008 ThinkUI Software Inc. All rights reserved. ## ============================================================================ ## ## **************************************************************************** ## The following variables are available in this template. For more ## information on any of the following variable, please refer to the user guide. ## **************************************************************************** ## $projectName ## $authorName ## $headerText ## $tableName ## $schemaName ## $className ## $packageName ## $prjPkgName ## $prjClassPrefix ## $dataClass ## $superClassName ## $dataClassName ## $date ## $auditTrailColumns ## $relationships ## $accessMethods ## $codeGen ## #if ($packageName) package $packageName; #end #parse( "ClassHeaderInclude.vm" ) import java.sql.Date; import java.sql.Timestamp; #if (!$auditTrailColumns) import thinkui.db.$superClassName; import thinkui.db.$dataClassName; #end import thinkui.db.DataClass; import thinkui.db.DefaultDataClass; import thinkui.db.PKColumn; import thinkui.db.FKColumn; import thinkui.db.BigDecimalColumn; import thinkui.db.CharacterColumn; import thinkui.db.DoubleColumn; import thinkui.db.DateColumn; import thinkui.db.DateTimeColumn; import thinkui.db.FloatColumn; import thinkui.db.IntegerColumn; import thinkui.db.LongColumn; import thinkui.db.StringColumn; import thinkui.db.TextColumn; import thinkui.db.TimestampColumn; import thinkui.db.YNCharacterColumn; import thinkui.db.attribute.Attribute; import thinkui.db.attribute.AttributeAccess; import thinkui.db.attribute.AttributeType; import thinkui.db.attribute.StringLengthConstraints; import thinkui.db.attribute.ValueRangeConstraints; #if ($relationships) import thinkui.db.Relationship; import thinkui.db.RelationshipType; #end /** * Implements the ${className} DataObject. */ public class ${className} extends ${superClassName} { // Attribute names. #foreach( $attr in $dataClass.getAttributes() ) #if ($codeGen.isIncludeAttrName($attr.getName())) public static final String $attr.getName().toUpperCase() = "$attr.getName().toUpperCase()"; #end #end // Table name. private static final String tableName = "$tableName"; private static final String schemaName =#if ($schemaName) "$schemaName";#else null; #end // Primary key. private static final String[] primaryKeyAttrNames = #set( $firstItem = 1 ) {#foreach( $pkAttrName in $dataClass.getPrimaryKeyAttrNames() ) #if ($firstItem == 1) #set( $firstItem = 0 ) #else, #end ${pkAttrName.toUpperCase()}#end}; // Caption attribute names. private static final String[] captionAttrNames = #set( $firstItem = 1 ) {#foreach( $captionAttrName in $dataClass.getCaptionAttrNames() ) #if ($firstItem == 1) #set( $firstItem = 0 ) #else, #end ${captionAttrName.toUpperCase()}#end}; // Attributes. private static final Attribute[] attrs = new Attribute[] { #set( $firstItem = 1 ) #foreach( $attr in $dataClass.getAttributes() ) #if ($codeGen.isIncludeAttrName($attr.getName())) #if ($firstItem == 1) #set( $firstItem = 0 ) #else, #end #if (${codeGen.isPKAttrName($dataClass, $attr.getName())}) new PKColumn($attr.getName().toUpperCase(), "$attr.getCaption()", AttributeType.${codeGen.getAttributeTypeConstant($attr.getType())})#elseif (${codeGen.isFKAttrName($dataClass, $attr.getName())}) new FKColumn($attr.getName().toUpperCase(), "$attr.getCaption()", $attr.isRequired(), AttributeType.${codeGen.getAttributeTypeConstant($attr.getType())})#else new ${codeGen.getAttributeTypeClassName($attr.getType())}Column($attr.getName().toUpperCase(), "$attr.getCaption()", $attr.isRequired()${codeGen.getConstraintsCode($attr)}${codeGen.getAccessCode($attr)})#end#end#end}; public static final DataClass DATA_CLASS = new ${dataClassName}( ${className}.class, tableName, schemaName, attrs, primaryKeyAttrNames, captionAttrNames); #if ($relationships) #if (!$relationships.isEmpty()) // Relationships. static { #foreach( $relationship in $relationships ) DATA_CLASS.addRelationship( new Relationship( "$relationship.getName()", RelationshipType.${relationship.getType()}, "$relationship.getFromDataClassName()", new String[] {${codeGen.toString($relationship.getFromAttrNames(), null, null, ",")}}, "$relationship.getToDataClassName()", new String[] {${codeGen.toString($relationship.getToAttrNames(), $codeGen.toClassName(${relationship.getToDataClassName()}, "."), null, ",")}})); #end } #end #end /** * ${className} constructor. */ public $className() { super(); } /** * ${className} constructor. */ public $className(String objectName) { super(); setName(objectName); } public final DataClass getDataClass() { return DATA_CLASS; } #if ($accessMethods) // // Access methods. // #foreach( $attr in $dataClass.getAttributes() ) #if ($codeGen.isIncludeAttrName($attr.getName())) /** * Convenience method to invoke getValue() for the ${attr.getName().toUpperCase()} attribute. * @return the ${attr.getName().toUpperCase()} attribute value. */ public final $codeGen.getAttributeTypeValueClassName($attr.getType()) get${codeGen.toTypeName($attr.getName())}Value() { return (${codeGen.getAttributeTypeValueClassName($attr.getType())}) getValue(${attr.getName().toUpperCase()}); } /** * Convenience method to invoke setValue() for the ${attr.getName().toUpperCase()} attribute. * Sets the ${attr.getName().toUpperCase()} attribute value. */ public final void set${codeGen.toTypeName($attr.getName())}Value($codeGen.getAttributeTypeValueClassName($attr.getType()) $codeGen.toVarName($attr.getName())) { setValue(${attr.getName().toUpperCase()}, ${codeGen.toVarName($attr.getName())}); } #end #end #end }