atg.cortex
Class CortexGenerator

java.lang.Object
  extended by atg.cortex.CortexGenerator

public class CortexGenerator
extends java.lang.Object

This class is a utility that will generate a set of Cortex bean definitions from a schema definition properties file. The property file defines the names of tables, columns, column types, etc. This class will read this property file and generate a bean corresponding to each table, with a property corresponding to each column. The resulting beans will also implement CortexFactory, and will contain a static "createTableDeclaration" method that returns the table declaration that can be used to create the table in the database.

The schema definition properties file has the following definition:

packageName={packageName}
The name of the package assigned to all of the generated classes
schemaManipulator={className}
The name of the utility class that will manipulate the schema. This class will generally be run from the command line. When passed a driver class and URL, it will create the tables in this schema. It can also drop those tables, test their existence, or print the CREATE TABLE statement used to create the tables. Run the class with no arguments to get a usage explanation.
tables.{tableName}.{key}={value}
Specifies the definition for a table. The {tableName} indicates which table, and the {key} can be one of the following:
tableName={name}
Specifies the name of the table in the database. If not specified, then the table name is the same as {tableName}.
className={name}
Specifies the name of the resulting bean class. If not specified, then the class name is the same as {tableName}.
superclassName={name}
Specifies the name of the resulting bean's superclass. If not specified, then the bean has no superclass.
comment={comment}
Specifies the comment that will be placed at the top of the generated java file.
columns.{columnName}.{key}={value}
Specifies the definition for a column. The {columnName} indicates which column, and the {key} can be one of the following:
columnName={name}
Specifies the name of the column in the database. If not specified, then the column name is the same as {columnName}.
propertyName={name}
Specifies the name of the property in the generated java file. If not specified, then the property name is the same as {columnName}.
comment={name}
Specifies the comment that will be placed with the property setter and getter.
sqlType={type}[({size})]
Specifies the SQL type of the column. This must be specified in JDBC terms, and must match one from the following table (case-sensitive). In addition, this also determines the java property type. The {size} parameter only need to be specified for sql types that require it, such as VARCHAR. The size must be enclosed in parentheses, and must follow the type without any spaces.
sqlTypejava property type
BITboolean
TINYINTbyte
SMALLINTshort
INTEGERint
BIGINTlong
FLOATdouble
REALfloat
DOUBLEdouble
NUMERICjava.math.BigDecimal
DECIMALjava.math.BigDecimal
CHARString
VARCHARString
LONGVARCHARString
DATEjava.sql.Date
TIMEjava.sql.Time
TIMESTAMPjava.sql.Timestamp
BINARYbyte[]
VARBINARYbyte[]
LONGVARBINARYbyte[]
constraints={constraints}
Specifies database-specific constraints on the column such as unique, primary key, null, not null, foreign key, etc. These constraints are passed directly to the CREATE TABLE statement used to create the database.
readOnly={true|false}
Specifies whether the column is read-only. Columns that are automatically filled in by the database, such as identity columns, should be marked read-only. By default, this is false.
insertSQL={SQL value expression}
Specifies that when this column is inserted using an INSERT statement, the property corresponding to the column should not be used to supply the column's value, but instead the given SQL expression should be inserted verbatim. This can be used to have the database generate the value itself using a database function, for example "insertSQL=getdate()".
updateSQL={SQL value expression}
Specifies that when this column is updated using an UPDATE statement, the property corresponding to the column should not be used to supply the column's value, but instead the given SQL expression should be inserted verbatim. This can be used to have the database generate the value itself using a database function, for example "updateSQL=getdate()".
primaryKey={true|false}
Specifies whether or not this column is a primary key. Even if this is marked as a primary key, the constraints must still be set to the database-specific notion of primary key.

The following is an example of properties file used to generate a schema:

 packageName=atg.cortex.test
 schemaManipulator=Schema
 
 #####################################
 # Person table
 
 tables.Person.comment=\
        Represents a single person
 
 # Person.name
 
 tables.Person.columns.name.comment=\
        The person's name
 tables.Person.columns.name.sqlType=VARCHAR(40)
 tables.Person.columns.name.constraints=NOT NULL PRIMARY KEY
 tables.Person.columns.name.primaryKey=true
 
 # Person.age
 
 tables.Person.columns.age.comment=\
        The person's age
 tables.Person.columns.age.sqlType=INTEGER
 
 # Person.birthmonth
 
 tables.Person.columns.birthmonth.comment=\
        The month in which the person was born
 tables.Person.columns.birthmonth.sqlType=VARCHAR(40)
 
 
 #####################################
 # Birthstone table
 
 tables.Birthstone.comment=\
        Represents a mapping from a month to a birthstone
 
 # Birthstone.month
 
 tables.Birthstone.columns.month.comment=\
        The month to which a stone is mapped
 tables.Birthstone.columns.month.sqlType=VARCHAR(40)
 tables.Birthstone.columns.month.constraints=NOT NULL PRIMARY KEY
 tables.Birthstone.columns.month.primaryKey=true
 
 # Birthstone.stone
 
 tables.Birthstone.columns.stone.comment=\
        The birthstone stone corresponding to the month
 tables.Birthstone.columns.stone.sqlType=VARCHAR(40)
 
 


Field Summary
static java.lang.String CLASS_VERSION
           
 
Method Summary
static void main(java.lang.String[] pArgs)
          Usage: CortexGenerator {propertiesFile} {outputDirectory}
 void writeClassComment(java.io.PrintStream pOut, java.lang.String pComment)
          Writes the initial class comments
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Method Detail

writeClassComment

public void writeClassComment(java.io.PrintStream pOut,
                              java.lang.String pComment)
Writes the initial class comments


main

public static void main(java.lang.String[] pArgs)
                 throws java.io.IOException
Usage: CortexGenerator {propertiesFile} {outputDirectory}

Throws:
java.io.IOException