Let's say I use JPA with @transactions annotations.
So, for a method to execute under a transaction, I add @transaction annotations and my BINGO method executed in the transaction.
To achieve the above, we need to have an interface for the class, and the instance is controlled by some kind of container.
Also, I should always call the method from the interface link so that the proxy object can start the transaction. So my code will look like this:
class Bar { @Inject private FooI foo; ... void doWork() { foo.methodThatRunUnderTx(); } } class FooImpl implements FooI { @Override @Transaction public void methodThatRunUnderTx() {
Good and good
Now let's say methodThatRunUnderTx performs two logical operations
[1] call some service (long request / response cycle, say, 5 seconds) and select the results
[2] make some modifications to the jpa object
Now, since this method call is long, and we donβt want to hold the transaction for a long time, so we change the code so that [2] occurs in separate tx and methodThatRunUnderTx does not execute in the transaction
So, we will remove @transaction from methodThatRunUnderTx and add another method to the class with @transaction , suppose that the new methods are methodThatRunUnderTx2 , now to call this method from methodThatRunUnderTx we need to insert it into and add a method for the interface so that the call is made through a proxy an object.
So, now our code will look like this:
class Bar { @Inject private FooI foo; ... void doWork() { foo.methodThatRunUnderTx(); } } class FooImpl implements FooI { @Inject private FooI self; @Override
NOW Problem
We made methodThatRunUnderTx2() public through the interface .
But this is not what we want to expose as our api from FooI and not be meant to be called from outside.
Any suggestions for resolving it?