Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] debugging "with runtime test"?

Here's some more detail.

The code to be advised:

public class ToBeAdvised {

   @PersistenceContext
   private EntityManager em;

   public void useEM() {
       em.flush();
   }
}


Here is a set of pointcuts/advise. All but one is indicated by AJDT as being conditionally advised. But at runtime only the first advise is actually invoked.

   //---- matches in AJDT, invoked at runtime
@Pointcut("get(@javax.persistence.PersistenceContext javax.persistence.EntityManager *.*)")
   void entityManagerFieldGet_1(){}
@Around("entityManagerFieldGet_1()")
   public EntityManager getEntityManager_1(JoinPoint jp){
       System.err.println("****getEntityManager_1");
       return null;
   }

   //---- matches in AJDT, not invoked at runtime
@Pointcut("get(@javax.persistence.PersistenceContext javax.persistence.EntityManager *.*) && args(..)")
   void entityManagerFieldGet_2(){}
@Around("entityManagerFieldGet_2()")
   public EntityManager getEntityManager_2(JoinPoint jp){
       System.err.println("****getEntityManager_2 ..");
       return null;
   }

   //---- does not match in AJDT, not invoked at runtime
@Pointcut("get(@javax.persistence.PersistenceContext javax.persistence.EntityManager *.*) && args(em)")
   void entityManagerFieldGet_3(EntityManager em){}
@Around("entityManagerFieldGet_3(em)")
   public EntityManager getEntityManager_3(JoinPoint jp, EntityManager em){
       System.err.println("****getEntityManager_3 em=" + em);
       return null;
   }

   //---- matches in AJDT, not invoked at runtime
@Pointcut("get(@javax.persistence.PersistenceContext javax.persistence.EntityManager *.*) && this(em)")
   void entityManagerFieldGet_4(EntityManager em){}
@Around("entityManagerFieldGet_4(em)")
   public EntityManager getEntityManager_4(JoinPoint jp, EntityManager em){
       System.err.println("****getEntityManager_4 em=" + em);
       return null;
   }

   //---- matches in AJDT, not invoked at runtime
@Pointcut("get(@javax.persistence.PersistenceContext javax.persistence.EntityManager *.*) && @this(pc)")
   void entityManagerFieldGet_5(PersistenceContext pc){}
@Around("entityManagerFieldGet_5(pc)") public EntityManager getEntityManager_5(JoinPoint jp, PersistenceContext pc){
       System.err.println("****getEntityManager_5 pc=" + pc);
       return null;
   }

   //---- matches in AJDT, not invoked at runtime
@Pointcut("get(@javax.persistence.PersistenceContext javax.persistence.EntityManager *.*) && target(em)")
   void entityManagerFieldGet_6(EntityManager em){}
@Around("entityManagerFieldGet_6(em)")
   public EntityManager getEntityManager_6(JoinPoint jp, EntityManager em){
       System.err.println("****getEntityManager_6 em=" + em);
       return null;
   }

   //---- matches in AJDT, not invoked at runtime
@Pointcut("get(@javax.persistence.PersistenceContext javax.persistence.EntityManager *.*) && @target(pc)")
   void entityManagerFieldGet_7(PersistenceContext pc){}
@Around("entityManagerFieldGet_7(pc)") public EntityManager getEntityManager_7(JoinPoint jp, PersistenceContext pc){
       System.err.println("****getEntityManager_7 pc=" + pc);
       return null;
   }


Also I only run with LTW'ing since I can't run it pre-compiled because ADJT is eating duplicate aop.xml/peristence.xml files in multiple eclipse output paths. Also because of this I haven't tried this with code style. I can peel this out of my larger project and create a small test case. But i you think you know the problem.... I suppose I can get the LTW'er spew out the weaved class file... I'll have to look up how to do that. Where whould you like me to send you the class file to?

thanks!

-bk


Andy Clement wrote:
I don't know if we have many tests for annotation style pointcuts
using annotation binding designators.  Does it behave any differently
using code style pointcuts?  the runtime test here is simple
reflection to obtain the annotation.  I've half an idea what it might
be - if you email me the .class file i will take a look

Andy.

On 30/11/06, Barry Kaplan <groups1@xxxxxxxxxxx> wrote:
I have advised that is getting weaved with a runtime test:

    @Pointcut("get(@com.foliofn.icconvert.folio1.account.SessionContext
org.hibernate.SessionFactory *.*) && @target(sc)")
    void sessionFactoryFieldGet(SessionContext sc){}

    @Pointcut("get(@com.foliofn.icconvert.folio1.account.SessionContext
org.hibernate.Session *.*) && @target(sc)")
    void sessionFieldGet(SessionContext sc){}

    @Around("sessionFactoryFieldGet(sc)")
    public SessionFactory getSessionFactory(JoinPoint jp, SessionContext
sc){
        return sessionFactories.get(sc.unitName());
    }

    @Around("sessionFieldGet(sc)")
    public Session getSession(JoinPoint jp, SessionContext sc){
        return sessionFactories.get(sc.unitName()).getCurrentSession();
    }

The advise never executes, but I cannot see why. I've turned on the
weavers debugging in aop.xml but that adds no new information. Is there
any way I get aspectj to log info at runtime on the actual checks?

-barry
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top