Browse Source

DATACMNS-257 - PropertyPath can now handle all-uppercase fields.

So far, PropertyPath inevitably uncapitalized the property names it was created for. We now check, whether the source name is all uppercase and prevent uncapitalization in this case.
pull/19/head
Oliver Gierke 13 years ago
parent
commit
0c4ed8a86a
  1. 3
      spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyPath.java
  2. 29
      spring-data-commons-core/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java

3
spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyPath.java

@ -35,6 +35,7 @@ import org.springframework.util.StringUtils; @@ -35,6 +35,7 @@ import org.springframework.util.StringUtils;
public class PropertyPath implements Iterable<PropertyPath> {
private static final String DELIMITERS = "_\\.";
private static final String ALL_UPPERCASE = "[A-Z0-9._$]+";
private static final Pattern SPLITTER = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", DELIMITERS));
private final TypeInformation<?> owningType;
@ -67,7 +68,7 @@ public class PropertyPath implements Iterable<PropertyPath> { @@ -67,7 +68,7 @@ public class PropertyPath implements Iterable<PropertyPath> {
Assert.hasText(name);
Assert.notNull(owningType);
String propertyName = StringUtils.uncapitalize(name);
String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
TypeInformation<?> type = owningType.getProperty(propertyName);
if (type == null) {

29
spring-data-commons-core/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -281,10 +281,37 @@ public class PropertyPathUnitTests { @@ -281,10 +281,37 @@ public class PropertyPathUnitTests {
assertThat(left.hashCode(), is(not(shortPath.hashCode())));
}
/**
* @see DATACMNS-257
*/
@Test
public void findsAllUppercaseProperty() {
PropertyPath path = PropertyPath.from("UUID", Foo.class);
assertThat(path, is(notNullValue()));
assertThat(path.getSegment(), is("UUID"));
}
/**
* @see DATACMNS-257
*/
@Test
public void findsNestedAllUppercaseProperty() {
PropertyPath path = PropertyPath.from("_fooUUID", Sample2.class);
assertThat(path, is(notNullValue()));
assertThat(path.getSegment(), is("_foo"));
assertThat(path.hasNext(), is(true));
assertThat(path.next().getSegment(), is("UUID"));
}
private class Foo {
String userName;
String _email;
String UUID;
}
private class Bar {

Loading…
Cancel
Save