Re: EOEditingContext in Application
Re: EOEditingContext in Application
- Subject: Re: EOEditingContext in Application
- From: Lachlan Deck <email@hidden>
- Date: Wed, 2 Jul 2008 10:35:05 +1000
On 01/07/2008, at 10:18 PM, Drew Thoeni wrote:
Thanks. This looks like the path I was looking for.
However, in the docs referenced below, it seems to say use something
like this in the session:
public NSArray languageList() {
return
(NSArray
)EOUtilities
.objectsWithFetchSpecificationAndBindings( defaultEditingContext(),
"Language", "FetchAllAvailableLanguages", null);
}
I wouldn't be surprised if you found the above sufficient (so long as
in your model you've specified in the shared tab that Language records
fetched with the above fetchspec name are shared AND your default
editing context has a sharedEditingContext ==
EOSharedEditingContext.defaultSharedEditingContext().
I've never defined fetch specs in the model that way.
Bear in mind that you cannot edit these records. In order to make
changes to records that are shared, they need to be localized into an
ec that does not have a shared ec backing it. Then those changes will
be auto picked up by the shared ec.
That code works (I also set the fetchspec in EOModel to "shared",
but I'm wanting to make sure I'm actually accomplishing my goal.
That is, does the above code still get loaded into session memory?
Or, because it is designated as defaultEditingContext and drawn from
a "shared" fecthspec, does WO handle this smartly behind the scenes?
I kind of expected the code to be more like this in the application:
private EOSharedEditingContext sharedEC = new
EOSharedEditingContext();
Don't do that. Do:
EOSharedEditingContext.defaultSharedEditingContext()
What Art's suggesting is something like this...
public class Application ...
{
public NSArray sharedRecordsForEntity( String entityName, String
fetchSpecName )
{
EOSharedEditingContext sec =
EOSharedEditingContext.defaultSharedEditingContext();
boolean isAlreadyBound = false;
NSDictionary stuff =
sec.objectsByEntityNameAndFetchSpecificationName();
NSDictionary entityStuff = stuff.valueForKey( entityName );
NSArray records = entityStuff == null ? null :
entityStuff.valueForKey( fetchSpecName );
boolean isAlreadyBound = records != null;
if ( !isAlreadyBound )
{
EOFetchSpecification fetchSpec =
EOModelGroup.defaultGroup().fetchSpecificationNamed( fetchSpecName,
entityName );
if ( fetchSpec == null )
// throw exception maybe
sec.bindObjectsWithFetchSpecification( fetchSpec, fetchSpecName );
return sharedRecordsForEntity( entityName, fetchSpecName );
}
return records;
}
}
with regards,
--
Lachlan Deck
_______________________________________________
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