• 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: opposite method to objectMatchingKeyAndValue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: opposite method to objectMatchingKeyAndValue


  • Subject: Re: opposite method to objectMatchingKeyAndValue
  • From: Stamenkovic Florijan <email@hidden>
  • Date: Fri, 20 Feb 2009 14:48:13 -0400

Gus,

Bringing this back to the list. Sorry about going off-list, I mistakenly hit "Reply"...

On Feb 20, 2009, at 14:25, Gustavo Pizano wrote:

Hello Florijan.

I made a try-test trying to insert a product that was already there, to see which kind of exception EOF will throw, I go this one, EOGeneralAdaptorException, of course after setting up in the DB a unique constrain for the code, so what about if I catch that exception and inform the user?

In principle, this is exactly what you should do. However, an EOGeneralAdaptorException can be raised for various reasons, not only a violation of the uniqueness constraint. And since the exception does not have an API to tell you what the exact reason is, you need to parse the textual information that the exception contains to determine what happened. Which is specific to the database you are using. Depending on the DB, people on the list might be able to give you the code that deals with this.


F

On 20.2.2009, at 19:14, Stamenkovic Florijan wrote:

Hey Gus,

The code you intend to use does not guarantee that the code value will be unique in the database. The only way of achieving this with a 100% guarantee is to have a uniqueness constraint on the given column in the database. In short, what you are doing is not a good way to deal with this requirement. I suggest you look into this, there is plenty of discussions in the archives on the subject, most of them going into much more depth then would fit into this email. Search for "uniqueness constraint", "unique value", "unique column" etc...

That said, I believe you are looking for the following code pattern (you do not need to throw any kind of an additional exception):

try{
// this line potentially throws an exception
Product p = (Product )EOUtilities .objectMatchingKeyAndValue (editingContext(),"Product",Product.CODE_KEY, code);


// if this line is reached, then the object *is* found in the database, so inform the user about it
informUser();


}catch(EOObjectNotAvailableException ex){
// at the moment of fetching the object with the given code was not found in the db
insertObject();
}


HTH,
F

On Feb 20, 2009, at 13:40, Gustavo Pizano wrote:

Hello all.
Well I want to insert a EObject into the database, I found that the objectMatchingKeyAndValue will return me the object with the given parameters, and if not found will throw and EOObjectNotAvailableException.
Now, I need to insert the new objects, but I need to be sure that they don't exist in the database, the entity has a attribute called code, which is not the primary key, so I was thinking in using the following.


try{
Product p = (Product )EOUtilities .objectMatchingKeyAndValue (editingContext(),"Product",Product.CODE_KEY, code);
}catch (EOObjectNotAvailableException e){


//insert the new object into the EC, and save it

}

the problem i see, is that if the object in fact exists, I must alert the user that this particular product exist already, so Im feeling doing the things in the wrong way, I was thinking in putting a throw exception before the catch and with that alert the user... but i dunno i feel kinda weird doing this...



Suggestions??


Thanks

Gus




_______________________________________________ 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
References: 
 >opposite method to objectMatchingKeyAndValue (From: Gustavo Pizano <email@hidden>)

  • Prev by Date: opposite method to objectMatchingKeyAndValue
  • Next by Date: Re: opposite method to objectMatchingKeyAndValue
  • Previous by thread: opposite method to objectMatchingKeyAndValue
  • Next by thread: Re: opposite method to objectMatchingKeyAndValue
  • Index(es):
    • Date
    • Thread