• 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: Ken Anderson <email@hidden>
  • Date: Fri, 20 Feb 2009 14:31:00 -0500

What I like to do in these situations is:

- When the user wants to create, ask for the code, then insert the record into the database with just the code (and whatever primary key gets generated).
- If the insert fails, you can catch the unique constraint failure and tell the user, and they haven't wasted their time filling out a huge form.
- If the insert succeeds, the record is now in the table, and the user can fill in a form that has the code uneditable to update the remaining fields.


The advantages:

- The user doesn't fill in a big form that they don't need to.
- The interaction is very quick, reducing the potential for 2 users to create the same record (with the same code).


If you have a situation where the data might be used by some other process prior to it being properly filled in, I'll put an 'active' flag that by default is false, and then in the large form there will be a checkbox (defaulting to checked) for active, so it won't go active until the 2nd save.

Ken

On Feb 20, 2009, at 2:00 PM, Alan Ward wrote:


Add a unique constraint to the database. That is the only way this will work.
Your code below could return EOObjectNotAvailableException and then another instance
inserts the row before your insert. The database is your friend here. With the unique constraint
you don't need to fetch first, just do the insert and see if it throws.


Alan


On Feb 20, 2009, at 10:40 AM, 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

_______________________________________________ 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>)
 >Re: opposite method to objectMatchingKeyAndValue (From: Alan Ward <email@hidden>)

  • Prev by Date: Re: Using MS SQL Server with WO
  • Next by Date: Re: Migration/Frontbase Implementation Question
  • Previous by thread: Re: opposite method to objectMatchingKeyAndValue
  • Next by thread: Re: opposite method to objectMatchingKeyAndValue
  • Index(es):
    • Date
    • Thread