ThinkUI SQL Client 1.1.3 API

thinkui.codegen
Class CodeGenHelper

java.lang.Object
  extended bythinkui.codegen.CodeGenHelper

public abstract class CodeGenHelper
extends java.lang.Object

Wrapper class to provide access to the CodeGenUtils class from within the Velocity template file. This is needed because static methods cannot be accessed directly from within the template file.


Constructor Summary
CodeGenHelper()
           
 
Method Summary
 boolean contains(java.lang.String[] values, java.lang.String value)
           
 java.lang.Object create(java.lang.String className)
          Helper method to lookup the Class for the given className using Java reflection and create a new instance.
 java.lang.String dbName(java.lang.String dbNameOrIdentifier)
           
 java.lang.String formatConstraints(Attribute attr)
           
 java.lang.String formatJDBC(DataObject dataObject, Attribute attr)
          Helper function to format the attribute value of the specified type.
 java.lang.String formatJDBCHolder(DataObject dataObject, Attribute attr)
          Helper function to format the attribute value of the specified type.
 java.lang.String formatXML(DataObject dataObject, Attribute attr)
          Helper function to format the attribute value of the specified type.
 java.lang.String getAccessCode(Attribute attr)
           
 java.lang.String getAttributeAccess(AttributeAccess access)
           
 java.lang.String getAttributeTypeClassName(AttributeType attrType)
          Helper method used mainly for generating Java Bean code.
 java.lang.String getAttributeTypeConstant(AttributeType attrType)
           
 java.lang.String getAttributeTypeValueClassName(AttributeType attrType)
          Helper method used mainly for generating Java Bean code.
 java.lang.String getAttributeTypeValueFullClassName(AttributeType attrType)
          Helper method used mainly for generating Java Bean code.
 java.lang.String getColumnName(Attribute attribute)
           
 java.lang.String getColumnNameExpr(Attribute attribute)
           
 java.lang.String getColumnNames(DataClass dataClass, java.lang.String[] attributeNames)
           
 java.lang.String getConstraintsCode(Attribute attr)
           
static Relationship getFKRelationship(DataClass dataClass, java.lang.String attrName)
          Returns the FK relationship for the given attribute name or return null.
 java.lang.String getHintText(Attribute attr)
           
 java.lang.String getMaxStringLengthConstraint(Attribute attr)
           
 java.lang.String getPrjClassPrefix(java.lang.String projectName)
           
 java.lang.String getPrjPkgName(java.lang.String projectName)
           
 java.lang.String getRelatedColumnNames(Relationship relationship)
           
 java.lang.String getShortClassName(java.lang.String className)
           
 java.lang.String getShortTableName(java.lang.String fullTableName)
           
 java.lang.String getSQLTypeName(AttributeType attrType)
           
 java.lang.String identifier(java.lang.String identifier)
          Workaround due to Velocity bug not being able to invoke convertIdentifier() abstract method.
 boolean isAutoIncPKAttrName(DataClass dataClass, java.lang.String attrName)
          Returns whether or not the given attribute name specify a primary key column that can be auto incremented.
 boolean isEmpty(java.lang.String str)
           
 boolean isFKAttrName(DataClass dataClass, java.lang.String attrName)
          Returns whether or not the given attribute name specify a foreign key column.
 boolean isIncludeAttrName(java.lang.String attrName)
           
 boolean isLegend(Attribute attr)
          Returns whether or not the given attribute has a legend.
 boolean isPKAttrName(DataClass dataClass, java.lang.String attrName)
          Returns whether or not the given attribute name specify a primary key column.
 boolean isSyncAttrName(DataClass dataClass, java.lang.String attrName)
          Returns whether or not the given attribute name specify an auto increment/defaulted column.
 boolean isTextAttributeType(AttributeType attrType)
           
 boolean isUpdateAttrName(DataClass dataClass, java.lang.String attrName)
          Returns whether or not the given attribute name specify a column that can be updated.
 java.lang.String nvl(java.lang.Object obj, java.lang.String value)
           
 java.lang.String prependPrefix(java.lang.String prefix, java.lang.String separator, java.lang.String str)
          Helper method to prepend the given string with the specified prefix and separator only if the prefix is not empty.
 java.lang.String quote(java.lang.String str)
          Adds double quotes around the given string (if not already quoted) and escape any double quotes found inside the string.
 java.lang.String repeat(java.lang.String str, int count)
          Helper method to generate a string consisting of count copies of str.
 java.lang.String singleQuote(java.lang.String str)
          Adds single quotes around the given string (if not already quoted) and escape any single quotes found inside the string.
 java.lang.String toCaption(java.lang.String identifier)
           
 java.lang.String toClassName(java.lang.String fullTableName)
           
 java.lang.String toClassName(java.lang.String fullTableName, java.lang.String suffix)
           
 java.lang.String toConstantName(java.lang.String identifier)
           
 java.lang.String toIdentifier(java.lang.String shortClassName)
          Converts the given short Java class name to a variable by simply changing the first letter to lower case.
 java.lang.String toPlural(java.lang.String noun)
           
 java.lang.String toShortDbName(java.lang.String dbName)
          Returns the short name for the given database table/column name.
 java.lang.String toString(java.lang.String[] array, java.lang.String prefix, java.lang.String suffix, java.lang.String delimiter)
           
 java.lang.String toString(java.lang.String[] array, java.lang.String prefix, java.lang.String suffix, java.lang.String delimiter, boolean upperCase)
           
 java.lang.String toTypeName(java.lang.String dbName)
           
 java.lang.String toVarName(java.lang.String dbName)
           
 java.lang.String unquote(java.lang.String str)
          Removes double quotes around the given string (if needed) and unescape any double quotes found inside the string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeGenHelper

public CodeGenHelper()
Method Detail

contains

public final boolean contains(java.lang.String[] values,
                              java.lang.String value)
Returns:
whether or not the specified value is in the list of values.

create

public final java.lang.Object create(java.lang.String className)
                              throws java.lang.Exception
Helper method to lookup the Class for the given className using Java reflection and create a new instance. It is assumed that the class has a public no-arg constructor.

Throws:
java.lang.Exception

dbName

public final java.lang.String dbName(java.lang.String dbNameOrIdentifier)
Returns:
the corresponding DB name in a standardized format.

formatConstraints

public final java.lang.String formatConstraints(Attribute attr)

formatJDBC

public final java.lang.String formatJDBC(DataObject dataObject,
                                         Attribute attr)
Helper function to format the attribute value of the specified type. Any special SQL characters found will be escaped (e.g. the single quote).

Returns:
the attribute value formatted for the specified type.

formatJDBCHolder

public final java.lang.String formatJDBCHolder(DataObject dataObject,
                                               Attribute attr)
Helper function to format the attribute value of the specified type. Any special SQL characters found will be escaped (e.g. the single quote).

Returns:
the attribute value formatted for the specified type or a '?' place holder.

formatXML

public final java.lang.String formatXML(DataObject dataObject,
                                        Attribute attr)
Helper function to format the attribute value of the specified type. Any special XML characters found will be escaped (e.g. <, >, etc.).

Returns:
the attribute value formatted for the specified type or "".

getAccessCode

public final java.lang.String getAccessCode(Attribute attr)
Returns:
the access code fragment for the given attribute or an empty string.

getAttributeAccess

public final java.lang.String getAttributeAccess(AttributeAccess access)
Returns:
the constant identifier for the specified attribute access.

getAttributeTypeClassName

public final java.lang.String getAttributeTypeClassName(AttributeType attrType)
Helper method used mainly for generating Java Bean code.

Returns:
the class name for the specified attribute type.

getAttributeTypeConstant

public final java.lang.String getAttributeTypeConstant(AttributeType attrType)
Returns:
the constant identifier for the specified attribute type.

getAttributeTypeValueClassName

public final java.lang.String getAttributeTypeValueClassName(AttributeType attrType)
Helper method used mainly for generating Java Bean code.

Returns:
the class name of the value for the specified attribute type.

getAttributeTypeValueFullClassName

public final java.lang.String getAttributeTypeValueFullClassName(AttributeType attrType)
Helper method used mainly for generating Java Bean code.

Returns:
the full class name of the value for the specified attribute type.

getColumnName

public final java.lang.String getColumnName(Attribute attribute)
Returns:
the column name for the given attribute.

getColumnNameExpr

public final java.lang.String getColumnNameExpr(Attribute attribute)
Returns:
the column name for the given attribute for use in SELECT SQL queries.

getColumnNames

public final java.lang.String getColumnNames(DataClass dataClass,
                                             java.lang.String[] attributeNames)
Returns:
the column names for the given attribute names as a comma separated String.

getConstraintsCode

public final java.lang.String getConstraintsCode(Attribute attr)
Returns:
the constraints code fragment for the given attribute or an empty string.

getFKRelationship

public static final Relationship getFKRelationship(DataClass dataClass,
                                                   java.lang.String attrName)
Returns the FK relationship for the given attribute name or return null. If the FK consists of multiple columns, the corresponding relationship will be returned if any of the relationship "From" attribute names matches the given attrName.

Returns:
the FK relationship for the given attribute name or return null.

getHintText

public final java.lang.String getHintText(Attribute attr)

getMaxStringLengthConstraint

public final java.lang.String getMaxStringLengthConstraint(Attribute attr)
Returns:
the maximum string length constraint for the given attribute or an empty string.

getPrjClassPrefix

public final java.lang.String getPrjClassPrefix(java.lang.String projectName)
Returns:
the project class prefix for the given project name or null.

getPrjPkgName

public final java.lang.String getPrjPkgName(java.lang.String projectName)
Returns:
the project package name for the given project name or null.

getRelatedColumnNames

public final java.lang.String getRelatedColumnNames(Relationship relationship)
                                             throws java.lang.Exception
Returns:
the column names for the given relationship as a comma separated String.
Throws:
java.lang.Exception

getShortClassName

public final java.lang.String getShortClassName(java.lang.String className)
Returns:
the short class name of the specified class name.

getShortTableName

public final java.lang.String getShortTableName(java.lang.String fullTableName)
Returns:
the short table name of the specified full table name.

getSQLTypeName

public final java.lang.String getSQLTypeName(AttributeType attrType)
Returns:
the JDBC SQL type name for the specified attribute type.

identifier

public final java.lang.String identifier(java.lang.String identifier)
Workaround due to Velocity bug not being able to invoke convertIdentifier() abstract method. This method simply calls convertIdentifier() to convert the given identifier to the appropriate case (if needed) and quote the identifier if it contains mixed case or spaces.


isAutoIncPKAttrName

public final boolean isAutoIncPKAttrName(DataClass dataClass,
                                         java.lang.String attrName)
Returns whether or not the given attribute name specify a primary key column that can be auto incremented.

Returns:
whether or not the given attribute name specify a primary key column that can be auto incremented.

isEmpty

public final boolean isEmpty(java.lang.String str)
Returns:
whether or not the specified string is null or blank.

isFKAttrName

public final boolean isFKAttrName(DataClass dataClass,
                                  java.lang.String attrName)
Returns whether or not the given attribute name specify a foreign key column.

Returns:
whether or not the given attribute name specify a foreign key column.

isIncludeAttrName

public final boolean isIncludeAttrName(java.lang.String attrName)
Returns:
whether or not to include the specified attribute name in a data class definition.

isLegend

public final boolean isLegend(Attribute attr)
Returns whether or not the given attribute has a legend.

Returns:
whether or not the given attribute has a legend.

isPKAttrName

public final boolean isPKAttrName(DataClass dataClass,
                                  java.lang.String attrName)
Returns whether or not the given attribute name specify a primary key column.

Returns:
whether or not the given attribute name specify a primary key column.

isSyncAttrName

public final boolean isSyncAttrName(DataClass dataClass,
                                    java.lang.String attrName)
Returns whether or not the given attribute name specify an auto increment/defaulted column. If so, when a record is inserted, the values for the column must be synchronized with the object.

NOTE: This method considers an attribute to be a sync attribute if it is part of the primary key.

Returns:
whether or not the given attribute name specify an auto increment/defaulted column.

isTextAttributeType

public final boolean isTextAttributeType(AttributeType attrType)
Returns:
whether or not the given attribute type is a Text type.

isUpdateAttrName

public final boolean isUpdateAttrName(DataClass dataClass,
                                      java.lang.String attrName)
Returns whether or not the given attribute name specify a column that can be updated.

Returns:
whether or not the given attribute name specify a column that can be updated.

nvl

public final java.lang.String nvl(java.lang.Object obj,
                                  java.lang.String value)
Returns:
value if object is null or object.toString() otherwise.

prependPrefix

public final java.lang.String prependPrefix(java.lang.String prefix,
                                            java.lang.String separator,
                                            java.lang.String str)
Helper method to prepend the given string with the specified prefix and separator only if the prefix is not empty.

Returns:
str prefixed with the specified prefix and separator only if the prefix is not empty.

quote

public final java.lang.String quote(java.lang.String str)
Adds double quotes around the given string (if not already quoted) and escape any double quotes found inside the string.

Returns:
the a properly escaped string with double quotes around it.

repeat

public final java.lang.String repeat(java.lang.String str,
                                     int count)
Helper method to generate a string consisting of count copies of str.


singleQuote

public final java.lang.String singleQuote(java.lang.String str)
Adds single quotes around the given string (if not already quoted) and escape any single quotes found inside the string. If the given string is null, then "null" string will be returned.

Returns:
the a properly escaped string with single quotes around it.

toCaption

public final java.lang.String toCaption(java.lang.String identifier)
Returns:
the caption appropriate for the specified Java identifier.

toClassName

public final java.lang.String toClassName(java.lang.String fullTableName)
Returns:
the short Java class name for the specified full table name.

toClassName

public final java.lang.String toClassName(java.lang.String fullTableName,
                                          java.lang.String suffix)
Returns:
the short Java class name for the specified full table name.

toConstantName

public final java.lang.String toConstantName(java.lang.String identifier)
Returns:
the Java constant name appropriate for the specified Java identifier.

toIdentifier

public final java.lang.String toIdentifier(java.lang.String shortClassName)
Converts the given short Java class name to a variable by simply changing the first letter to lower case. To convert a variable name from a database table/column name, use the toVarName() method.

Returns:
the variable name for the given short Java class name.

toPlural

public final java.lang.String toPlural(java.lang.String noun)
Returns:
the plural form of the given noun.

toShortDbName

public final java.lang.String toShortDbName(java.lang.String dbName)
Returns the short name for the given database table/column name. The short name consists of the first letter of the given name plus each letter after each underscore (if any).

Returns:
the short name for the given database table/column name.

toString

public final java.lang.String toString(java.lang.String[] array,
                                       java.lang.String prefix,
                                       java.lang.String suffix,
                                       java.lang.String delimiter)
Returns:
the String equivalent to the specified array with optional prefix, suffix, and delimiter.

toString

public final java.lang.String toString(java.lang.String[] array,
                                       java.lang.String prefix,
                                       java.lang.String suffix,
                                       java.lang.String delimiter,
                                       boolean upperCase)
Returns:
the String equivalent to the specified array with optional prefix, suffix, and delimiter.

toTypeName

public final java.lang.String toTypeName(java.lang.String dbName)

toVarName

public final java.lang.String toVarName(java.lang.String dbName)

unquote

public final java.lang.String unquote(java.lang.String str)
Removes double quotes around the given string (if needed) and unescape any double quotes found inside the string.

Returns:
the given string without any double quotes or the original string.

ThinkUI SQL Client 1.1.3 API

Copyright © 2007-2009. ThinkUI Software Inc. All rights reserved.