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      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/qdolan% 40gmail.com

This email sent to [EMAIL PROTECTED]



--
Seeya...Q

Quinton Dolan - [EMAIL PROTECTED]
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      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/eviltofu% 40mac.com

This email sent to [EMAIL PROTECTED]

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/flor385% 40mac.com

This email sent to [EMAIL PROTECTED]

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to