From f1516a96aac4fc97d4907448c4cdce16e18fce76 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 19 Apr 2012 12:45:33 +0200 Subject: [PATCH] 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. --- .../support/DefaultRepositoryInformation.java | 5 ++++- .../DefaultRepositoryInformationUnitTests.java | 16 +++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java index 38f1cf1b9..8f524847a 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java @@ -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; } diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java index 5cb699372..fb4b43987 100644 --- a/spring-data-commons-core/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java +++ b/spring-data-commons-core/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java @@ -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. iterableWithSize(2))); - assertThat(information.getQueryMethods(), not(hasItem(saveMethod))); + Iterable queryMethods = information.getQueryMethods(); + + assertThat(queryMethods, not(hasItem(saveMethod))); + assertThat(queryMethods, not(hasItem(deleteMethod))); + assertThat(queryMethods, is(Matchers. iterableWithSize(2))); } private Method getMethodFrom(Class type, String name) { @@ -159,11 +163,13 @@ public class DefaultRepositoryInformationUnitTests { } } - interface BaseRepository extends CrudRepository { + interface BaseRepository extends CrudRepository { + + S findBySomething(String something); - T findBySomething(String something); + K save(K entity); - K save(K entity); + void delete(S entity); } interface ConcreteRepository extends BaseRepository {