DATACMNS-1383 - Parameters now properly detects Pageable and Sort extensions.
One of the constructors of Pageable wasn't properly checking for assignability of Pageable parameters to detect them but was expecting Pageable itself being used under all circumstances. This has now been opened up by an assignability check. $ Conflicts: $ src/test/java/org/springframework/data/repository/query/ParametersUnitTests.java
This commit is contained in:
@@ -67,6 +67,9 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
|
||||
this.parameters = new ArrayList<T>(types.size());
|
||||
this.dynamicProjectionIndex = -1;
|
||||
|
||||
int pageableIndex = -1;
|
||||
int sortIndex = -1;
|
||||
|
||||
for (int i = 0; i < types.size(); i++) {
|
||||
|
||||
MethodParameter methodParameter = new MethodParameter(method, i);
|
||||
@@ -82,11 +85,19 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
|
||||
this.dynamicProjectionIndex = parameter.getIndex();
|
||||
}
|
||||
|
||||
if (Pageable.class.isAssignableFrom(parameter.getType())) {
|
||||
pageableIndex = i;
|
||||
}
|
||||
|
||||
if (Sort.class.isAssignableFrom(parameter.getType())) {
|
||||
sortIndex = i;
|
||||
}
|
||||
|
||||
parameters.add(parameter);
|
||||
}
|
||||
|
||||
this.pageableIndex = types.indexOf(Pageable.class);
|
||||
this.sortIndex = types.indexOf(Sort.class);
|
||||
this.pageableIndex = pageableIndex;
|
||||
this.sortIndex = sortIndex;
|
||||
|
||||
assertEitherAllParamAnnotatedOrNone();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
@@ -161,6 +162,14 @@ public class ParametersUnitTests {
|
||||
assertThat(parameters.getParameter(0).getType(), is(typeCompatibleWith(String.class)));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1383
|
||||
public void acceptsCustomPageableParameter() throws Exception {
|
||||
|
||||
Parameters<?, Parameter> parameters = getParametersFor("customPageable", SomePageable.class);
|
||||
|
||||
assertThat(parameters.hasPageableParameter(), is(true));
|
||||
}
|
||||
|
||||
private Parameters<?, Parameter> getParametersFor(String methodName, Class<?>... parameterTypes)
|
||||
throws SecurityException, NoSuchMethodException {
|
||||
|
||||
@@ -194,5 +203,9 @@ public class ParametersUnitTests {
|
||||
<T> T dynamicBind(Class<T> type, Class<?> one, Class<Object> two);
|
||||
|
||||
void methodWithOptional(Optional<String> optional);
|
||||
|
||||
Page<Object> customPageable(SomePageable pageable);
|
||||
}
|
||||
|
||||
interface SomePageable extends Pageable {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user