Managing DAO transactions
Aspects do not only intercept the service layer but also the data transaction layer. This recipe will give us a concrete scenario when AOP is needed in most DAO transactions. Aspects implemented for the DAO layer are just limited to logging, tracing, and validating tasks due to undesirable effects when transactions become complex.
Getting started
Open ch05
and add an @Aspect
that will filter null
record(s) from JdbcSimpleInsert
and JdbcTemplate
.
How to do it...
Our first AOP implementation will be applied for managing DAO transactions. Follow the following procedure to log all the DAO transactions using aspects, advices and Pointcuts:
- Before this recipe starts, be sure to have the
EmployeeDao
andEmployeeDaoImpl
inside the packagesorg.packt.aop.transaction.dao
andorg.packt.aop.transaction.dao.impl
, respectively. - To apply aspects to our DAO transactions, let us create an
@Aspect
inside the packageorg.packt.aop.transaction.core
that will monitorgetEmployees()
andgetEmployee...