cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <mgen...@masslight.net>
Subject Re: Implementing and audit log using Cayenne; finding what was modified in an object
Date Fri, 07 Aug 2015 16:51:41 GMT
Hi Hugi,

I was mainly interest in attributes, so that's all I coded up.  I'm sure
there is a way to take relationships into account, as well, but I'd have to
code it up and test it and don't have time at the moment (maybe over the
weekend).  If someone else, including yourself, beats me to it, that would
be great.

I'd start by looking at getRelationships():

http://cayenne.apache.org/docs/3.0/api/org/apache/cayenne/map/ObjEntity.html

mrg


On Fri, Aug 7, 2015 at 12:20 PM, Hugi Thordarson <hugi@karlmenn.is> wrote:

> Thanks a lot Michael, objectStore.getSnapshot( object.getObjectId() );
> does almost exactly what I needed.
>
> One thing though, this code does not handle modifications to
> relationships, since my foreign keys are not modeled as attributes in the
> ObjEntity. Do you think there’s some way to get at changes to modeled
> foreign keys as well?
>
> Cheers,
> - hugi
>
>
>
>
> > On 7. ágú. 2015, at 14:33, Michael Gentry <mgentry@masslight.net> wrote:
> >
> > Hi Hugi,
> >
> > Maybe something like isIdenticalToSnapshot() in this Gist will help you?
> >
> > https://gist.github.com/mrg/4dce22b67175c27f4047
> >
> > If I recall, this version is for Cayenne 3.0, so there might be a few
> > tweaks needed for 3.1.
> >
> > mrg
> >
> >
> > On Fri, Aug 7, 2015 at 10:16 AM, Hugi Thordarson <hugi@karlmenn.is>
> wrote:
> >
> >> Hi all.
> >>
> >> I’m attempting to implement an audit log using Cayenne, automatically
> >> storing information on modifications alongside every insert, update and
> >> delete.
> >>
> >> I’m currently doing this by adding a listener on the DataDomain that
> >> watches for the lifecycle events PrePersist, PreUpdate and PreRemove,
> and
> >> there I log what’s happening with the objects. Works perfectly.
> >>
> >> One thing I’m wondering though. How can I find what has changed in an
> >> object in PreUpdate (i.d. when logging modifications)? For those
> familiar
> >> with EOF, I do it there by looking at the
> >> EOEditingContext’s.commitedSnapshotForObject() and comparing the values
> >> found there with the object’s current values—but I can’t find how to to
> do
> >> something similar in Cayenne.
> >>
> >> Am I maybe going about this in a completely wrong way (and there’s
> perhaps
> >> a much better, more Cayenne-ish way to do this)? If so, I’d be grateful
> if
> >> someone could point me in the correct direction :).
> >>
> >> Thanks once again,
> >> - hugi
> >>
> >> // Hugi Thordarson
> >> // http://www.loftfar.is/ <http://www.loftfar.is/>
> >> // s. 895-6688
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message