May be I didn't get you but may be JpaTransactionAdvisorImpl can help. It uses 
@CommitAfter and checks the PersistenceContext using @PersistenceContext on the 
same method to get the context for which the method has to be advised. 


On Oct 22, 2012, at 8:22 PM, Rural Hunter wrote:

> hmm...I think it won't work in any way trying to get the annotation from the 
> method where plastic already removes the annotation...
> 
> 于 2012/10/22 18:34, Taha Siddiqi 写道:
>> May be get the annotation in the advisor implementation using 
>> MethodAdviceReceiver#getMethodAnnotation
>> 
>> 
>> On Oct 22, 2012, at 3:11 PM, Rural Hunter wrote:
>> 
>>> 于 2012/10/22 17:02, Taha Siddiqi 写道:
>>>> Did you try invocation.getInstance().getAnnotation() ?
>>> What is that for? I read the API and seems it's not what I needed. My 
>>> annotation is on methods being advised, not on the class instance. I also 
>>> tried invocation.getMethod().getAnnotations() and it returns an empty 
>>> array. I just googled and found an old post:
>>> http://tapestry.1045711.n5.nabble.com/Plastic-amp-proxy-annotations-td4453361.html
>>> 
>>> Seems annotation is not copied for methods by plastic...If it's still true, 
>>> is there anything else I can implement what I needed? My intention is to 
>>> audit methods call on my DAO services, including user information from 
>>> session, method names(or operation type: update/delete/insert etc.) and 
>>> some parameters(to get record id etc.), which I planed to implement by 
>>> service advising and annotation.
>>>> On Oct 22, 2012, at 1:15 PM, Rural Hunter wrote:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> I have an annotation:
>>>>> @Documented
>>>>> @Retention(RetentionPolicy.RUNTIME)
>>>>> @Target(ElementType.METHOD)
>>>>> public @interface Audit
>>>>> {
>>>>>    String operate() default "";
>>>>>    String desc() default "";
>>>>>    int type();
>>>>>    int idParamIndex() default 0;
>>>>> }
>>>>> 
>>>>> I put on some methods of my DAO services and advised them in AppModule:
>>>>> 
>>>>> DAOInterface:
>>>>>    @Audit(type=1)
>>>>>    public void delete(int id) throws Exception;
>>>>> 
>>>>> AppModule:
>>>>>        for (Method m : receiver.getInterface().getMethods())
>>>>>        {
>>>>>            if (m.getAnnotation(Audit.class) != null)
>>>>>            {
>>>>>                System.out.println("advising "+m.getName());
>>>>>                receiver.adviseMethod(m, advice);
>>>>>            }
>>>>>        }
>>>>> 
>>>>> There is no problem and I can see the methods are advised by the 
>>>>> System.out above. But in the advise method, I can not get the Audit 
>>>>> annotation:
>>>>>    public void advise(MethodInvocation invocation)
>>>>>    {
>>>>>        String methodName = invocation.getMethod().getName();
>>>>>        Audit audit = invocation.getAnnotation(Audit.class);
>>>>>        System.out.println("method="+methodName+", audit="+audit);
>>>>>        invocation.proceed();
>>>>>    }
>>>>> 
>>>>> The above advise method is called and I can see the system.out is always 
>>>>> like this: "method=delete, audit=null". I need some information in the 
>>>>> Audit annotation but why I can not get the annotation instance?
>>>>> 
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>> 
>>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>> 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to