HTML Code:
@Around("execution(* com.virtusa.base.dao.*.*(..)) && @annotation(logAction)" + "args(logAction)")
public Object logAuditTrail(ProceedingJoinPoint runtimeInstance, AuditTrailInterface logAction) throws Throwable {
LOGGER.debug("Inside logAuditTrail method ....");
// Action performed in DAO level
String actionPerformed = DataAccessFactory.getOperationsMap().get(logAction.logAuditTrail());
// join point arguments
for (Object object : runtimeInstance.getArgs()) {
com.virtusa.domainobjects.AuditTrail auditTrail = new com.virtusa.domainobjects.AuditTrail();
auditTrail.setAction(object.toString() + actionPerformed);
auditTrail.setTimestamp(new Timestamp(Calendar.getInstance().getTime().getTime()));
LOGGER.debug("INSERT INTO AUDIT TRAIL: " + object.toString() + actionPerformed);
auditTrailDao.createAuditTrail(auditTrail);
}
LOGGER.debug("End logAuditTrail method ....");
return runtimeInstance.proceed();
}
I have a EmployeeDAOImpl which extends an abstract Base DAO class, following is the Base DAO class which include a method to insert a record in to database ("
HTML Code:
@Repository
public abstract class BaseDaoImpl<T extends Entity> implements BaseDao<T> {
/** Holds the Logger object for logging. */
private static final Logger LOGGER = Logger.getLogger(BaseDaoImpl.class);
/** Holds Session Factory. */
protected SessionFactory sessionFactory;
/**
* @param sessionFactory
* the sessionFactory to set
*/
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
/**
* Method to insert domain specific objects.
*
* @param domainObject
* - Entity type instance.
* @return generated domain id.
*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackForClassName = "DataAccessException")
@AuditTrailInterface(logAuditTrail = "create")
public int create(final T domainObject) {
sessionFactory.getCurrentSession().save(domainObject);
LOGGER.debug("New " + ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0] + " type object created with id " + domainObject.getId());
return domainObject.getId();
}
On the other hand, Employee DAO Impl class will be like following: