Browse Source

DATACMNS-963 - Returned type returns distinct input properties now.

We now manually filter already gathered property names in ReturnedInterface.getInputProperties() as we have to deal with duplications for properties with the same name at different levels of the inheritance hierarchy.
pull/347/head
Oliver Gierke 9 years ago
parent
commit
ae3869ca21
  1. 4
      src/main/java/org/springframework/data/repository/query/ReturnedType.java
  2. 22
      src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java

4
src/main/java/org/springframework/data/repository/query/ReturnedType.java

@ -191,7 +191,9 @@ public abstract class ReturnedType { @@ -191,7 +191,9 @@ public abstract class ReturnedType {
List<String> properties = new ArrayList<String>();
for (PropertyDescriptor descriptor : information.getInputProperties()) {
properties.add(descriptor.getName());
if (!properties.contains(descriptor.getName())) {
properties.add(descriptor.getName());
}
}
return properties;

22
src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java

@ -179,6 +179,20 @@ public class ReturnedTypeUnitTests { @@ -179,6 +179,20 @@ public class ReturnedTypeUnitTests {
assertThat(type.isProjecting(), is(false));
}
/**
* @see DATACMNS-963
*/
@Test
public void detectsDistinctInputProperties() {
ReturnedType type = ReturnedType.of(Child.class, Object.class, new SpelAwareProxyProjectionFactory());
List<String> properties = type.getInputProperties();
assertThat(properties, hasSize(1));
assertThat(properties, contains("firstname"));
}
private static ReturnedType getReturnedType(String methodName, Class<?>... parameters) throws Exception {
return getQueryMethod(methodName, parameters).getResultProcessor().getReturnedType();
}
@ -262,4 +276,12 @@ public class ReturnedTypeUnitTests { @@ -262,4 +276,12 @@ public class ReturnedTypeUnitTests {
@Value("#{target.firstname + ' ' + target.lastname}")
String getFullName();
}
static interface Parent {
String getFirstname();
}
static interface Child extends Parent {
String getFirstname();
}
}

Loading…
Cancel
Save