EO's appear(?) to be unexpectedly swapping EC's
EO's appear(?) to be unexpectedly swapping EC's
- Subject: EO's appear(?) to be unexpectedly swapping EC's
- From: <email@hidden>
- Date: Mon, 9 Jun 2008 08:57:17 +1000 (EST)
Hi All,
This ones a bit long for which I apologize but Im stuck and its not easy to
explain ....
My base WOComponent for a project Im working on is called RISFPageComponet
which extends WOComponent. It overrides appendToResponse to allow the
recording to the database of an audit log of all the pages a user visits. . It calls a
method writeToAccessLog in class LogHelper. If it has a session then it rips
some of the session data ( session ID and current person ) and passes that in to.
Write to AuditLog then creates a new EditingContext, adds a new instance of
AuditLog and the saves that to the database.
The code looks like this :
RISFPageComponet.java
/** Write to the accessLog what WOcomponent a person was visting and the
current breadCrumb etc */
publicvoid appendToResponse(WOResponse aResponse, WOContext
aContext)
{
....
// Write to page access logs.
if( aContext.hasSession() )
{
currentPerson =
(Person)(aContext.session().valueForKey("currentPerson"));
wosid = aContext.session().sessionID();
OMSession oms = (OMSession)aContext.session();
ip = oms.getIPAddress(aContext.request());
}
String breadCrumb =
(String)aContext.session().valueForKey("currentPageName");
LogHelper logHelper = new LogHelper();
// writeToAccessLog(String pageName, String breadCrumb, Person
person, String ip, int isAdminSite, String wosid)
logHelper.writeToAccessLog(aContext.page().getClass().getName() ,
breadCrumb, currentPerson,ip , isAdminSite, wosid);
super.appendToResponse(aResponse, aContext);
}
LogHelper.java
public void writeToAccessLog(String pageName, String breadCrumb, Person
person, String ip, int isAdminSite, String wosid)
{
LockErrorScreamerEditingContext ec = new
LockErrorScreamerEditingContext();
log.debug("(4) writeToAccessLog Editing Context : " + ec + " created in
session " + wosid);
ec.lock();
try {
AccessLog currentLog =
(AccessLog)EOUtilities.createAndInsertInstance(ec,"AccessLog");
if( person != null )
{
Person localPerson =
(Person)EOUtilities.localInstanceOfObject(ec, person);
currentLog.setPersonRelationship(localPerson);
}
currentLog.setPageName(pageName);
currentLog.setIpAddress( ip );
currentLog.setBreadCrumb(breadCrumb);
currentLog.setIsAdminSite( new Integer(isAdminSite) );
currentLog.setPersonSessionID(wosid);
ec.saveChanges(); //Error occurs from this save.
} catch (Exception e ) {
ExceptionHelper eh = new ExceptionHelper();
eh.emailException(e, "RISFramework", "error writeToAccessLog
application did not exit");
}
finally{
if ( ec != null ) {
ec.unlock();
ec.dispose();
}
}
}
writeToAccessLog takes a person ( who has come from session ), and gets a
local-Instance of it which besides the newly created AuditLog record, is the only
other EO involved here.
Person has the following relationship to Group.
Person <-- PersonGroup --> Group
We have started randomly receiving the following error when we save the EC of
the LogHelper ( unfortunately we don't have a consistent way of making the
error happen ) :
java.lang.IllegalStateException: Cannot obtain globalId for an object which is
registered in an other than the databaseContext's active editingContext, object:
Group:(Group_Code=203, Short_Name=RSO){groupID=203;}, databaseContext:
com.webobjects.eoaccess.EODatabaseContext@47098a, object's editingContext:
edu.uow.ris.framework.LockErrorScreamerEditingContext@144b543,
databaseContext's active editingContext:
edu.uow.ris.framework.LockErrorScreamerEditingContext@1fe842
So there are 3 EC's involved here :
The sessions Default EC which the person originally belonged to ( @1a79657 )
The objects EC ( @144b543 ) which came from the page the user was on.
The writeToAccessLog methods EC ( @1fe842 ) which is the active one
Which makes the error very strange, because its saying it can't save as the
Group object ( who's EC is the pages ) doesn't exist in the AuditLogs EC ( which
is correct ), but the question is why in the world is it even trying to USE this
object ? The code above doesn't use Group at all. The only way it could be linked
in is from the Person, but they have come from the Session
defaultEditingContext, not the page's one which is apparently the EC that the
Group belongs to.
Im stumped on this one. Does anyone have any idea of whats going on or
explain the behavior that Im seeing ?
Deployed Under :
WO 5.3.3
Tomcat 5.5.7
Owen McKerrow
WebMaster, emlab
Ph : +61 02 4221 5517
http://emlab.uow.edu.au
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
People who prefer typing to pointing then seem to prefer acronyms to save
typing :-)
-Denis Stanton, On people using Command Line Interfaces
_______________________________________________
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