Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 69251 invoked from network); 22 Feb 2008 16:41:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Feb 2008 16:41:52 -0000 Received: (qmail 71600 invoked by uid 500); 22 Feb 2008 16:41:36 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 71588 invoked by uid 500); 22 Feb 2008 16:41:36 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 71570 invoked by uid 99); 22 Feb 2008 16:41:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Feb 2008 08:41:36 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [208.78.103.231] (HELO vorsha.objectstyle.org) (208.78.103.231) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 22 Feb 2008 16:41:03 +0000 Received: (qmail 483 invoked from network); 22 Feb 2008 16:41:11 -0000 Received: from unknown (HELO localhost) (127.0.0.1) by localhost with SMTP; 22 Feb 2008 16:41:11 -0000 Message-Id: From: Andrus Adamchik To: user@cayenne.apache.org In-Reply-To: <14636937-589B-4276-8E16-B79FC5626936@puregumption.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v915) Subject: Re: Determining changes in a dataobject / modification diff Date: Fri, 22 Feb 2008 18:41:10 +0200 References: <759853800802220659m3292e649ke35d9cadfc33d93c@mail.gmail.com> <14636937-589B-4276-8E16-B79FC5626936@puregumption.com> X-Mailer: Apple Mail (2.915) X-Virus-Checked: Checked by ClamAV on apache.org One more way of doing that, based on the internal Cayenne mechanism for tracking all object changes as instances of GraphDiff: http://cayenne.apache.org/doc20/api/cayenne/org/apache/cayenne/graph/GraphDiff.html There is no public API to access the diffs directly, but you can intercept and process diffs on commit. Normally a DataContext.getChannel() would return a DataDomain. A user can replace it with a wrapper (via 'context.setChannel(..)') that delegates all DataChannel operations to the DataDomain: http://cayenne.apache.org/doc20/api/cayenne/org/apache/cayenne/DataChannel.html In the wrapper you can override 'onSync' to analyze/capture all the diffs being sent to the DataDomain for commit. Andrus On Feb 22, 2008, at 6:09 PM, Robert Zeigler 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: > > @Override > 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 > >