Does JDO provide a hook/trigger to identify a transaction commit/boundary?


ebenzacar@...
 

I'm working on migrating legacy code that was using the OpenJPA Transaction Listener to identify a transaction boundary (commit) to trigger some post-commit functionality.  The logic is a bit messy, but the idea is that after a commit is completed, an MQ message must be published to trigger some asynchronous processing.  It is critical that the MQ message only be published after the commit as the MQ Client only has access to the persisted data and must only be triggered one the commit is confirmed.
`
The legacy code is leveraging the OpenJPA `org.apache.openjpa.event.EndTransactionListener#afterCommit()` listener to trigger the message publishing.

Is there any similar constructs that I can use with JDO?  The closest I have found are the JDO Lifecycle listeners, but those unfortunately provide triggers on the individual objects and not the transaction as a whole.  I noticed that the DN TransactionImpl has listeners n(org.datanucleus.TransactionEventListener) that I could likely leverage, but that would then imply that I need to have dependencies on the Impl instead of just the JDO standard.

Am I overlooking anything?


Andy
 

Look at JDO spec 13.4.3, you can call
transaction.setSynchronization(...)
and be notified via the (standard) beforeCompletion/afterCompletion methods.

Note that this is for a transaction itself. It will not include NON-TRANSACTIONAL ops which are ... not transactional.