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 James Wang <to...@yahoo.com> on 2003/06/24 18:58:57 UTC

obtaining native primary keys in DB2 V7.x

0)download torque-3.0.zip ,and decompress it to
d:\>torque3.0

1)define the d:\>torque3.0\schema\project-schema.xml
    note: the table'idMethod="native" and column's
autoIncrement="true"

<?xml version="1.0" encoding="ISO-8859-1"
standalone="no"?>
<!DOCTYPE database SYSTEM
"http://jakarta.apache.org/turbine/dtd/database.dtd">

<database name="jetspeed">
  <table name="USER" idMethod="native">
    <column name="USER_ID" required="true"
primaryKey="true" autoIncrement="true"
type="INTEGER"/>
    <column name="USER_NAME" type="VARCHAR"
size="225"/>    
    <column name="CREATEDTIME" type="TIMESTAMP"/>
  </table>
</database>  

2)d:\>torque3.0\ant -f build-torque.xml
3)write a Test.java,insert the following code,put the
file into d:\torque3.0\src\java,

            Torque.init("Torque.properties");

            /*
             * Creating new objects.  These will be
inserted
             * into your database automatically when
the
             * save method is called.
             */
            User us = new User();
            us.setUserId(111111111); //this line will
not take effect for idmethod='native'
            us.setUserName("james");
            java.util.Date d =  new
java.sql.Timestamp(System.currentTimeMillis());
            us.setCreatedtime(new
java.sql.Timestamp(System.currentTimeMillis()));
            us.save();

4)download the torque-3.0-src.zip and decompress it to
d:\>torque-3.0-src
  download jakarta-ant-1.5,connect to Internet

5)modify
D:\torque-3.0-src\torque-3.0\src\java\org\apache\torque\adapter\DBDB2App.java
  modify the following method,

    public String getIDMethodType()
    {
        return AUTO_INCREMENT;
    }

    public String getIDMethodSQL(Object obj)
    {
        String sql = "VALUES (IDENTITY_VAL_LOCAL())";
        //or you can write "VALUES 11","VALUES
123455667","VALUES 755545"........
        //just write a function to get a value and let
the DB2 to execute.
        return sql;
    }

6)build torque source,and get the
D:\torque-3.0-src\torque-3.0\target\torque-3.0.jar
     D:\torque-3.0-src\torque-3.0\ant -jar
     
7)replace D:\torque3.0\lib\torque-3.0.jar with this
8)set classpath including the all jars within the
directory  D:\torque3.0\lib\ 
9)java Test
    OK!!!!!everything is OK!that's all my night work




__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

Re: obtaining native primary keys in DB2 V7.x

Posted by Martin Poeschl <mp...@marmot.at>.
could you please send a patch?

martin

James Wang wrote:

>0)download torque-3.0.zip ,and decompress it to
>d:\>torque3.0
>
>1)define the d:\>torque3.0\schema\project-schema.xml
>    note: the table'idMethod="native" and column's
>autoIncrement="true"
>
><?xml version="1.0" encoding="ISO-8859-1"
>standalone="no"?>
><!DOCTYPE database SYSTEM
>"http://jakarta.apache.org/turbine/dtd/database.dtd">
>
><database name="jetspeed">
>  <table name="USER" idMethod="native">
>    <column name="USER_ID" required="true"
>primaryKey="true" autoIncrement="true"
>type="INTEGER"/>
>    <column name="USER_NAME" type="VARCHAR"
>size="225"/>    
>    <column name="CREATEDTIME" type="TIMESTAMP"/>
>  </table>
></database>  
>
>2)d:\>torque3.0\ant -f build-torque.xml
>3)write a Test.java,insert the following code,put the
>file into d:\torque3.0\src\java,
>
>            Torque.init("Torque.properties");
>
>            /*
>             * Creating new objects.  These will be
>inserted
>             * into your database automatically when
>the
>             * save method is called.
>             */
>            User us = new User();
>            us.setUserId(111111111); //this line will
>not take effect for idmethod='native'
>            us.setUserName("james");
>            java.util.Date d =  new
>java.sql.Timestamp(System.currentTimeMillis());
>            us.setCreatedtime(new
>java.sql.Timestamp(System.currentTimeMillis()));
>            us.save();
>
>4)download the torque-3.0-src.zip and decompress it to
>d:\>torque-3.0-src
>  download jakarta-ant-1.5,connect to Internet
>
>5)modify
>D:\torque-3.0-src\torque-3.0\src\java\org\apache\torque\adapter\DBDB2App.java
>  modify the following method,
>
>    public String getIDMethodType()
>    {
>        return AUTO_INCREMENT;
>    }
>
>    public String getIDMethodSQL(Object obj)
>    {
>        String sql = "VALUES (IDENTITY_VAL_LOCAL())";
>        //or you can write "VALUES 11","VALUES
>123455667","VALUES 755545"........
>        //just write a function to get a value and let
>the DB2 to execute.
>        return sql;
>    }
>
>6)build torque source,and get the
>D:\torque-3.0-src\torque-3.0\target\torque-3.0.jar
>     D:\torque-3.0-src\torque-3.0\ant -jar
>     
>7)replace D:\torque3.0\lib\torque-3.0.jar with this
>8)set classpath including the all jars within the
>directory  D:\torque3.0\lib\ 
>9)java Test
>    OK!!!!!everything is OK!that's all my night work
>
>
>
>
>__________________________________
>Do you Yahoo!?
>SBC Yahoo! DSL - Now only $29.95 per month!
>http://sbc.yahoo.com
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
>  
>