DATACMNS-1008 - Reintroduced lost support for non-generic redeclarations of generic CRUD methods.
The changes for DATACMNS-854 and DATACMNS-912 dropped the support for the simpler redeclaration of generic methods like CrudRepository.save(…) which as of the changes requires to be redeclared like <T extends Foo> T save(T entity). Previously a simple redeclaration like Foo save(Foo entity) was sufficient. This commit reintroduces the check for a direct match of the parameter types and shortcuts the more detailed check that's necessary in case of type variables being involved. Related tickets: DATACMNS-854, DATACMNS-912.
This commit is contained in:
@@ -372,6 +372,10 @@ class DefaultRepositoryInformation implements RepositoryInformation {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (types[i].equals(parameterType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!type.isAssignableFrom(parameterType) || !type.equals(methodParameterTypes[i])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -223,12 +223,12 @@ public class DefaultRepositoryInformationUnitTests {
|
||||
@Test // DATACMNS-912
|
||||
public void discoversCustomlyImplementedCrudMethodWithGenericParameters() throws Exception {
|
||||
|
||||
SampleRepositoryImpl customImplementation = new SampleRepositoryImpl();
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
GenericsSaveRepositoryImpl customImplementation = new GenericsSaveRepositoryImpl();
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(GenericsSaveRepository.class);
|
||||
RepositoryInformation information = new DefaultRepositoryInformation(metadata, RepositoryFactorySupport.class,
|
||||
customImplementation.getClass());
|
||||
|
||||
Method customBaseRepositoryMethod = SampleRepository.class.getMethod("save", Object.class);
|
||||
Method customBaseRepositoryMethod = GenericsSaveRepository.class.getMethod("save", Object.class);
|
||||
assertThat(information.isCustomMethod(customBaseRepositoryMethod), is(true));
|
||||
}
|
||||
|
||||
@@ -244,6 +244,18 @@ public class DefaultRepositoryInformationUnitTests {
|
||||
is(DummyRepositoryImpl.class.getMethod("save", Iterable.class)));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1008, DATACMNS-912, DATACMNS-854
|
||||
public void discoversCustomlyImplementedCrudMethodWithoutGenericParameters() throws Exception {
|
||||
|
||||
SimpleSaveRepositoryImpl customImplementation = new SimpleSaveRepositoryImpl();
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(SimpleSaveRepository.class);
|
||||
RepositoryInformation information = new DefaultRepositoryInformation(metadata, RepositoryFactorySupport.class,
|
||||
customImplementation.getClass());
|
||||
|
||||
Method customBaseRepositoryMethod = SimpleSaveRepository.class.getMethod("save", Object.class);
|
||||
assertThat(information.isCustomMethod(customBaseRepositoryMethod), is(true));
|
||||
}
|
||||
|
||||
private static Method getMethodFrom(Class<?> type, String name) {
|
||||
|
||||
for (Method method : type.getMethods()) {
|
||||
@@ -346,11 +358,13 @@ public class DefaultRepositoryInformationUnitTests {
|
||||
List<User> findAll();
|
||||
}
|
||||
|
||||
interface SampleRepository extends CrudRepository<Sample, Long> {}
|
||||
// DATACMNS-854, DATACMNS-912
|
||||
|
||||
static class SampleRepositoryImpl {
|
||||
interface GenericsSaveRepository extends CrudRepository<Sample, Long> {}
|
||||
|
||||
public <S extends Sample> S save(S entity) {
|
||||
static class GenericsSaveRepositoryImpl {
|
||||
|
||||
public <T extends Sample> T save(T entity) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -367,4 +381,15 @@ public class DefaultRepositoryInformationUnitTests {
|
||||
|
||||
private @Delegate CrudRepository<T, ID> delegate;
|
||||
}
|
||||
|
||||
// DATACMNS-1008, DATACMNS-854, DATACMNS-912
|
||||
|
||||
interface SimpleSaveRepository extends CrudRepository<Sample, Long> {}
|
||||
|
||||
static class SimpleSaveRepositoryImpl {
|
||||
|
||||
public Sample save(Sample entity) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user