When is going to explain Spring aspects the mandatory example usually are transactions and logging )))
So the question I was recently asked is: what kind of pointcut has @Transactional aspect? Before, After or Around? ( any other clarifications are appreciated!)
Thanks
In terms of a theoretical question (interview, explanation, etc), Transactional support can be implemented as an "Around" advice in terms of AOP.
Explanation:
An Around advice provides a hook both before and after the execution of an actual code, and this is exactly what is needed for implementing @Transactional
logic.
Before the "applicative" code gets executed, spring will open a transaction, or alternatively will implement more sophisticated logic (like nested transaction support, etc. This is called propagation; there is also isolation - all of them technically can be set up as parameters of @Transactional
annotation)
After the applicative code gets executed, spring should check the result, and commit or rollback a transaction depending on the status (usually, if the applicative code throws an exception, the rollback should be done, if all is ok - commit.
Note, also that the terminology you've used in question "what kind of pointcut has @Transactional aspect" is not totally accurate.
Pointcut in AOP defines at what joinpoints the associated Advice should be applied.
All the logic that handles transaction can be implemented in an Advice of type around.