• 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: Enforcing uniqueness of data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enforcing uniqueness of data


  • Subject: Re: Enforcing uniqueness of data
  • From: Arturo PĂ©rez <email@hidden>
  • Date: Wed, 7 Sep 2005 20:47:25 -0400

Chuck Hill wrote:
On Sep 7, 2005, at 10:00 AM, Daniel Eggert wrote:
I need the login of my user EO to be unique. Since the login is something the user enters, it is not the PK.

How would I go about ensuring this? If I fetch from the database and then write if it is unique, someone might be able to write to the database in the meantime.

This post
<http://lists.apple.com/archives/webobjects-dev/2004/Jun/ msg00249.html>
suggests locking. Is it a sane approach? How would I do such a thing with EOF?


I'd consider the other option that it mentions, adding a unique constraint. You will then have to catch exceptions from save changes and determine if the exception was a DB server side exception (EOGeneralAdaptorException) and, if so, if the exception was raised due to a violation of the unique constraint. Unfortunately, the exceptions and errors returns from DB servers are vendor specific so you will end up writing handling code for each server you need to support.
You can do the locking too, and it is possible, but I can't whip the EOF code off the top of my head.
Chuck


In my code I trap the EOGeneralAdaptorException, extract the EOAdaptionOperation (which had failed), extract the JDBCException and then check the SQL-92 standard SQLState provided by that. For a SQL standard database the SQLState will contain a String of the form 23XXX where the 23 denotes an integrity constraint failure (uniqueness, check, etc). I think, for my database, the UNIQUE failure was a 23505 which, as it turns out, is standard SQL for a UNIQUEness failure.

So, in you situation, I do a saveChanges(), trap the exception as above, if it's a 23505 I convert it into a validation error. I personally did not like the idea of 2 hits against the database and the possibility that the uniqueness of an ID could change while the user was updating it.


YMMV, -arturo


_______________________________________________ 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
  • Prev by Date: Re: Unable to write file (java file creation)
  • Next by Date: Re: Java Monitor Woes
  • Previous by thread: Re: Enforcing uniqueness of data
  • Next by thread: Problem with objectsWithFetchSpecification
  • Index(es):
    • Date
    • Thread