Re: valueForKey(...) from within takeStoredValueForKey(...) = infinite loop
Re: valueForKey(...) from within takeStoredValueForKey(...) = infinite loop
- Subject: Re: valueForKey(...) from within takeStoredValueForKey(...) = infinite loop
- From: Fabian Peters <email@hidden>
- Date: Wed, 16 Jan 2008 20:31:28 +0100
Hi Florijan,
Am 16.01.2008 um 20:20 schrieb Florijan Stamenkovic:
Hi all,
I've been trying to override some EOCustomObject methods to perform
event firing. However, I bumped into a problem when the objects are
first being initialized with values. The thing is, i use the old
value in the fired event. This meant my takeStoredValue method looks
like this:
public void takeStoredValueForKey(Object object, String key){
Object oldValue = FIRE_EVENTS ? valueForKey(key) : null;
super.takeStoredValueForKey(object, key);
if(FIRE_EVENTS) fireDataObjectEvent(key, oldValue);
}
However, during the first initialization of the EO the first line of
the method (getting of the old value) triggers a fault to fire,
which triggers EOF to get the value and set it on the EO using the
takeStoredValueForKey(..) method. Which ends up in an infinite loop.
Bummer.
I've been down that road as well. storedValueForKey is used behind the
scenes by EOF. I ended up putting a method in a common superclass:
public void willChange(Object oldValue, Object newValue, String
key) {
// to be used by subclasses
}
And then placing this in the setters created by EOGenerator:
willChange(storedValueForKey("theKey"), value, "theKey");
When I need this fine-grained change tracking on an EO, I fill in the
willChange() method.
HTH,
Fabian
What I've tried is printing a stack trace of an exception as the
first line in the takeStoredValueForKey(..) method, hoping to find
out which method was calling it. Then I'd override that method, to
skip event firing during the initialization (by setting the
FIRE_EVENTS flag to false during it's duration). But, the stack
trace does not imply any method in which I could do that (I edited
out all the trace elements that are not from com.webobjects...):
java.lang.Exception
at
org
.jbnd
.eof
.FiringEOFDataObject.takeStoredValueForKey(FiringEOFDataObject.java:
102)
at
com
.webobjects
.eodistribution
.client
.EODistributedObjectStore
.initializeObject(EODistributedObjectStore.java:249)
at
com
.webobjects
.eocontrol.EOEditingContext.initializeObject(EOEditingContext.java:
3805)
at
com
.webobjects
.eodistribution
.client
.EODistributedObjectStore._fireFault(EODistributedObjectStore.java:
1129)
at
com
.webobjects
.eodistribution
.client
.EODistributedObjectStore
.initializeReplacementObject(EODistributedObjectStore.java:814)
at
com
.webobjects
.eodistribution
.client
.EODistributedObjectStore
._replacementObjectForDecodedObject(EODistributedObjectStore.java:788)
at
com
.webobjects.foundation.NSSelector._safeInvokeMethod(NSSelector.java:
120)
at com.webobjects.foundation._NSDelegate._perform(_NSDelegate.java:
225)
at com.webobjects.foundation._NSDelegate.perform(_NSDelegate.java:
162)
at
com
.webobjects
.eodistribution
.common
._EOReferenceRecordingCoder
.decodeObject(_EOReferenceRecordingCoder.java:559)
at
com
.webobjects
.eodistribution
.common
._EOReferenceRecordingCoder
.decodeObjects(_EOReferenceRecordingCoder.java:587)
at com.webobjects.foundation.NSArray.decodeObject(NSArray.java:1309)
at com.webobjects.eodistribution.common._EOReferenceRecordingCoder
$_Decoder.decodeObject(_EOReferenceRecordingCoder.java:704)
at
com
.webobjects
.eodistribution
.common
._EOReferenceRecordingCoder
.decodeObject(_EOReferenceRecordingCoder.java:551)
at
com
.webobjects
.eodistribution
.common._EOServerReturnValue.decodeObject(_EOServerReturnValue.java:
62)
at com.webobjects.eodistribution.common._EOReferenceRecordingCoder
$_Decoder.decodeObject(_EOReferenceRecordingCoder.java:704)
at
com
.webobjects
.eodistribution
.common
._EOReferenceRecordingCoder
.decodeObject(_EOReferenceRecordingCoder.java:551)
at
com
.webobjects
.eodistribution
.common
._EOReferenceRecordingCoder
.decodeObjects(_EOReferenceRecordingCoder.java:587)
at com.webobjects.foundation.NSArray.decodeObject(NSArray.java:1309)
at com.webobjects.eodistribution.common._EOReferenceRecordingCoder
$_Decoder.decodeObject(_EOReferenceRecordingCoder.java:704)
at
com
.webobjects
.eodistribution
.common
._EOReferenceRecordingCoder
.decodeObject(_EOReferenceRecordingCoder.java:551)
at
com
.webobjects
.eodistribution
.client.EOHTTPChannel._responseToMessage(EOHTTPChannel.java:533)
at
com
.webobjects
.eodistribution
.client.EOHTTPChannel.responseToMessage(EOHTTPChannel.java:603)
at
com
.webobjects
.eodistribution
.client.EODistributedObjectStore._send(EODistributedObjectStore.java:
594)
at
com
.webobjects
.eodistribution
.client.EODistributedObjectStore._send(EODistributedObjectStore.java:
623)
at
com
.webobjects
.eodistribution
.client
.EODistributedObjectStore
.objectsWithFetchSpecification(EODistributedObjectStore.java:506)
at
com
.webobjects
.eocontrol
.EOEditingContext
.objectsWithFetchSpecification(EOEditingContext.java:4114)
at
com
.webobjects
.eocontrol
.EOEditingContext
.objectsWithFetchSpecification(EOEditingContext.java:4500)
Anyone has any idea how I could do this? If not, I am stuck with
events being fired only in value setters.
Thx
Flor
_______________________________________________
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
_______________________________________________
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