Announcement Announcement Module
Collapse
No announcement yet.
Help needed for pointcut definition Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help needed for pointcut definition

    Hi,

    To write my DAO objects i'm using a Generic DAO class which works with Generics. GenericDAO implements an interface IGenericDao which code is :

    Code:
    public interface IGenericDao <T, ID extends Serializable> {
        List<T> readAll();
        T create(T entity);
        T read(ID id);
        T saveOrUpdate(T entity);
        void delete(T entity);
    }
    With hibernate, the GenericDAO code is :
    Code:
    public class GenericDao <T, ID extends Serializable> extends HibernateDaoSupport 
    	implements IGenericDao<T, ID>, FinderExecutor<T> {
    	private static Log logger = LogFactory.getLog(GenericDao.class);
    	
    	private Class<T> type;
        public GenericDao() {
        }
        
        public GenericDao(Class<T> type) {
            this.type = type;
        }
        
        @SuppressWarnings("unchecked")
        public T read(ID idType) {
        	return (T) getHibernateTemplate().get(getPersistentClass(), idType);
        }
        
        public Class<T> getPersistentClass() {
            return type;
        }
        
        @SuppressWarnings("unchecked")
        public T create(T entity) {
        	getHibernateTemplate().save(entity);
            return entity;
        }
        
        public T saveOrUpdate(T entity) {
        	getHibernateTemplate().saveOrUpdate(entity);
            return entity;
        }
        
        public void delete(T entity) {
        	getHibernateTemplate().delete(entity);
        }
    }
    Now i would like to be able to intercept the dao's methods before and after they are called, because i need to prepare objects before they are saved ot change some stuffs after they are read.

    I don't know how to build the pointcut expression. I've tried several syntax, but there seems to have a problem because of the generic type ID and T. Here's a syntax example :
    Code:
    @Before("execution(* org.escapek.core.dao.IGenericDao.saveOrUpdate(T)) ")
    ... and the exeception thrown :
    Code:
    /WEB-INF/domain.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: T [Xlint:invalidAbsoluteTypeName]
    Caused by:
    java.lang.IllegalArgumentException: warning no match for this type name: T [Xlint:invalidAbsoluteTypeName]
            at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:315)
            at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:189)
            at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:176)
            at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:157)
            at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:187)
            at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:244)
            at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:278)
            at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:83)
            at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:66)
            at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:296)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:312)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1180)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:261)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1099)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:861)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    Any idea on how to write this pointcut ?

  • #2
    why you need generic type ID and T?
    did you have try :
    @Before("execution(* org.escapek.core.dao.IGenericDao.saveOrUpdate(..)) ")

    Comment


    • #3
      That's what I'm using indeed as a workaround.
      In fact, it's true that i don't absolutelly need this generic , but i was wondering ...
      thx.

      Comment

      Working...
      X