Sep 3rd, 2009, 04:53 AM
XA TransactionManager provides any hook before commit?
We have an application where there would be multiple modules each associated with a different schema.
Multiple modules may be participating in a transaction for data modification. Hence we require the transaction manager to be XA enabled.
There is an audit service which tracks the changes done in the model within the transaction and persists the audit data in one of the database schema.
I would require a hook to call the audit service before the transaction is committed on all the databases participating in the transaction.
Could somebody please let me know how this can be achieved in a clean manner? Currently I am thinking of extending the JtaTransactionManager provided by spring and call the audit service before calling the super.doCommit. Would this be right approach?
Would appreciate any pointers for this.
Sep 3rd, 2009, 11:24 PM
Could somebody please share knowledge on this?
Sep 3rd, 2009, 11:49 PM
Why? Why not simply use some AOP for that. 1 thing you have to wonder is does the audit data need to be written in the same or in a separate transaction, it depends on your requirement.
Originally Posted by shashi
Sep 4th, 2009, 06:23 AM
Thanks for your reply.
I am already using an aspect for capturing the data changes. However the audit data captured during the data manipulation done by user has to be persisted only during the data change commit to the persistence store.
However the audit data needs to be stored to a separate datastore and the actual data would be persisted in a different store. Also the transaction may involve changes in the data stored across multiple datasources. That would require XA. Hence I was wondering if I could call saving the audit data in a hook called during the commit called by the XA transaction manager.
Sep 4th, 2009, 06:27 AM
You could try and register your class with the TransactionSynchronizationManager (you could use AOP for that) and implement the required interface and well implement what you need.