Re: Jooq and audit trail

477 views
Skip to first unread message

Lukas Eder

unread,
Sep 26, 2014, 1:32:16 AM9/26/14
to jooq...@googlegroups.com
You have, of course, several options to implement audit trails.

If you want to stay 100% sure to catch all updates, database triggers are your best way to go, here.

Otherwise, from a jOOQ perspective, RecordListener is the easiest to help you implement audit trails, although it will limit your application design by enforcing all updates to go via UpdatableRecord.store() and similar.

While you could delve into a harder-to-implement, yet possibly more reliable solution based on VisitListeners, there will always be cases involving bulk DML that you won't be able to catch, and that can be covered using triggers, only:

- MERGE statement
- INSERT .. SELECT statements
- Multi-row UPDATE statements

If others want to share their actual experience, I think that would be very interesting for the group.

Hope this helps,
Lukas


2014-09-25 18:25 GMT+02:00 <alexand...@a-sis.com>:
Hummm, It seems to be better with RecordListener which permit to have the complete record and the modification.

Le jeudi 25 septembre 2014 17:29:03 UTC+2, alexand...@a-sis.com a écrit :
Hello,

Do you know what is the best way for doing Audit trail with Jooq ? I think ExecuteListener can be good solution, but if someone has already implemented this, It could help me a lot.

Is there a way to catch fields that have been updated after a update statement ?

Thanks for your helps.

Alex


--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

alexand...@a-sis.com

unread,
Sep 29, 2014, 5:33:44 AM9/29/14
to jooq...@googlegroups.com
if it can help someone, I have found a solution with recordListener. 

Example : 

@Override
public void updateStart(RecordContext ctx) {
Row rows = ctx.record().fieldsRow();
List<Field<?>> fields = Arrays.asList(rows.fields());
for (Field f : fields) {
if (ctx.record().changed(f)) {
LOG.info("AUDIT TRAIL - Changed into <" + ((TableField) f).getTable().getName() + "."+ f.getName() + "> original value <"
+ ctx.record().original(f) + "> new value <"
+ ctx.record().getValue(f).toString() + ">");
//can insert into a single audit table...or something more sophisticated like hibernate envers...
}
}
super.updateEnd(ctx);
}
Reply all
Reply to author
Forward
0 new messages