db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lach, Thierry" <Thierry.L...@bbdodetroit.com>
Subject RE: Changes to Support Fully Qualified Tables Names
Date Tue, 01 Jun 2004 14:21:11 GMT
I'm fully in favor of schema-qualified table names, but I'd much rather
see a more dynamic approach.  We've got a number of identical schemas
that we use.  It would be much more useful to us here if the schema were
able to be assigned at runtime rather than at compile time.

-----Original Message-----
From: Michael Kashambuzi [mailto:mkashambuzi@k2tp.com] 
Sent: Friday, May 28, 2004 2:34 PM
To: torque-user@db.apache.org
Subject: Changes to Support Fully Qualified Tables Names


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"
javaName="TableName

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  

     columnName.lastIndexOf('.')
     orderByColumn.lastIndexOf('.')
     join#.lastIndexOf('.')

     instead of using

     columnName.indexOf('.')
     orderByColumn.indexOf('.')
     join#.indexOf('.')


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! -->
<database>
    <table javaName="MyTable" name="@SCHEMA@.MY_TABLE">
    ...
    </table>
</database>

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! -->
<database>
    <table javaName="MyTable" name="MYSCHEMA.MY_TABLE">
    ...
    </table>
</database>

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;
    static
    {
          MY_COLUMN = "MYSCHEMA.MY_TABLE.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 

     copyObj.setSomeNumber(0);

     instead of

     copyObj.setSomeNumber((short)0);

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 these.

Michael

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


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


Mime
View raw message