Browse Source

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.
pull/14/head
Oliver Gierke 14 years ago
parent
commit
f1516a96aa
  1. 5
      spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java
  2. 16
      spring-data-commons-core/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java

5
spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java

@ -292,7 +292,10 @@ class DefaultRepositoryInformation extends AbstractRepositoryMetadata implements @@ -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;
}

16
spring-data-commons-core/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java

@ -120,9 +120,13 @@ public class DefaultRepositoryInformationUnitTests { @@ -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 { @@ -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> {
S findBySomething(String something);
T findBySomething(String something);
<K extends S> K save(K entity);
<K extends T> K save(K entity);
void delete(S entity);
}
interface ConcreteRepository extends BaseRepository<User, Integer> {

Loading…
Cancel
Save