Re: Hooks for audit generation

Ricardo Parada <[email protected]> Wed, 8 Oct 2025 13:38:52 -0400
Newsgroups gmane.comp.java.cayenne.user
Message-ID <[email protected]>
--Apple-Mail-BED3EDBF-F4A9-41C7-A146-A10994351DD1
Content-Type: text/plain;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi all,

I made a little bit of progress. I=E2=80=99m doing this:

var myAuditFilter =3D new AuditFilter();

// Register the filter manually
runtime.getDataDomain().addFilter(myAuditFilter);

Then in AuditFilter implementation I have this method below only. The proble=
m is ObjDiff doesn=E2=80=99t seem to have any API to get the name of the pro=
perty, before and after values.=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 Ob=
jectStoreGraphDiff 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.getChangesByObjectId(=
).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.onS=
ync(originatingContext, diff, syncType);
}



>=20
> On Oct 8, 2025, at 10:57=E2=80=AFAM, Ricardo Parada <[email protected]> wrot=
e:
>=20
> =EF=BB=BFGood morning,
>=20
> I=E2=80=99m looking into replacing our framework developed for EOF that ca=
n generated an audit document describing what database operations are perfor=
med when saveChanges() is called.
>=20
> We capture the object identity, its entity and attributes changed includin=
g before and after values.
>=20
> I=E2=80=99m trying to do hook into Cayenne right now to just print the ent=
ities 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 commit=
Changes(). Because not everything is audited.
>=20
> Thanks in advance,
> Ricardo Parada

--Apple-Mail-BED3EDBF-F4A9-41C7-A146-A10994351DD1--