Skip to content

QueryExecutorMethodInterceptor does not delegate custom method execution to ImplementationMethodExecutionInterceptor [DATACMNS-1472] #1905

Open
@spring-projects-issues

Description

@spring-projects-issues

kchobantonov opened DATACMNS-1472 and commented

In spring-data-commons 1.8.0.RELEASE the QueryExecutorMethodInterceptor implementation checked if the query method is also a custom method and invoked the implementation method instead if this was the case.

Now since the query method execution and custom method (implementation) execution are separated into QueryExecutorMethodInterceptor and ImplementationMethodExecutionInterceptor, the new QueryExecutorMethodInterceptor no longer checks if the query method is also a custom method to skip it (effectively delegating the execution to ImplementationMethodExecutionInterceptor object)

Solutions

1) 

If we want to preserve the backward compatibility then we could change the QueryExecutorMethodInterceptor doInvoke method to skip any custom methods. So change 

 

if (hasQueryFor(method)) { 
  return queries.get(method).execute(arguments); 
}

 

to the following code (assuming that the passed RepositoryInformation parameter to the constructor is preserved as a field in that class )

 

if (hasQueryFor(method) && !repositoryInformation.isCustomMethod(method)) { 
   return queries.get(method).execute(arguments); 
}

 

  1. If the new functionality is desired then

Make creation of QueryExecutorMethodInterceptor extensible, currently we need to override 

public <T> T getRepository( Class<T> repositoryInterface, RepositoryFragments fragments )

that is in org.springframework.data.repository.core.support.RepositoryFactorySupport class

which refers to private methods - validate, getRepositoryComposition, getRepositoryInformation as well as private postProcessors field that forces us to use reflection to call those methods (validate could be simply copied over to the subclass but not the rest)

Make also the QueryExecutorMethodInterceptor extensible by changing the visibility for doInvoke(MethodInvocation invocation) from private to protected so that we can alter the doInvoke method to check for implementation methods as well - if the default is not going to be modified.

 

As separate note : should we change the visibility for org.springframework.data.repository.core.support.QueryExecutionResultHandler class from package to public if we want to extend it ?

Why we need a method to be both - query method and custom implementation method

The reason why the custom implementation method is annotated with a query annotation (custom query annotation that is annotated with org.springframework.data.annotation.QueryAnnotation) is because we need that repository method to be automatically exported as REST endpoint by RepositorySearchController


Affects: 2.1.4 (Lovelace SR4)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions