• 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: Shared editing context: rules of engagement
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shared editing context: rules of engagement


  • Subject: Re: Shared editing context: rules of engagement
  • From: Lachlan Deck <email@hidden>
  • Date: Thu, 19 Apr 2007 18:36:02 +1000

On 19/04/2007, at 5:57 PM, Fabian Peters wrote:

Am 19.04.2007 um 08:42 schrieb Lachlan Deck:

just wanting to clarify the do's/don'ts...

I'm getting "Cannot obtain globalId for an object which is registered in an other than the databaseContext's active editingContext..."

Ok, so the object you're trying to establish a relation with does not seem to be in the shared EC (SEC).


Okay, my understanding is that you ought _not_ have relationships going from a shared entity to a non-shared entity.

Yes.

Fine, so when the application starts up I've got some code that removes any such relations from the entities as they are registered (but leaving intact the relations from the non-shared to the shared). This allows me to specify an array property of "SharedEntities" relevant to that application.

Mmhhh, are your sure this is working correctly? I've never done anything like this and would think that it's rather tricky to get such a setup to work?

It seems to work well. i.e., the rest of the app functions well (for fetching data anyway).


Now according to the api, I can create a regular editing context, fetch the object into it, change it and save and that'll be all there is to it. Nice theory.

You mean you fetch some non-shared EO into a standard EC, set up a relation with a shared EO and save? Yes.

Yep.

I'm actually not needing to change that object but am setting the relationship from a non-shared entity to the shared one. However the exception I'm an exception that's preventing me from saving the context.

// Okay so I'm creating a editing context for editing like so:
public MyEditingContext editingContext() {
if ( _wec == null ) {
_wec = new MyEditingContext( clientForRequest( context().request () );

?

Never mine that part :-)

_wec.setSharedEditingContext( null );

Why are you setting the SEC to null here? If in this EC you're trying to set up a relationship to a shared EC, this is going to fail. Or is this the EC you're going to use to remove relationships to non-shared EOs from EOs that are to be shared?

No this is the ec where I'm trying to save a non-shared entity object (with a relation to a shared ec object). The api says to set the shared ec for such an ec to null. (See last paragraph in class description)


}

// and in the awakeFromInsertion(EOEditingContext) I'm doing the following:
{
if has reverse relation
// Note: this is where it's useful Mike :-)
addObjectToBothSidesOfRelationshipWithKey( aClient, key );
else
takeValueForKey( aClient, key );
}

If it's not the setting to null of the SEC above,

Woops... I know what the problem was. Ugh... Lazy!!!
Forgot to add a bit of code back into my EOEditingContext subclass that localises the shared objects.


then I'd say your "code that removes any such relations from the entities as they are registered" seems suspicious.

It was definitely *my* code. That part is true. The other part was not the problem. The fix was ensuring that my eoeditingcontext subclass sets its shared ec to null and internally localising shared objects. Now I can save. Great.


Could we get more details on that?

Sure. In my base framework I've a WOApplication subclass.

public ISHApplication() {
	super();

	<...>

//
// Add the application class as observer for various things
//
// disabled EOModel.EntityLoaded... as it seems it's too early to mangle the entities.
//NSNotificationCenter.defaultCenter().addObserver( this, new NSSelector( "_entityLoading", new Class[] { NSNotification.class } ), EOModel.EntityLoadedNotification, null );
NSNotificationCenter.defaultCenter().addObserver( this, new NSSelector( "_entityLoaded", new Class[] { NSNotification.class } ), ISHEntity.EntityHasLoadedNotification, null );
NSNotificationCenter.defaultCenter().addObserver( this, new NSSelector( "_modelAdded", new Class[] { NSNotification.class } ), EOModelGroup.ModelAddedNotification, null );
NSNotificationCenter.defaultCenter().addObserver( this, new NSSelector( "_reloadSharedEntities", new Class[] { NSNotification.class } ), EOSharedEditingContext.DefaultSharedEditingContextWasInitializedNotifica tion, null );


	<...>

// to be able to manipulate relationships per entities. There seems to
// be a race condition of some kind.
// So once all the models are loaded we'll munge the relationships
en = EOModelGroup.globalModelGroup().models().objectEnumerator();
while ( en.hasMoreElements() )
{
Enumeration dn;
EOModel aModel;

aModel = ( EOModel )en.nextElement();
NSLog.debug.appendln( "Model relationships munging...:" + aModel.name() );
dn = aModel.entities().objectEnumerator();
while ( dn.hasMoreElements() )
NSNotificationCenter.defaultCenter().postNotification ( ISHEntity.EntityHasLoadedNotification, dn.nextElement() );
}


	<...>
}

<...>

/**
*<p>Auto-removes any relationships from the runtime where the source
*entity is contained by <code>sharedEntities</code> but where the
*destination entity of the relationship is not shared
*(unless the destination is a join between two shared entities).</p>
*
*<p>Note:you will need to override such relationship keys in your subclasses
*to handle fetching of these objects.</p>
*
*@see<a href="http://en.wikibooks.org/wiki/Programming:WebObjects/EOF/ Using_EOF/EOSharedEditingContext">SharedContextbestpractices</a>
*@paramaNotification-thenotification
*/
public void _entityLoaded( NSNotification aNotification ) { <...> }


If you'd like to know more feel free to ask... but I've just kept the email shorter for now.

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


References: 
 >Shared editing context: rules of engagement (From: Lachlan Deck <email@hidden>)
 >Re: Shared editing context: rules of engagement (From: Fabian Peters <email@hidden>)

  • Prev by Date: Fetch objects: Error in MYSQL or WO
  • Next by Date: Re: Fetch objects: Error in MYSQL or WO
  • Previous by thread: Re: Shared editing context: rules of engagement
  • Next by thread: Re: Shared editing context: rules of engagement
  • Index(es):
    • Date
    • Thread