db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Boehm" <bo...@nortel.com>
Subject How to handle Postgresql sequence in om generation?
Date Wed, 30 Apr 2008 18:57:36 GMT
I'm  a novice at both torque and Java. I am using
postgresql-8.3-603-jdbc3.jar. 

I've have the following schema excerpt

    <table name="fs_list">
        <column name="fs" required="true" size="2147483647" type="VARCHAR"/>
        <column default="nextval('fs_list_fsid_seq'::regclass)"
            name="fsid" primaryKey="true" required="true" type="INTEGER"/>
        <column name="rhost" size="2147483647" type="VARCHAR"/>
        <column default="now()" name="first_report" type="TIMESTAMP"/>
        <column default="now()" name="last_report" type="TIMESTAMP"/>
        <column default="0" name="fullpercent" type="INTEGER"/>
        <column default="0" name="capacity" type="DOUBLE"/>
    </table>

for the table

\d fs_list
                                      Table "public.fs_list"
    Column    |           Type           |                       Modifiers               
        
--------------+--------------------------+--------------------------------------------------------
 fs           | text                     | not null
 fsid         | integer                  | not null default nextval('fs_list_fsid_seq'::regclass)
 rhost        | text                     | 
 first_report | timestamp with time zone | default now()
 last_report  | timestamp with time zone | default now()
 fullpercent  | integer                  | default 0
 capacity     | double precision         | default 0
Indexes: fs_list_pkey primary key btree (fsid),
         fs_list_fs_key unique btree (fs)


The sequence fs_list_fsid_seq is

\d fs_list_fsid_seq
Sequence "public.fs_list_fsid_seq"
    Column     |  Type   
---------------+---------
 sequence_name | name
 last_value    | bigint
 increment_by  | bigint
 max_value     | bigint
 min_value     | bigint
 cache_value   | bigint
 log_cnt       | bigint
 is_cycled     | boolean
 is_called     | boolean

This generates java code that looks like this

          copyObj.setFsid( nextval('fs_list_fsid_seq'::regclass));

which won't compile.

I read the PostgreSQLFAQ and Scott Eade mentioned a similar problem
back in 2003

  There might be another way to handle sequences for wiser heads to
  figure out. Using maven torque:jdbc with Postgresql 7.4.1-jdbc3, my
  SERIAL columns were converted to XML as follows

         <table name="company">
          <column default="nextval('public.company_id_seq'::text)"
              name="id" primaryKey="true" required="true" type="INTEGER"/>
          ...

  While there are lots of problems with that snippet (such as the fact
  that the java produced by subsequent the maven torque:om goal is
  buggy), perhaps this could be recognized as calling the Postgresql
  internal function nextval [WWW] Postgresql--Sequence-Manipulation
  Functions, and somehow link that with the ability to define such calls
  in java, as in [WWW] Postgresql--Calling Stored Functions. Grepping
  the source tree, I saw calls to nextval in the Oracle driver, but I
  didn't explore further. 


However, I am at a loss on what the correct way to fix this is. I
don't necessarily have to have access to this table, but I would like
to correct it.

Any suggestions or pointers to information on what needs to be done
would be appreciated.

-- 
Eric M. Boehm                  /"\  ASCII Ribbon Campaign
boehm@nortel.com               \ /  No HTML or RTF in mail
                                X   No proprietary word-processing
Respect Open Standards         / \  files in mail

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


Mime
View raw message