DATACMNS-363 - Improved support for unicode characters for repository query methods.

In order to find a keyword like "And" followed by a property name we now probe also for non Basic Latin characters in addition to just an uppercase letter. This is needed to support property-names with characters that don't have an upper or lowercase representation. This allows us to support finder methods like: findBy이름And생일OrderBy생일Asc(…).

Original pull request: #47.
This commit is contained in:
Thomas Darimont
2013-10-01 14:59:34 +02:00
committed by Oliver Gierke
parent 93b2d39cf1
commit 43b7a54294
2 changed files with 134 additions and 14 deletions

View File

@@ -34,11 +34,23 @@ import org.springframework.util.StringUtils;
* each query execution.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
public class PartTree implements Iterable<OrPart> {
private static final Pattern PREFIX_TEMPLATE = Pattern.compile("^(find|read|get|count)(\\p{Lu}.*?)??By");
private static final String KEYWORD_TEMPLATE = "(%s)(?=\\p{Lu})";
/*
* We look for a pattern of: keyword followed by
*
* an upper-case letter that has a lower-case variant \p{Lu}
* OR
* any other letter NOT in the BASIC_LATIN Uni-code Block \\P{InBASIC_LATIN} (like Chinese, Korean, Japanese, etc.).
*
* @see http://www.regular-expressions.info/unicode.html
* @see http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#ubc
*/
private static final String KEYWORD_TEMPLATE = "(%s)(?=(\\p{Lu}|\\P{InBASIC_LATIN}))";
/**
* The subject, for example "findDistinctUserByNameOrderByAge" would have the subject "DistinctUser".