• 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: [SOLVED] Re: DB uniqueness constraints and dealing with them
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [SOLVED] Re: DB uniqueness constraints and dealing with them


  • Subject: Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
  • From: Miguel Arroz <email@hidden>
  • Date: Fri, 4 Jul 2008 16:36:49 +0100

Hi!

What I do in those situations is searching for the name of the constraint. Like:

catch (EOGeneralAdaptorException saveException) {
if (Util.isOptimisticLockingFailure(saveException)) {
NSLog.out.appendln("saveAnswersOnSurvey - Optimistic locking failure");
} else if ( saveException .getMessage().contains("unique_respondent_number_for_survey") ) {
NSLog.out.appendln("saveAnswersOnSurvey - unique_respondent_number_for_survey failure");
} else if ( saveException .getMessage().contains("respondent_multiplier_unique") ) {
NSLog.out.appendln("saveAnswersOnSurvey - respondent_multiplier_unique failure");
} else if( saveException.getMessage().contains("unique_uid_per_channel") ) {
NSLog.out.appendln("saveAnswersOnSurvey - unique_uid_per_channel failure");
} else {
throw saveException;
}
}


In PostgreSQL it works. I don't know if it works on other DBs, but I suppose the error message will contain the constraint name somehow. Anyway, test it on the DBs you use.

  Yours

Miguel Arroz


} On 2008/07/04, at 16:11, Florijan Stamenkovic wrote:

One more question though... An adapter exception *is* thrown, regardless of the database backing EOF, right? No standardized info is provided, but it is guaranteed that the exception is thrown, right???

F

On Jul 04, 2008, at 11:03, Florijan Stamenkovic wrote:

Right all, well, thanks everyone for sinking that ship of an idea down to the abyss, where it apparently belongs :)

Arghhh... So, the seems to be no way to really properly handle this, is there?

Paul, thanks for the code, I am currently deploying on OpenBase, I will look into what kind of info the adapter exception gives me there... Perhaps your code will help.

Again, many thanks everyone from saving me from attempting this.

F

On Jul 04, 2008, at 03:08, Q wrote:


On 04/07/2008, at 1:01 PM, Florijan Stamenkovic wrote:

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?

Now try and think about the case for three simultaneous violations, network, database or application level disruption and how to deal with contention and retries and your head will start to really hurt.. I know mine does.


In a word, don't try it, ok that's three words. Unless you can do it atomically with either database level uniqueness, or a table level locking you are going to just torture yourself.

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.

There are probably plenty of reasons, they just aren't obvious. What if the detection detects a conflict but the reversal fails?


--
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: 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

http://www.survs.com

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

  • Follow-Ups:
    • Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
      • From: Neil MacLennan <email@hidden>
References: 
 >DB uniqueness constraints and dealing with them (From: Florijan Stamenkovic <email@hidden>)
 >Re: DB uniqueness constraints and dealing with them (From: Q <email@hidden>)
 >Re: DB uniqueness constraints and dealing with them (From: Jerome Chan <email@hidden>)
 >Re: DB uniqueness constraints and dealing with them (From: Florijan Stamenkovic <email@hidden>)
 >Re: DB uniqueness constraints and dealing with them (From: Q <email@hidden>)
 >[SOLVED] Re: DB uniqueness constraints and dealing with them (From: Florijan Stamenkovic <email@hidden>)
 >Re: [SOLVED] Re: DB uniqueness constraints and dealing with them (From: Florijan Stamenkovic <email@hidden>)

  • Prev by Date: Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
  • Next by Date: Re: Practical Webobjects Utilities Framework
  • Previous by thread: Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
  • Next by thread: Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
  • Index(es):
    • Date
    • Thread