Re: Uniqueness of attributes ...

Chuck Hill <[email protected]> Mon, 3 May 2004 09:28:19 -0700
Newsgroups gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
Hi,

I think the common way to do this is to do a fetch while validating.  I 
don't like this because, as you point out, it leaves open an unhandled 
race condition.

The only certain way of doing this is with a unique constraint at the 
database level. Unfortunately that is anything but database specific.  
I try and give the unique index a name that I can recognize in code so 
that it can be parsed out of the exception thrown during saveChanges.  
Neither indexing nor database exceptions are done in anything even 
remotely resembling a standard way.  Some databases, OpenBase for 
example, don't even support named indexes.  If you really need database 
independence you are probably going to need to abstract this out and 
keep it in a database independent framework that can be added to your 
application.

Yes, this is somewhat of a hole in EOF but a hard one to plug due to 
lack of standardization.

Chuck


On May 3, 2004, at 2:15 AM, Ashley Aitken wrote:

>
> Howdy All,
>
> I need to ensure a non-primary key (non-foreign key) attribute is 
> unique.
>
> The "obvious" way of doing this is to do a fetch on that property when 
> validating the attribute to see if any records currently exist with 
> that value.
>
> Is that the best way of doing it (with EOF)?   Surely "another 
> process" could enter a row with that value between when I fetch to 
> check and then save the row ...
>
> Is there someway of telling the database (generically) that this 
> attribute should be unique, and it automatically causing an exception 
> if a duplicate value is saved.
>
> I don't want to get into database specifics, I want to keep this at 
> the EOF level.
>
> Thanks,
> Ashley.
>
> --
> Ashley Aitken
> Perth, Western Australia
> mrhatken at mac dot com
>
> _______________________________________________
> EOF mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/eof