Browse Source

DATACMNS-221 - Added support for Unicode characters in PartTree.

Altered parsing regular expressions to support unicode characters.
pull/16/head
Aleksander Blomskøld 14 years ago committed by Oliver Gierke
parent
commit
f0ffd0316c
  1. 2
      spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyPath.java
  2. 6
      spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java
  3. 6
      spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java
  4. 16
      spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java

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

@ -340,7 +340,7 @@ public class PropertyPath implements Iterable<PropertyPath> { @@ -340,7 +340,7 @@ public class PropertyPath implements Iterable<PropertyPath> {
exception = e;
}
Pattern pattern = Pattern.compile("[A-Z]+[a-z]*$");
Pattern pattern = Pattern.compile("\\p{Lu}+\\p{Ll}*$");
Matcher matcher = pattern.matcher(source);
if (matcher.find() && matcher.start() != 0) {

6
spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2008-2010 the original author or authors.
* Copyright 2008-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.
@ -35,7 +35,7 @@ import org.springframework.util.StringUtils; @@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
*/
public class OrderBySource {
private static final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=[A-Z])";
private static final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=\\p{Lu})";
private static final Pattern DIRECTION_SPLIT = Pattern.compile("(.+)(Asc|Desc)$");
private final List<Order> orders;
@ -107,4 +107,4 @@ public class OrderBySource { @@ -107,4 +107,4 @@ public class OrderBySource {
public String toString() {
return "Order By " + StringUtils.collectionToDelimitedString(orders, ", ");
}
}
}

6
spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2008-2010 the original author or authors.
* Copyright 2008-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.
@ -37,8 +37,8 @@ import org.springframework.util.StringUtils; @@ -37,8 +37,8 @@ import org.springframework.util.StringUtils;
*/
public class PartTree implements Iterable<OrPart> {
private static final Pattern PREFIX_TEMPLATE = Pattern.compile("^(find|read|get)(\\p{Upper}.*?)??By");
private static final String KEYWORD_TEMPLATE = "(%s)(?=[A-Z])";
private static final Pattern PREFIX_TEMPLATE = Pattern.compile("^(find|read|get)(\\p{Lu}.*?)??By");
private static final String KEYWORD_TEMPLATE = "(%s)(?=\\p{Lu})";
/**
* The subject, for example "findDistinctUserByNameOrderByAge" would have the subject "DistinctUser".

16
spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java

@ -307,6 +307,17 @@ public class PartTreeUnitTests { @@ -307,6 +307,17 @@ public class PartTreeUnitTests {
"commonNameContaining", Organization.class) });
}
/**
* @see DATACMNS-221
*/
@Test
public void parsesSpecialCharactersCorrectly() {
PartTree tree = new PartTree("findByØreAndÅrOrderByÅrAsc", DomainObjectWithSpecialChars.class);
assertPart(tree, new Part[] { new Part("øre", DomainObjectWithSpecialChars.class),
new Part("år", DomainObjectWithSpecialChars.class) });
assertTrue(tree.getSort().getOrderFor("år").isAscending());
}
private static void assertType(Iterable<String> sources, Type type, String property) {
assertType(sources, type, property, 1, true);
}
@ -380,4 +391,9 @@ public class PartTreeUnitTests { @@ -380,4 +391,9 @@ public class PartTreeUnitTests {
String commonName;
String legalName;
}
class DomainObjectWithSpecialChars {
String øre;
String år;
}
}

Loading…
Cancel
Save