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 protected])
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      ([email protected])
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