Combining two pointcuts but with parameters (if is possible)

徘徊边缘 提交于 2019-12-25 09:08:44

问题


For a Spring application project, before to delete or update something (an entity) I want before check if that object exists.

I have the following:

@Pointcut("execution(* com.manuel.jordan.service.impl.PersonaServiceImpl.deleteOne(String)) 
&& args(id)")
public void deleteOnePointcut(String id){}

@Pointcut("execution(* com.manuel.jordan.service.impl.PersonaServiceImpl.updateOne(com.manuel.jordan.domain.Persona)) 
&& args(persona)")
public void updateOnePointcut(Persona persona){}

If I use:

@Around("PersonaServicePointcut.deleteOnePointcut(id)")
public void delete(ProceedingJoinPoint proceedingJoinPoint, String id) throws Throwable{
    if(id != null){
        personaService.findOneById(id);
        //throw error if not exists, 
        //has no sense delete something that does not exists
        ...
    }
...

works.

Just how playing I've tried the following (a combination of two pointcuts shown above):

@Around("PersonaServicePointcut.deleteOnePointcut(id) ||
               PersonaServicePointcut.updateOnePointcut(persona)")
    public Object mai(ProceedingJoinPoint proceedingJoinPoint, String id, Persona persona){
        if(id != null){
            personaService.findOneById(id);
            //throw error
        }

        if(persona != null){
            personaService.findOneById(persona.getId());
            //throw error
        }

        //...

        proceedingJoinPoint.proceed();

        return null;
    }

But I get

Caused by: java.lang.IllegalArgumentException: 
error at ::0 inconsistent binding

I am assuming because either the 2nd or 3rd parameter is null since we have an OR. I mean all the parameters should be assigned.

I have read some tutorials about combining pointcuts, but all of them without parameters.

Just curious if is possible accomplish this approach. If yes how?

来源:https://stackoverflow.com/questions/39730232/combining-two-pointcuts-but-with-parameters-if-is-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!