• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Best way to generate unique IDs that are not PKs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Best way to generate unique IDs that are not PKs (From: Florijan Stamenkovic <email@hidden>)

  • Prev by Date: Re: examining the SQL?
  • Next by Date: WebServerResources & subfolders
  • Previous by thread: Best way to generate unique IDs that are not PKs
  • Next by thread: Re: Best way to generate unique IDs that are not PKs
  • Index(es):
    • Date
    • Thread