Re: Hooks for audit generation

Ricardo Parada <[email protected]> Wed, 8 Oct 2025 14:25:50 -0400
Newsgroups gmane.comp.java.cayenne.user
Message-ID <[email protected]>
--Apple-Mail-5AD47474-1EC2-45D9-BD52-5041A302A47F
Content-Type: text/plain;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi all,

More progress I think I figured it out.=20
I created a class that implements GraphChangeHandler. =20

Then, in the onSync() method I do this:

 var handler =3D new AuditGraphChangeHandler();

changes.apply(handler);

Where changes is the GraphDiff passed into the onSync() method.=20

The AuditGraphChangeHandler prints out what I was looking for.=20

Thank you=20
Ricardo Parada



> On Oct 8, 2025, at 1:38=E2=80=AFPM, Ricardo Parada <[email protected]> wrote=
:
>=20
> =EF=BB=BF
> Hi all,
>=20
> I made a little bit of progress. I=E2=80=99m doing this:
>=20
> var myAuditFilter =3D new AuditFilter();
>=20
> // Register the filter manually
> runtime.getDataDomain().addFilter(myAuditFilter);
>=20
> Then in AuditFilter implementation I have this method below only. The prob=
lem is ObjDiff doesn=E2=80=99t seem to have any API to get the name of the p=
roperty, before and after values.=20
>=20
> @Override
> public GraphDiff onSync(
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82ObjectContext originatingContext,
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82GraphDiff diff,
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82int syncType,
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82DataChannelSyncFilterChain filterChain) {
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82if (diff instanceof O=
bjectStoreGraphDiff changes) {
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82// Let's peek
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82for (var entry : changes.getChangesByObject=
Id().entrySet()) {
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=
=E2=80=82Object objId =3D entry.getKey();
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=
=E2=80=82ObjectDiff objDiff =3D entry.getValue();
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=
=E2=80=82System.out.println("objId =3D " + objId);
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=
=E2=80=82System.out.println("objDiff =3D " + objDiff);
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=
=80=82=E2=80=82=E2=80=82=E2=80=82}
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82}
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82
> =E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82=E2=80=82return filterChain.o=
nSync(originatingContext, diff, syncType);
> }
>=20
>=20
>=20
>>=20
>> On Oct 8, 2025, at 10:57=E2=80=AFAM, Ricardo Parada <[email protected]> wro=
te:
>>=20
>> =EF=BB=BFGood morning,
>>=20
>> I=E2=80=99m looking into replacing our framework developed for EOF that c=
an generated an audit document describing what database operations are perfo=
rmed when saveChanges() is called.
>>=20
>> We capture the object identity, its entity and attributes changed includi=
ng before and after values.
>>=20
>> I=E2=80=99m trying to do hook into Cayenne right now to just print the en=
tities changed and the attributes before and after values to explore how we w=
ould do this in Cayenne.
>>=20
>> ChatGPT suggested implementing DataChannelSyncFilter and adding a module t=
o set it up during configuration. It looks pretty close to what I need excep=
t it does not compile. So it may be hallucinating.
>>=20
>> I would prefer if the hook can be set up right there before calling commi=
tChanges(). Because not everything is audited.
>>=20
>> Thanks in advance,
>> Ricardo Parada

--Apple-Mail-5AD47474-1EC2-45D9-BD52-5041A302A47F--