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?