db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Keeney, Thomas" <Keen...@SEC.GOV>
Subject RE: Using save() and audit trails
Date Wed, 15 Oct 2003 18:05:27 GMT

You could override the appropriate Peer/OM class methods that
insert/save/delete your object and add the audit table insert there.  Before
you commit the object changes, retrieve the object values for the audit
table with a *NEW* connection.  If your isolation level is set to
READ_COMMITTED, the *NEW* connection should return the object values prior
to the transaction commit.  Check if the Torque object isModified() before
inserting into the audit table.  Determining the object properties that have
changed is a tricky problem.  You could write code to compare the original
value and the current value for each property.  The introspection utilities
in Jakarta Commons BeanUtils may help here.  Any customization of the Torque
generated classes should be added to the OM/Peer classes, not the
BaseOM/BasePeer classes, to minimize problems when upgrading Torque.

You can also clone the original object values immediately after retrieval
from the database, instead of using a *NEW* connection to retrieve the
object values before the commit.  Use the Torque object copy() method to
create the clone.  Beware though that the cloning will retrieve all
dependent foreign-key objects.  Of course, you could override the copyInto()
method to prevent retrieving the foreign-key objects.

Let me know if these recommendations help.

Best Regards,
Tom Keeney
Dunbar Consulting Inc.

-----Original Message-----
From: Scott Eade [mailto:seade@backstagetech.com.au]
Sent: Tuesday, October 14, 2003 9:49 PM
To: Apache Torque Users List
Subject: Re: Using save() and audit trails

Dave Hahn wrote:

>Sorry if this has been brought up before.  I like the clean interface
>for Torque, but have an audit trail requirement I'd like to know if
>there is a solution for using Torque.  This is a legacy system I'd like
>to interface to.
>Upon any insert, save, or delete of an object, I need to also log
>column values to a normalized audit trail table.
>In SQL terms, consider this update:
>  update A set a1=v1, a2=v2 where rec_id=1
>  insert into audit values ('A', 1, 'a1', old_a1, v1)
>  insert into audit values ('A', 1, 'a2', old_a2, v2)
>as part of the save transaction.
>It seems I could accomplish this if there is some callback mechanism,
>and I can get at column values that have changes between the persisted
>version of the object and the currently being saved object.  Can this
>be accomplished?  Any hints on how?
Torque does not provide a specific solution to your problem.  You could 
I guess modify the velocity templates used to generate your OM classes 
to write the audit records, but it would probably be a fair chunk of 
work and you would need to re-do it each time you upgrade Torque 
versions.  Perhaps a simpler approach would be to modify the torque 
templates to provide the desired callbaback only - at least this would 
minimise the maintenance necessary when upgrading versions.



Scott Eade
Backstage Technologies Pty. Ltd.

To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

View raw message