Re: Shared editing context: rules of engagement
Re: Shared editing context: rules of engagement
- Subject: Re: Shared editing context: rules of engagement
- From: Fabian Peters <email@hidden>
- Date: Thu, 19 Apr 2007 18:23:42 +0200
Hi Dov,
Am 19.04.2007 um 16:40 schrieb Dov Rosenberg:
We have been using the SharedEditingContext for a couple of years
and have
finally gotten it pretty stable and useful. Here are some things we
did:
I'm using the SharedEditingContext (SEC) a lot myself, so here are my
2 cents:
1. Make sure to set the reference to the SharedEditingContext to
null on ANY
regular editing context that you create i.e. Doing
_wec.setSharedEditingContext( null );
Why would you do that? IMHO this is what you do if you plan to change
objects that are being shared, i.e. are in the SEC. In normal
operation however, you won't set the SEC to null?
2. Retrieve the data you need into the shared editing context your
self -
don't try to grab it from somewhere else. If you have to use
localInstanceOfObject() to get a copy
I'm not sure I get your point here: If you set the SEC to null on any
EC you create, you'll of course have to localInstance...() the shared
EOs manually into the EC to be able to establish relationships to
them. But IMHO it's one of the advantages of using the SEC that you
can use references to EOs in the SEC and link to these EOs from EOs
in any EC (with the SEC not set to null!).
3. Never make any changes to an EO in the scope of the shared editing
context - i.e. Don't do anything like saveChanges(). If you need to
make
changes create a new editingcontext, retrieve the data and then
save it
there (observing rule #1). The object store coordinator will notify
the
shared editing context of the change for you
Yes, except for newly inserted EOs that you want to be shared. For
these, you'll have to use the SEC's
bindObjectsWithFetchSpecificationName after saving them, to make them
available.
4. If you are using the defaultSharedEditing context you don't need
to lock
anything. Make sure that you DO lock any editing contexts that you
create
manually and make sure they get unlocked properly (in the FINALLY
block)
If you obey these rules things should behave nicely, if you stray
at all you
are in for a world of bizarre behaviors and frustrating issues that
are a
PIA to debug.
Yep, I've had my share of "interesting" errors. But the Wikibook
section on the SEC covers everything necessary, I think: <http://
en.wikibooks.org/wiki/Programming:WebObjects/EOF/Using_EOF/
EOSharedEditingContext> Be sure to check out the original Apple
documentation on the SEC, which is linked from the Wikibook: <http://
developer.apple.com/documentation/LegacyTechnologies/WebObjects/
WebObjects_4.5/System/Documentation/Developer/WebObjects/DeltaDoc/
EOF.html#CBGCHAIA>
cheers
Fabian
On 4/19/07 2:42 AM, "Lachlan Deck" <email@hidden> wrote:
Hi all,
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..."
Okay, my understanding is that you ought _not_ have relationships
going from a shared entity to a non-shared entity. 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.
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.
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() );
_wec.setSharedEditingContext( null );
_wec.setStopsValidationAfterFirstError( false );
}
}
// 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 );
}
Any ideas? What have I missed?
Thanks muchly...
with regards,
--
Lachlan Deck
[2007-04-19 15:57:53 EST] <WorkerThread14>
<com.webobjects.appserver._private.WOComponentRequestHandler>:
Exception occurred while handling request:
java.lang.RuntimeException: <WOLongResponsePage> Exception occurred
in long response thread: com.webobjects.foundation.NSForwardException
[java.lang.IllegalStateException] Cannot obtain globalId for an
object which is registered in an other than the databaseContext's
active editingContext
<...>
[2007-04-19 15:57:53 EST] <WorkerThread14>
java.lang.RuntimeException: <WOLongResponsePage> Exception occurred
in long response thread: com.webobjects.foundation.NSForwardException
[java.lang.IllegalStateException] Cannot obtain globalId for an
object which is registered in an other than the databaseContext's
active editingContext, object: {values = {webServicesPass = "**";
collegeDomains = "<com.webobjects.eocontrol._EOCheapCopyMutableArray
3228a1 (<EOAccessArrayFaultHandler collegeDomains
_EOIntegralKeyGlobalID[College (java.lang.Long)3]>)>"; promotions =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 278e83
(<EOAccessArrayFaultHandler promotions _EOIntegralKeyGlobalID[College
(java.lang.Long)3]>)>"; created = 2006-06-23 07:45:05 Etc/GMT;
modified = 2006-06-23 07:45:05 Etc/GMT; name = "Some name"; sites =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 1a5ec6c
(<EOAccessArrayFaultHandler sites _EOIntegralKeyGlobalID[College
(java.lang.Long)3]>)>"; courses =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 61cd2
(<EOAccessArrayFaultHandler courses _EOIntegralKeyGlobalID[College
(java.lang.Long)3]>)>"; isDeleted = false; nationalProviderCode =
<com.webobjects.foundation.NSKeyValueCoding$Null>; messageTemplates =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 5dfaf1
(<EOAccessArrayFaultHandler messageTemplates _EOIntegralKeyGlobalID
[College (java.lang.Long)3]>)>"; preferences =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray fd66a5
(<EOAccessArrayFaultHandler preferences _EOIntegralKeyGlobalID
[College (java.lang.Long)3]>)>"; courseClasses =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 1ef7de4
(<EOAccessArrayFaultHandler courseClasses _EOIntegralKeyGlobalID
[College (java.lang.Long)3]>)>"; categories =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 10980e7
(<EOAccessArrayFaultHandler categories _EOIntegralKeyGlobalID[College
(java.lang.Long)3]>)>"; webServicesLogin = "iscd"; rooms =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 44d990
(<EOAccessArrayFaultHandler rooms _EOIntegralKeyGlobalID[College
(java.lang.Long)3]>)>"; courseSessions =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 14e4e31
(<EOAccessArrayFaultHandler courseSessions _EOIntegralKeyGlobalID
[College (java.lang.Long)3]>)>"; subcategories =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray b85c17
(<EOAccessArrayFaultHandler subcategories _EOIntegralKeyGlobalID
[College (java.lang.Long)3]>)>"; tutors =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 1b5391b
(<EOAccessArrayFaultHandler tutors _EOIntegralKeyGlobalID[College
(java.lang.Long)3]>)>"; webServicesSecurityCode =
<com.webobjects.foundation.NSKeyValueCoding$Null>; }; this =
"<com.ish.willow.college.model.College 7e8c4d _EOIntegralKeyGlobalID
[College (java.lang.Long)3]>"; }, databaseContext:
com.webobjects.eoaccess.EODatabaseContext@c743eb, object's
editingContext:
com.webobjects.eocontrol.EOSharedEditingContext@ba5c7a,
databaseContext's active editingContext:
com.ish.willow.eocontrol.WillowEditingContext@1a78071: Failed to save
enrolments!
at
com.webobjects.woextensions.WOLongResponsePage.pageForException
(WOLongResponsePage.java:205)
at com.webobjects.woextensions.WOLongResponsePage.refresh
(WOLongResponsePage.java:244)
at
com.webobjects.woextensions.WOLongResponsePage.invokeAction
(WOLongResponsePage.java:224)
at com.webobjects.appserver.WOSession.invokeAction
(WOSession.java:1166)
at com.webobjects.appserver.WOApplication.invokeAction
(WOApplication.java:1375)
at
com.webobjects.appserver._private.WOComponentRequestHandler._dispatch
Wit
hPreparedPage(WOComponentRequestHandler.java:196)
at
com.webobjects.appserver._private.WOComponentRequestHandler._dispatch
Wit
hPreparedSession(WOComponentRequestHandler.java:287)
at
com.webobjects.appserver._private.WOComponentRequestHandler._dispatch
Wit
hPreparedApplication(WOComponentRequestHandler.java:322)
at
com.webobjects.appserver._private.WOComponentRequestHandler._handleRe
que
st(WOComponentRequestHandler.java:358)
at
com.webobjects.appserver._private.WOComponentRequestHandler.handleReq
ues
t(WOComponentRequestHandler.java:432)
at com.webobjects.appserver.WOApplication.dispatchRequest
(WOApplication.java:1306)
at
com.ish.webobjects.appserver.ISHApplication.dispatchRequest
(ISHApplication.java:807)
at
com.ish.willow.college.appserver.Application.dispatchRequest
(Application.java:172)
at com.webobjects.appserver._private.WOWorkerThread.runOnce
(WOWorkerThread.java:173)
at com.webobjects.appserver._private.WOWorkerThread.run
(WOWorkerThread.java:254)
at java.lang.Thread.run(Thread.java:534)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40inquira.com
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:
40e-lumo.com
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