i wondering possible configure spring in way fire particular method on end transaction?
for example have service class method
@service public class service implements iservice { @resource private entitydao entitydao; @resource private someservice someservice; @transactional @override public void dothings() { entitydao.dosmthondb(); someservice.thismethodfiresonendoftransaction(); } }
and second service class
@service public class secondservice implements isecondservice { @resource private iservice service; @transactional @override public void method() { service.dothings(); /* other code can break transaction */ } }
so if call secondservice.method()
want someservice.thismethodfiresonendoftransaction()
fire if transaction end successfully.
is possible in spring?
not sure, if it's idea delegate spring when can add new bean indirection layer between services , delegate thing it.
but if don't have choice or want spring, can specify own platformtransactionmanager
, delegate calls default manager, intercepts successful commit()
calls. example:
public class mytransactionalmanager implements platformtransactionmanager { // ... implementation via delegation skipped here @override public void commit(transactionstatus status) throws transactionexception { defaultmanager.commit(status); // might want check status.isrollbackonly() here someservice.thismethodfiresonendoftransaction(); }
now can either replace default transaction manager in application (then ::thismethodfiresonendoftransaction called after each transaction) or add in context qualifier, should write this:
@override @transactional(value = "mymanager", rollbackfor = ...) public void method()
(and in end of answer still think flawed approach , implementing via bean far better)
Comments
Post a Comment