So, it's not portable either... right?

That's actually the problem; it _never_ is portable. It has been
discussed over and over again on the list, especially between September
2000 and March 2001. The browsable list archives are available at
http://archives.java.sun.com
A lot of useful resources are there to reap on
http://www.theserverside.com altough many are about how to generate the
numbers on your own instead of using a DB's own sequence generator
mechanisms.

Basically, the best solution depends on your system. Here's a checklist.

Are J2EE apps the only ones accessing the DB? If true, is it a clustered
app?
What is the write/read ratio?
Do you need CMP sequence generation on every table?

Having being involved in a number of projects on different RDBMS, and my
principal responsibility being reusing code as components(binary reuse
as much as possible), I've found that the fastest/cheapest way to
implement PK creation is:

String pk = ("" + (long) (Math.random() * Math.pow(10,10) ) );

Yielding a 10 digit ::non sequential:: pk. As _most_ systems I've worked
with the chances of collision are within acceptable parameters, I
disregarded the possibility of collisions. Of course, this may not apply
to all cases, but speed gains were way more important than the possible
collisions, esp. since we'd trap them somewhere else.

To obtain a sequential PK, the portable & efficient way is to keep a
Hi-Lo Counter Bean or something like it.
That's why I use String for my pk's, btw. I can plug-in a more accurate
pk alg. At a later date if the situation demands it.

I think you may be able to modify the Hi/Lo implementation given here:

http://sourceforge.net/projects/ejbutils/

To make it work in a sequential manner instead of using GUIDs, if what
you're after is a true Sequence.

HTH,


Juan Pablo Lorandi
Chief Software Architect
Code Foundry Ltd.
[EMAIL PROTECTED]

Barberstown, Straffan, Co. Kildare, Ireland.
Tel: +353-1-6012050  Fax: +353-1-6012051
Mobile: +353-86-2157900
www.codefoundry.com


> -----Original Message-----
> From: Vincent Shek [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 21, 2002 9:33 PM
> To: Juan Pablo Lorandi
> Subject: RE: Re: How to use sequence generator for primary key in CMP?
>
>
>
> Juan,
>
> I didn't show the code the Sequence class, basically, it's
> just a query to your favorite database to get the sequence
> number.. For Oracle, you would do something like this:
>
> SELECT sequencename.NEXTVAL FROM SYS.DUAL"
>
> Hopes this help,
>
> Vinecnt
>
> -----Original Message-----
> From: Juan Pablo Lorandi [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 21, 2002 1:25 PM
> To: [EMAIL PROTECTED]
> Subject: Re: How to use sequence generator for primary key in CMP?
>
>
> I'm sorry for the ignorance, but for my enlighment, I would
> appreciate an answer to these questions:
>
> 1) What's this Sequence class? I couldn't find it in either
> java.sql nor javax.sql
> 2) Do all databases support a db-independent(portable) way of
> generating sequence numbers?
>
> TIA,
>
> Juan Pablo Lorandi
> Chief Software Architect
> Code Foundry Ltd.
> [EMAIL PROTECTED]
>
> Barberstown, Straffan, Co. Kildare, Ireland.
> Tel: +353-1-6012050  Fax: +353-1-6012051
> Mobile: +353-86-2157900
> www.codefoundry.com
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to