db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Kashambuzi" <mkashamb...@k2tp.com>
Subject Changes to Support Fully Qualified Tables Names
Date Fri, 28 May 2004 18:34:10 GMT
Torque Users and Developers:

I find Toruqe to be one of the best and easiest to use persistence layers but was very dimayed
by its lack of support for fully-qualified table names.  So I decided to make a few changes,
and in the spirit of open source, share those changes.  I ran all the existing Torque tests
so I feel comfortable in making the JARs available to anyone who is interested.

I made the following changes to the torque-gen-3.1 source code to support fully qualified
table names:
1. TorqueJDBCTransformTask.java. now generates schema.xml with attributes name="@SCHEMA@.TABLE_NAME"

2. build-torque.xml now includes an ant task for filtering @SCHEMA@ from schema.xml when generating
${project}-schema.xml with ${torque.database.schema} specified in build.properties

and the following in torque-3.1 source code  to support fully qualified table names:

1.  BasePeer.java now determines the table names using  


     instead of using


2. Criteria.java now determines table name using

     int dot = tableColumn.lastIndexOf('.');

     instead of

     int dot = tableColumn.indexOf('.');

Here is a sample of the relevant snippets from schema.xml

<?xml version="1.0"?>
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_1.dtd">
<!-- Autogenerated by JDBCToXMLSchema! -->
    <table javaName="MyTable" name="@SCHEMA@.MY_TABLE">

and the relevant snippets from ${project}-schema.xml

<?xml version="1.0"?>
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_1.dtd">
<!-- Autogenerated by JDBCToXMLSchema! -->
    <table javaName="MyTable" name="MYSCHEMA.MY_TABLE">

and the relevant snippets from BaseMyTablePeer.java

public abstract class BaseMyTablePeer extends BasePeer

    /** the default database name for this class */
    public static final String DATABASE_NAME = "default";

     /** the table name for this class */
    public static final String TABLE_NAME = "MYSCHEMA.MY_TABLE";

      /** the column name for the MY_COLUMN field */
    public static final String MY_COLUMN;

I also made an additional change which allows the user to specify a property, ${torque.database.tables}
= ${databaseTables}, which allows Torque to generate files only for a subset of tables.  

1. TorqueJDBCTransformTask.java has an additional attribute, dbTables, which is set from ${torque.database.tables}
and only includes this subset of tables when generating the schema.xml file.  To include all
tables, leave this blank or you can set it to %.

Lastly, I found bugs which did not correctly define or provide casting for default values
for primitive values.  Torque was doing

     private short someNumber = ;

      instead of

     private short someNumber;

and, in the method protected MyTable copyInto(MyTable copyObj)  throws TorqueException, Torque
was doing 


     instead of


so I  updated in Object.vm to account for these.

Again, if you'd like a diff of the source or the generated JAR files, I can gladly provide


To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

View raw message