From f0ffd0316c327935e7b4c79cd46c19e606dc1d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Blomsk=C3=B8ld?= Date: Mon, 3 Sep 2012 06:39:37 +0200 Subject: [PATCH] DATACMNS-221 - Added support for Unicode characters in PartTree. Altered parsing regular expressions to support unicode characters. --- .../data/mapping/PropertyPath.java | 2 +- .../repository/query/parser/OrderBySource.java | 6 +++--- .../data/repository/query/parser/PartTree.java | 6 +++--- .../query/parser/PartTreeUnitTests.java | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyPath.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyPath.java index cce9a9ec8..b77232e47 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyPath.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyPath.java @@ -340,7 +340,7 @@ public class PropertyPath implements Iterable { 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) { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java index ad66c533d..5c03c898d 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java @@ -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; */ 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 orders; @@ -107,4 +107,4 @@ public class OrderBySource { public String toString() { return "Order By " + StringUtils.collectionToDelimitedString(orders, ", "); } -} \ No newline at end of file +} diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java index 12c9b510b..0305ca42e 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java @@ -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; */ public class PartTree implements Iterable { - 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". diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java index 869c7414d..9f3246e33 100644 --- a/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java +++ b/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java @@ -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 sources, Type type, String property) { assertType(sources, type, property, 1, true); } @@ -380,4 +391,9 @@ public class PartTreeUnitTests { String commonName; String legalName; } + + class DomainObjectWithSpecialChars { + String øre; + String år; + } }