You do not need a single entry point, but you need the ability to apply a transactional interceptor to all input points so that repeated calls can participate in a single transaction. Assuming you can do this, you can accomplish this using the ThreadLocal flag and a custom implementation of org.springframework.transaction.support.TransactionSynchronization .
You must modify ZT to set the ThreadLocal flag when commit is safe to continue. In your implementation of TransactionSynchronization.beforeCommit() , which is called from PlatformTransactionManager , you can check the flag and use this to determine if the commit is allowed to continue. You can force a rollback by RuntimeException if the flag is missing.
One warning - if you have other types of transactions (that are not related to the 3 coordinating classes that you described), you need to make sure that they will not be rolled back inadvertently. To do this, you can mark this “special transaction” in A.Foo, B.Bar, and ZT with another ThreadLocal flag, and then check this flag in the guard clause in the beforeCommit() method mentioned above. Pseudocode:
void beforeCommit() { if in special transaction if commit flag not set throw new RuntimeException("cancel transaction") end if end if end
And, obviously, this is a hack, and I would not speak in the new system :).
user124498
source share