Re: EO's appear(?) to be unexpectedly swapping EC's
Re: EO's appear(?) to be unexpectedly swapping EC's
- Subject: Re: EO's appear(?) to be unexpectedly swapping EC's
- From: Lachlan Deck <email@hidden>
- Date: Mon, 9 Jun 2008 17:59:55 +1000
Hi Owen,
obviously enjoying the public holiday :-)
On 09/06/2008, at 8:57 AM, <email@hidden> <email@hidden> wrote:
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 */
public void 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();
currentPerson = (Person)oms.valueForKey("currentPerson");
wosid = oms.sessionID();
ip = oms.getIPAddress(aContext.request());
}
else
{
// should currentPerson, wosid, ip be set to null?
// or should they be set after the next getting the currentPageName
which initiates the session?
}
String breadCrumb =
(String)aContext.session().valueForKey("currentPageName");
LogHelper logHelper = new LogHelper();
Does LogHelper subclass/implement any EOF/WOF classes/interfaces or
is it just one of yours?
// 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);
// put in some logs to ensure the localisation succeeded.
// i.e., localPerson.editingContext() == ec
// or
EOGlobalID personID =
person.editingContext().globalIDForObject(person);
if (personID instanceof EOTemporaryGlobalID)
throw IllegalStateException("Attempting to log stuff for a non
persistent person");
Person localPerson = (Person)ec.faultForGlobalID(personID, ec);
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
Hmm.
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.
Are you doing any awakeFromFetch/Insertion stuff?
Perhaps you need some logging in Group to see what's going on.
Something is (possibly) touching it...
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