Re: Need Help on EOModel Auto update of DATE column for DirectToWebapp

Mark Ritchie <[email protected]> Thu, 12 Nov 2009 10:54:00 -0800
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Hey Bhagyalata!

On 9/Nov/2009, at 8:47 PM, Bhagyalata Sahu wrote:
> Thank you all for quick response.
> Thanks Pierre for your response specifically. That gave me a flash  
> to do another simpler solution:
>
> I changed the getter and setter methods of the corresponding java  
> class to automatically update the create date if create date is null.
> public NSTimestamp createDate() {
>         if(storedValueForKey("createDate") == null) {
>             NSTimestamp currentTime = new NSTimestamp();
>             setCreateDate(currentTime);
>             return currentTime;
>         } else {
>             return (NSTimestamp)storedValueForKey("createDate");
>         }
>     }
Yikes!  That's called a mutating accessor and it's a bad idea.
What if an administrative application wanted to use the same EOModel  
and EO's to examine the records which did not have a createDate set.   
With this implementation, the fetch specification would could  
correctly find the records however by the time they were reported  
there would be values in the createDate field.   Just one of the many  
reasons that accessor methods should not modify values!

I've updated the EOF Commandments with some more details on this case:
http://wiki.objectstyle.org/confluence/display/WO/EOF-Using+EOF-The+EOF+Commandments

Side note, if you are using D2W then you should really use Wonder as  
well!
Wonder has many enhancements for D2W!

Best!
Mark

_______________________________________________
WebObjects-dev mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/webobjects-dev