Re: locking editing context when removing item
Re: locking editing context when removing item
- Subject: Re: locking editing context when removing item
- From: "Jonathan Fleming" <email@hidden>
- Date: Mon, 16 Feb 2004 18:29:53 +0000
From: Jonathan Rochkind <email@hidden>
To: "Jonathan Fleming" <email@hidden>,
email@hidden
Subject: Re: locking editing context when removing item
Date: Mon, 16 Feb 2004 10:44:45 -0600
Yes, I think it would definitely be a good idea to lock the EC before
calling deleteObject on it. In general, you should ensure an EC is locked
before just about anything at all with it; an EC should pretty much always
be locked before dealing with it.
Note that if 'ecTb' in the first block of code is not the same EC as 'ec'
in the second block----then unless there's other code you're not showing
us, this isn't going to do anything. Calling ecTb.deleteObject() just
tells ecTb to register an EO as 'deleted'. ecTb now tracks that EO as
deleted, fine. But unless you call saveChanges() on ecTb, nothing is going
to happen.
Correct. This is done on purpose
Once you call saveChanges on ecTb,
the saveChages is called with the defaultEditingContext (referenced in this
example as ec)
the change is either committed to the db, or again registered with a parent
EC if ecTb is a nested EC.
Tell me if i'm wrong, but ain't all other editing contexts automatically
nested in the defaultEditingContext? I use this sort of setup a lot for one
reason or another :^/
Regardless I shall go around my app and now lock all my deletes as this is
the only place that i don't lock. Just didn't think it was necassary, but
thinking about it, you're updating, so...
Jonathan :^)
Hope this helps,
--Jonathan
At 2:39 PM +0000 2/16/04, Jonathan Fleming wrote:
Just checking really... do I need to put a lock on the ec when removing an
item from its own ec? So would this code be wrong or cause problems?:
// the default ec is instatiated somewhere else earlier in the
code
EOEditingContext ec = session().defaultEditingContext();
....................
// remove tbAddressAdminUser from queryResults
queryResults.removeObject(tbAddressAdminUser);
// get objects editing context
EOEditingContext ecTb =
tbAddressAdminUser.editingContext();
// remove tbAddressAdminUser from object graph
ecTb.deleteObject(tbAddressAdminUser);
// save changes made in editing context to object
store
....................
// the save is done later with the default ec
ec.saveChanges();
Advanced Thanks
Jonathan :^)
_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger
http://www.msn.co.uk/messenger
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_________________________________________________________________
Sign-up for a FREE BT Broadband connection today!
http://www.msn.co.uk/specials/btbroadband
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.