Re: Determining changes in a dataobject / modification diff

From: Ilya Lazarev (glaref..mail.com)
Date: Tue Feb 26 2008 - 05:28:38 EST

  • Next message: Marek Wawrzyczny: "Cayenne and Spring (a Hibernate inspired question)"

    Thanks a lot for the feedback everyone. I implemented Robert's way - it was
    simple and effective. Also, I had to override removeToManyTarget to log
    removal from to-many relationships. And if anyone is going to be researching
    this problem later, I might just as well mention that extending the logger
    object to use the custom overridden writeProperty is a bad idea because it
    keeps trying to log it's own log operation recursively :-)

    On Fri, Feb 22, 2008 at 5:09 PM, Robert Zeigler <robert..uregumption.com>
    wrote:

    > Hi,
    >
    > I had a requirement very similar to this in a recent project.
    > Every change made to a set of objects had to be recorded to be able to
    > provide a history of changes to an object.
    > What I did was to have those objects descend from a common super
    > class, which, in turn, descends from CayenneDataObject.
    > In my superclass, I overrode writeProperty and setToOneTarget. You
    > get the new values passed into you, and you have a chance to examine
    > the old values, as well, by calling readProperty. It has worked out
    > quite nicely.
    >
    > Here's a sample snippet from writeProperty:
    >
    > ..verride
    > public void writeProperty(String name, Object value){
    > Object old = readProperty(name);
    > if (value == null) {
    > if (old != null) {
    > recordChange(name,name + " changed from " +
    > labelFor(readProperty(name)) + " to " + labelFor(value));
    > }
    > } else if (!value.equals(old)) {
    > recordChange(name,name + " changed from " +
    > labelFor(readProperty(name)) + " to " + labelFor(value));
    > }
    > super.writeProperty(name, value);
    > }
    >
    > recordChange handles recording the changes for me; labelFor takes an
    > object and converts it into a string suitable for user consumption.
    >
    > HTH,
    >
    > Robert
    >
    > On Feb 22, 2008, at 2/228:59 AM , Ilya Lazarev wrote:
    >
    > > Apologies if this has been asked before, I couldn't find anything in
    > > the
    > > archives. The problem boils down to this: there is a cayenne object
    > > which is
    > > updated via a form. I want to capture changes made to every single
    > > modified
    > > field in a DB, the value before modification and the value after.
    > > The object
    > > has a number of to-many relationships, which would also have to be
    > > checked
    > > one by one. The simplest way I can envision this is by manually
    > > creating an
    > > object clone before any modifications are made, and then comparing
    > > the two
    > > objects and noting the differences. Is there an easier way to see a
    > > diff of
    > > the fields, perhaps by accessing properties of the cayenne object
    > > itself? I
    > > am using cayenne 2.
    > >
    > > Many thanks,
    > > Ilya
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Feb 26 2008 - 05:29:21 EST