DATACMNS-154 - Fixed query method detection when re-declararing CrudRepositoryMethods.
With the fix for DATACMNS-151 we apparently broke the generic parameter type matching for methods that carry the domain class type parameter as argument. We now inspect the bound and make sure we compare the name of it if it's a TypeVariable or use the plain parameter type if its not.
This commit is contained in:
@@ -292,7 +292,10 @@ class DefaultRepositoryInformation extends AbstractRepositoryMetadata implements
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DOMAIN_TYPE_NAME.equals(variable.getBounds()[0].toString()) && parameterType.isAssignableFrom(entityType)) {
|
||||
Type boundType = variable.getBounds()[0];
|
||||
String referenceName = boundType instanceof TypeVariable ? boundType.toString() : variable.toString();
|
||||
|
||||
if (DOMAIN_TYPE_NAME.equals(referenceName) && parameterType.isAssignableFrom(entityType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,9 +120,13 @@ public class DefaultRepositoryInformationUnitTests {
|
||||
RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, null);
|
||||
|
||||
Method saveMethod = BaseRepository.class.getMethod("save", Object.class);
|
||||
Method deleteMethod = BaseRepository.class.getMethod("delete", Object.class);
|
||||
|
||||
assertThat(information.getQueryMethods(), is(Matchers.<Method> iterableWithSize(2)));
|
||||
assertThat(information.getQueryMethods(), not(hasItem(saveMethod)));
|
||||
Iterable<Method> queryMethods = information.getQueryMethods();
|
||||
|
||||
assertThat(queryMethods, not(hasItem(saveMethod)));
|
||||
assertThat(queryMethods, not(hasItem(deleteMethod)));
|
||||
assertThat(queryMethods, is(Matchers.<Method> iterableWithSize(2)));
|
||||
}
|
||||
|
||||
private Method getMethodFrom(Class<?> type, String name) {
|
||||
@@ -159,11 +163,13 @@ public class DefaultRepositoryInformationUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
interface BaseRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
|
||||
interface BaseRepository<S, ID extends Serializable> extends CrudRepository<S, ID> {
|
||||
|
||||
T findBySomething(String something);
|
||||
S findBySomething(String something);
|
||||
|
||||
<K extends T> K save(K entity);
|
||||
<K extends S> K save(K entity);
|
||||
|
||||
void delete(S entity);
|
||||
}
|
||||
|
||||
interface ConcreteRepository extends BaseRepository<User, Integer> {
|
||||
|
||||
Reference in New Issue
Block a user