Re: takeValueForKey, takeStoredValueForKey and willChange message problem

Patrick Middleton <[email protected]> Tue, 29 Jun 2004 09:42:30 +0100
Newsgroups gmane.comp.web.webobjects.devel,gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
> ...
> I have a subclass of EOGenericRecord, call it myClass.  It has a number 
> of attibutes, but the base case is one column/attribute called 
> myColumn.  Assume the select out of a database works.
>
> ...
>
> Now, when I want to change the value of myColumn and I want to trigger 
> a "willchange" message I can use myClass.setMyColumn(newValue), or 
> myClass.takeValueForKey(newValue,"myColumn") or takeStoredValueForKey 
> (newValue,"myColumn").   So when I call editingContext.saveChagnes() 
> the value gets sent to the database via an update statement.
>
> Problem:
>
> I want to set the value of myColumn but I do NOT want to trigger 
> "willchange" and I don't want the new value to be sent to the database, 
> but I do want the new value to be used as part of the update where 
> clause.
> How do I do this?  Do I have to recode my objects as EOCustomObject to 
> get around this so I can have custom accessor, or is there a way to get 
> EOGenericRecord to do this also?
>
> The docs at apple tell me this:
> <http://developer.apple.com/documentation/WebObjects/Enterprise_Objects/EnterpriseObjects/
> chapter_3_section_9.html>
>
> There has to be some way to set the value "under the hood" so all the 
> validation and notification does not happen.
>
> Why:
>
> We are using Sybase and to control changes we use the sybase timestamp 
> column and it is maintained by the server.  Everytime the row it 
> touched the timestamp column value changes.  If you include this column 
> in your where clause you can catch changes by others before you 
> overwrite them.  But you must update your local value after an 
> update/insert.
>
> I know I can achieve what I want by invalidating the object and 
> refetching, but that is expensive to do and not an elegant solution. I 
> have the update values selected out, but I can not figure out how to 
> get EOF to take it without triggering an update.

Your choices are:
[1] use the com.webobjects.EOAccess.EOAdaptorChannel.Delegate and 
com.webobjects.EOAccess.EODatabaseContext.Delegate interface APIs to 
rewrite the lists of EOAdaptorOperations and EODatabaseOperations as and 
when appropriate, or
[2] take the pain, and invalidate and refetch

I favour option 2.

Why are you using Sybase timestamp columns instead of using the 
optimistic locking strategy offered by EOF by default?

-- Patrick