Re: Best way to generate unique IDs that are not PKs
Re: Best way to generate unique IDs that are not PKs
- Subject: Re: Best way to generate unique IDs that are not PKs
- From: shaun <email@hidden>
- Date: Tue, 02 Jan 2007 13:54:33 +1030
Florijan Stamenkovic wrote:
Hi all,
I have a need in several of my tables to generate identifying numbers,
but relative to a certain relationship. So, if there is a Book, I need
to generate number 6 for it if Author currently relates to 5 other
books... I have an approach of doing this, please anyone tell me if
there is a better way to do it!
My approach:
1. Lock the working thread on a monitor that is "static final" in my
SessionWorker class
2. Get the next number by using aBook.valueForKeyPath
("email@hiddeneNumber"); //can not use @count in case of
previous deletions
3. Set the next number in aBook
4. Save the changes of my working editing context
5. Release the synchronization lock
Questions:
Is there way to use EOF locking to lock on the database? It seems to me
that would be more appropriate for what I am doing then the plain Java
thread synching, and would work even if there were multiple application
servers running, where the above approach would not. Any other ideas
where this might flop and how to prevent it?
You might want to put a DB constraint on the column if you haven't
already. You could then catch the constraint violation exception and
take appropriate action.
I use a custom database function to do this type of thing. I use raw
rows sql to select the next value from the function, then stuff the
value into the relevant EO attribute.
cheerio,
- shaun
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden