Re: Newbie question
Re: Newbie question
- Subject: Re: Newbie question
- From: David LeBer <email@hidden>
- Date: Thu, 07 Apr 2011 08:15:17 -0400
On 2011-04-07, at 7:02 AM, Amedeo Mantica wrote:
> do you insert the Enterprise Object in the Editing Context immediately after creation or when submitting form ?
Create and insert together, always.
Follow the commandments:
<http://wiki.objectstyle.org/confluence/display/WO/EOF-Using+EOF-The+EOF+Commandments>
>
>
> On 07/apr/2011, at 12.39, Pascal Robert wrote:
>
>>
>> Le 2011-04-06 à 23:48, Chuck Hill a écrit :
>>
>>> That is going to leave you with a race condition. The only certain way to prevent the creation of duplicates is to put an unique constraint on the database. Then you have to catch the database exception (EOGeneralAdaptorException) in your code and handle appropriately. The ugly part is that the exception message returned is different for each database which makes doing this in a database agnostic way slightly challenging.
>>
>> Example for H2:
>>
>> try {
>> editingContext().saveChanges();
>> } catch (EOGeneralAdaptorException ex) {
>> EOAdaptorOperation operation = (EOAdaptorOperation)((NSMutableArray)ex.userInfo().valueForKey("EOAdaptorOperationsKey")).objectAtIndex(0);
>> if (operation.exception().getMessage().contains("Unique index or primary key violation")) {
>> throw new SomeException();
>> }
>>
>>> Chuck
>>>
>>> On Apr 6, 2011, at 8:21 PM, Paul D Yu wrote:
>>>
>>>> Based on the column/attribute in your DB/EOModel that would make your consider the record/EO to be duplicate of another, you should implement a method that would check for those values in the existing set.
>>>>
>>>> I don't think there is a one line solution to what you are seeking.
>>>>
>>>> Paul
>>>> On Apr 6, 2011, at 10:52 PM, Mr Tonnew wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> How do I avoid committing duplicate entries in the DB? I have a form
>>>>> from where I take entries. Is there a single line of code that can
>>>>> accomplish this?
>>>>>
>>>>> MR
>>>>> _______________________________________________
>>>>> 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
>>>
>>> --
>>> Chuck Hill Senior Consultant / VP Development
>>>
>>> Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
>>> http://www.global-village.net/products/practical_webobjects
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> 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
;david
--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site: http://codeferous.com
blog: http://davidleber.net
profile: http://www.linkedin.com/in/davidleber
twitter: http://twitter.com/rebeld
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org
_______________________________________________
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