Re: PosgreSQL Sequence
"Michael Nash JGlobal.com" <[email protected]>
| Newsgroups | gmane.comp.java.keel.user |
|---|---|
| Organization | JGlobal |
| Message-ID | <20040309113126.7e887e6f@jglobal> |
Wilfredo: If I understand it correctly, a Postgres sequence does essentially what the idgenerator component in Keel does - maintains a table for keeping sequence values. My first thought would be to use a Query class to retrieve the sequence value, then plug that value in to the persistent object before doing the "add" (all in a transaction, ideally). The advantage of Query is that you can use db-specific SQL, such as the nextval function, without actually including it in your code. The other choice would of course be to implement an IdGenerator class that *uses* the Postgres-specific syntax, then just assign that IdGenerator implementation to the appropriate persistents. I've not done an example of this myself, so there may be a better way to go about it, but I think that would work and not be very complex. The second route (using a custom IdGenerator) would have the advantage of requiring no extra code in your models at all, it would all be handled at the persistent level. Anyone else used sequences in Postgres directly? Mike On Tue, 9 Mar 2004 16:16:18 +0800 "Wilfredo Sellado" <wsellado-Lo/[email protected]> wrote: > I am having a problem when adding a row > unsing Persistent. I am using the existing > database in Postgres which I made before. > Before I was using Sequences for my primary keys. > In my DAO module, I just call the nextval postgres > function every insert to get the latest id value. > I would like to use same way in persisten so that > i wont have any modification in my existing > database schema. Anyone could help me. > > Thanks in advance! > > Pipo > > > _______________________________________________ > User mailing list > [email protected] > http://lists.keelframework.org/listinfo.cgi/user-keelframework.org -- Michael Nash JGlobal Ltd Next-Generation Web Application Development and Open Source Support http://www.jglobal.com Bahamas Commerce and Trade Offshore eCommerce Hosting and Business Services http://www.bahamascommerce.com