You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Michael Kashambuzi <mk...@k2tp.com> on 2004/05/28 20:34:10 UTC

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


Re: Changes to Support Fully Qualified Tables Names

Posted by Bogdan Vatkov <bv...@globaltech-bg.com>.
Have you testet that on postgresql
and using a keywords for the names of table,column ?
regards,
bogdan
----- Original Message -----
From: "Michael Kashambuzi" <mk...@k2tp.com>
To: <to...@db.apache.org>
Sent: Friday, May 28, 2004 9:34 PM
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