Torque Schema ReferenceThe Torque Database Schema Reference attempts to explain what the different elements and attributes are when defining your own database schema. In addition I will attempt to explain which attributes mean what in the different databases that are currently supported. Elements and their attributes
Some of the following examples are taken from the project-schema.xml document in the src/conf/torque/schema. Element: databaseThe database element and its relevant attributes. <database name="MY_DATABASE" defaultIdMethod="idBroker" package="com.myapp.om" baseClass="com.myapp.om.BaseClass" basePeer="com.myapp.om.BasePeer"> <table name="SIMPLE"> <!-- table info goes here --> </table> </database> The database element has 8 attributes associated with it, they are:
The database element can contain the following elements:
Attribute: defaultIdMethodBy defining this attribute at the database level it applies the defaultIdMethod to those tables which do not have an idMethod attribute defined. The attribute defaultIdMethod has 5 possible values, they are:
Attribute: defaultJavaNamingMethodThis attribute determines how table or column names, from the name attribute of the table or column element, are converted to a Java class or method name respectively when creating the OM Java objects. defaultJavaNamingMethod can contain 3 different values:
Attribute: packageThe base package in which this database will generate the Object Models associated with it. This overrides the targetPackage property in the Torque build.properties file. Attribute: baseClassThe base class to use when generating the Object Model. This class does not have to extend org.apache.torque.om.BaseObject. Attribute: basePeerThe base peer to use when generating the Object Model Peers. Unlike baseClass, basePeer should extend BasePeer at some point in the chain, i.e. it needs to be the superclass. Element: tableThe table element and its relevant attributes <table name="MY_TABLE" javaName="table" idMethod="idbroker" skipSql="false" baseClass="com.myapp.om.table.BaseClass" basePeer="com.myapp.om.table.BasePeer" javaNamingMethod="underscore" description="Table for Torque tests"> <!-- column information here --> </table> The table element has 13 attributes associated with it, they are:
The table element can contain the following elements:
Attribute: javaNameThis is the Java class name to use when generating the Table or column. If this is missing the Java name is generated in the following manner: Underscores are removed, first letter and first letter after each underscore is uppercased, all other letters are lowercased. So YOUR_TABLE_NAME would become YourTableName. Element: columnThe column element and its relevant attributes <column name="MY_COLUMN" javaName="Column" primaryKey="true" required="true" size="4" type="VARCHAR" javaNamingMethod="underscore"> <!-- inheritance info if necessary --> </column> The column element has 13 attributes associated with it, they are:
The column element can contain the following elements:
Element: inheritanceThe inheritance element and its relevant attributes <inheritance key="key" class="classname" extends="mybase"/> The inheritance element has 3 attributes associated with it, they are:
The inheritance element can not contain other elements. Element: foreign-keyThe foreign-key element and its relevant attributes <foreign-key foreignTable="MY_TABLE" name="MY_TABLE_FK" onUpdate="none" onDelete="none"> <!-- reference info --> </foreign-key> The foreign-key element has 4 attributes associated with it, they are:
The foreign-key element can contain the following elements:
Element: referenceThe reference element and its relevant attributes <reference local="FK_TABLE_ID" foreign="PK_COLUMN_ID"/> The reference element has 2 attributes associated with it, they are:
The reference element can not contain other elements. Element: indexThe index element and its relevant attributes <index name="MY_INDEX"> <!-- index-column info --> </index> The index element has 1 attribute associated with it, it is:
The index element can contain the following elements:
Element: index-columnThe index-column element and its relevant attributes <index-column name="INDEX_COLUMN"/> The index-column element has 2 attributes associated with it, they are:
The index-column element can not contain other elements. Element: uniqueThe unique element and its relevant attributes <unique name="MY_UNIQUE"> <!-- unique-column info --> </unique> The unique element has 1 attribute associated with it, it is:
The unique element can contain the following elements:
Element: unique-columnThe unique-column element and its relevant attributes <unique-column name="UNIQUE_COLUMN"/> The unique-column element has 1 attribute associated with it, it is:
The unique-column element can not contain other elements. |