Introduction

This page gives an overview what can be done to customize the output of the generation process. In most cases, there is more than one possibility; the same thing can be achieved through high-level changes as well as through low-level changes. This page is organized such that the high level changes are described first and the low-level changes are described later. It is recommended to use the first technique which solves your problem.

Options

The Torque templates come with a lot of options, which can be used to customize behaviour. The following table lists the most commonly used options (more might be found and described in the conf/options.properties file of the template package of the current unit of generation) :

Property Default Description Used for generation of
Basic Properties
torque.database N/A Torque must know the target database platform in order to generate the appropriate SQL code, i.e. this option is required for SQL generation. Currently supported values are: derby, hsqldb, mssql, mysql, oracle, postgresql.
For SQL generation, you can also specify the a custom name. In this case you need to provide an implementation of the interface org.apache.torque.templates.platform.Platform interface which must be in the package org.apache.torque.templates.platform. Its name must be Platform${CustomName}Impl, where ${CustomName} must start with an upper case character.
sql, html, xdoc
Java Template Variables (only used for the generation of java classes)
torque.om.addGetByNameMethods true If true, Torque adds methods to get database fields by name/position.
torque.om.save.addSaveMethods true Determines whether a save method is generated.
torque.om.save.saveException Exception Defines which Exception should be thrown by the DbObject.save() method.
torque.om.trackModified true Determines whether code should be added to track whether a DbObject was modified.
torque.om.trackNew true Determines whether code should be added to track whether a DbObject was read from or already written to the database.
torque.om.addTimeStamp true If true, Torque puts time stamps in generated om files. This also triggers the generation of "serialVersionUID"-constants in the classes that implement Serializable (object, peer and manager). The version is equal to the generation timestamp.
torque.om.package N/A The Java package that Torque will put the generated classes in. This option is required if you generate the java classes. A valid value would be com.company.project.om.
torque.om.package.peerPackageSuffix Not set The subpackage (relative to ${torque.om.package}) where Torque will put the generated Peer Java classes. If set, the property needs to start with a dot. If not set, the Peer classes will be generated in ${torque.om.package}. A valid value would be .peer.
torque.om.package.dbObjectPackageSuffix Not set The subpackage (relative to ${torque.om.package}) where Torque will put the generated Database Object Java classes. If set, the property needs to start with a dot. If not set, the Database Object classes will be generated in ${torque.om.package}. A valid value would be .dbobject.
torque.om.package.mapPackageSuffix .map The subpackage (relative to ${torque.om.package}) where Torque will put the generated Java classes for the database map. If set, the property needs to start with a dot. If set to empty, the the database map classes will be generated in ${torque.om.package}.
torque.om.package.managerPackageSuffix .manager The subpackage (relative to ${torque.om.package}) where Torque will put the generated Java Manager classes, if they are generated at all. If set, the property needs to start with a dot. If set to empty, the Manager classes will be generated in ${torque.om.package}
option:torque.om.package.beanPackageSuffix .bean The subpackage (relative to ${torque.om.package}) where Torque will put the generated JavaBean classes, if they are generated at all. If set, the property needs to start with a dot. If set to empty, the the database map classes will be generated in ${torque.om.package}.
torque.om.package.baseDbObjectPackageSuffix Not set The subpackage (relative to ${torque.om.package}) where Torque will put the generated BaseObject Java classes. If set, the property needs to start with a dot. If not set, the BaseObject classes will be generated in ${torque.om.package} A valid value would be .dbobject.base.
torque.om.package.basePeerPackageSuffix Not set The subpackage (relative to ${torque.om.package}) where Torque will put the generated BasePeer Java classes. If set, the property needs to start with a dot. If not set, the BasePeer classes will be generated in ${torque.om.package} A valid value would be .peer.base.
torque.om.package.baseManagerPackageSuffix .manager.base The subpackage (relative to ${torque.om.package}) where Torque will put the generated BaseManager Java classes, if they are generated at all. If set, the property needs to start with a dot. If set to empty, the BaseManager classes will be generated in ${torque.om.package}
torque.om.package.baseBeanPackageSuffix .bean The subpackage (relative to ${torque.om.package}) where Torque will put the generated BaseBean Java classes, if they are generated at all. If set, the property needs to start with a dot. If set to empty, the BaseBean classes will be generated in ${torque.om.package}
torque.om.className.baseDbObjectClassNamePrefix Base A string to pre-pend to the file names of base data objects.
torque.om.className.basePeerClassNamePrefix Base A string to pre-pend to the file names of base peer objects.
torque.om.useManagers false If true, Torque will generate Manager classes that use JCS for caching. Still considered experimental.
torque.om.complexObjectModel true If true, Torque generates data objects with collection support and methods to easily retrieve foreign key relationships.
torque.om.objectIsCaching true If true, Torque generates data objects that cache their foreign key relationships. If this is not desired (because the underlying objects can be manipulated from other code), set this property to false.
torque.om.silentDbFetch true If true and torque.objectIsCaching is true, Torque silently fetches foreign key relation collections if the collection is not yet initialized.
torque.om.useIsForBooleanGetters false If true, Torque generates is<xxx> getter methods for boolean columns instead of get<xxx> methods.
torque.om.generateBeans false If true, Torque generates a bean object for each data object, plus methods to convert data objects to beans and vice versa.
torque.om.className.beanClassNameSuffix Bean A string to append to the name of generated Beans.
torque.om.bean.beanExtendsClass Not set A fully qualified class name (e.g. org.apache.struts.action.ActionForm) that the generated base bean classes will extend.
SQL Template Variables (only used for the generation of sql ddl)
torque.sql.generate.drops true If set to true (default), Torque will generate drop commands in the sql which drop and re-create all known tables. If set to false, Torque will not generate any drop commands - Then you need to male sure to execute the sql file(s) against an empty schema.
JDBC2Schema settings (not used for other generation targets)
torque.jdbc2schema.url N/A The connection url to the database.
torque.jdbc2schema.driver N/A The fully qualified name of the driver class. The driver class must be in the classpath.
torque.jdbc2schema.user N/A The database user which is used to read table information.
torque.jdbc2schema.password N/A The administrative password for the supplied username.
IDBroker settings (not used for other generation targets)
torque.idbroker.initialId 101 Controls the starting id of table entries when creating SQL for the id-table. If you have two projects that use the same id-table in the same database with different tables, make sure that they have different initialID settings and the ranges (initialID is incremented for every new table) don't overlap.
torque.idBroker.initialIdValue 1000 The start value of the ID broker for supplying IDs to Torque. This value is incremented every time Torque requests ID keys from the broker. If you pre-load your table straight from SQL, make sure that you don't accidentially overlap with this setting, because Torque doesn't keep record of what IDs are already taken in the database. If you overlap, inserting new objects will fail because the ID assigned by Torque is already taken.
torque.idbroker.initialIdStep 10 For performance reasons, the ID Broker does not request a single ID at a time but fetches a whole range and increments the current next ID Value in the ID Table by this step. If you have to do lots of inserts straight in a row, increment this value to get slightly better performance.

Altering the SQL type mapping

If you want to alter the way the Torque data types are mapped to SQL types or generate SQL for a dtadabase type not supported by Torque, you can write a custom platform class. This class must implement the Platform interface in the package org.apache.torque.templates.platform. The class itself must be in the same org.apache.torque.templates.platform package and its name must be Platform${CustomName}Impl. Then, put the class file in the class path from where it can be accessed by the templates, and set the option torque.database to ${customName}.

Overriding templates

If there is no option which does what you want, you can override some of the templates. See the generator reference and the ant tasks or maven plugin documentation on how to do this.