We were facing issues overriding Custom Transaction Factory in ADF 11g R1, it was initialized only for the first loaded AM, this seems is not the case anymore in ADF 11g R2 (11.1.2.x). I would like to present today a use case of implementing global after commit call. Read more about use cases with Custom Transaction Factory in ADF Developer Guide - 12.8 Customizing Business Components Error Messages.
Sample application - CustomDBTransactionApp.zip is based on two separate AM's:
First AM is configured with Custom Transaction Factory:
Second AM is configured with Custom Transaction Factory:
Referenced Transaction Factory class creates new instance of DB Transaction implementation, where commit() and doCommit() methods are overriden:
You can see that message is printed after calling super in both cases:
If you want to execute code after commit operation was completed, you should call it after super in commit() method. This will be called one single time after commit, for all EO's at once.
In addition I have overriden doDML and afterCommit methods available in EO implementation to compare invocation time. Obviously these methods will be invoked separately for each EO:
We can test it now. Edit data from the first AM and commit transaction with Save button:
Check the log - first it starts executing SQL update statement. It calls doDML() method from EO implementation, next it calls doCommit() method from Transaction Factory, right before DB commit it calls afterCommit() method from EO implementation and finally after DB commit - commit() method from Transaction factory (after calling super) is called. This means afterCommit() method from EO is really invoked after data was posted to DB, but not after actual DB commit. In contrast, after super in Transaction Factory commit(), we can call custom logic and it will be executed after DB commit:
Test the same for the second AM:
It does same logic as for the first AM, you can check it applies correct AM instance:
Sample application - CustomDBTransactionApp.zip is based on two separate AM's:
First AM is configured with Custom Transaction Factory:
Second AM is configured with Custom Transaction Factory:
Referenced Transaction Factory class creates new instance of DB Transaction implementation, where commit() and doCommit() methods are overriden:
You can see that message is printed after calling super in both cases:
If you want to execute code after commit operation was completed, you should call it after super in commit() method. This will be called one single time after commit, for all EO's at once.
In addition I have overriden doDML and afterCommit methods available in EO implementation to compare invocation time. Obviously these methods will be invoked separately for each EO:
We can test it now. Edit data from the first AM and commit transaction with Save button:
Check the log - first it starts executing SQL update statement. It calls doDML() method from EO implementation, next it calls doCommit() method from Transaction Factory, right before DB commit it calls afterCommit() method from EO implementation and finally after DB commit - commit() method from Transaction factory (after calling super) is called. This means afterCommit() method from EO is really invoked after data was posted to DB, but not after actual DB commit. In contrast, after super in Transaction Factory commit(), we can call custom logic and it will be executed after DB commit:
Test the same for the second AM:
It does same logic as for the first AM, you can check it applies correct AM instance:

































