Re: DB uniqueness constraints and dealing with them
Re: DB uniqueness constraints and dealing with them
- Subject: Re: DB uniqueness constraints and dealing with them
- From: Florijan Stamenkovic <email@hidden>
- Date: Thu, 03 Jul 2008 23:01:31 -0400
The save -> error check is exactly what I had in mind, sorry if I was
not clear about it. However, I would rather like to delete the newly
saved EO, and throw a validation exception. But this is only possible
if I can find the exactly same EO, once before it saved to the db,
and once after. Is that possible? Huh, never thought about this.
To answer Q's question, yes, it is a race condition, but a rather
funky one. Because each thread, regardless in which app instance or
even which machine they are one, checks for the record uniqueness
after it has saved it. So, it can happen that there are two records
saved that violate the uniqueness, but it will be detected. And the
EO created in the thread that detected the uniqueness violation
should be deleted. As far as I can see, this can never result in
having the uniqueness violated. In some circumstances however it
could result in all attempts failing. That would be the race
condition in this setup... If both processes manage to save at first,
then the first process detects the violation, but the second process
kicks in before the first deletes it's EO, then the second one will
also detect a violation. Both fail. See what I mean?
But perhaps I do not see it clearly, and somehow uniqueness could be
violated? I've been trying to run multithreaded (non synchronized)
scenarios in my head, and I can never come to one in which the
uniqueness is violated and not detected.
F
On Jul 03, 2008, at 20:30, Jerome Chan wrote:
What about doing
save -> if error check to see if existing record exists and if so
throw up a duplicate error ?
On Jul 4, 2008, at 7:52 AM, Q wrote:
On 04/07/2008, at 2:58 AM, Florijan Stamenkovic wrote:
Hi all,
While reading older discussions on dealing with DB uniqueness
restraints I've found out that the EOGeneralAdaptorException
thrown differs among databases. Is there some generic code that
deals with this in absolute terms ( don't you just *love* the
word absolute being used in conjunction with software :) ? If
there is in WOnder, could someone please be so kind to point me
in the right direction (which part of WOnder) so I can look at it?
Or should I write some pure EOF code like: Fetch -> Check
uniqueness -> Create new record -> Save -> Fetch -> Check, or
something along those lines?
I don't know about you but this just screams race condition to me.
However unlikely it may be to happen trying to do uniqueness
without using an atomic operation is extremely painful to get
right, and difficult to test properly.
This would assume that I know which attributes should be unique
in code, which can be done. I'd rather not deal with this like
this, it seems a nuisance.
Thanks,
Flor
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com
This email sent to email@hidden
--
Seeya...Q
Quinton Dolan - email@hidden
Gold Coast, QLD, Australia (GMT+10)
Ph: +61 419 729 806
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com
This email sent to email@hidden
_______________________________________________
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