diff --git a/src/docbkx/repositories.xml b/src/docbkx/repositories.xml index 392ed2348..e430d428b 100644 --- a/src/docbkx/repositories.xml +++ b/src/docbkx/repositories.xml @@ -316,7 +316,7 @@ interface UserRepository extends MyBaseRepository<User, Long> { The query builder mechanism built into Spring Data repository infrastructure is useful for building constraining queries over entities of the repository. The mechanism strips the prefixes - find…By, read…By, and get…By + find…By, read…By, query…By, and get…By from the method and starts parsing the rest of it. The introducing clause can contain further expressions such as a Distinct to set a distinct flag on the query to be created. However, the first diff --git a/src/main/java/org/springframework/data/repository/query/parser/PartTree.java b/src/main/java/org/springframework/data/repository/query/parser/PartTree.java index a5d9f166c..7ce8b8ba8 100644 --- a/src/main/java/org/springframework/data/repository/query/parser/PartTree.java +++ b/src/main/java/org/springframework/data/repository/query/parser/PartTree.java @@ -38,7 +38,7 @@ import org.springframework.util.StringUtils; */ public class PartTree implements Iterable { - private static final Pattern PREFIX_TEMPLATE = Pattern.compile("^(find|read|get|count)(\\p{Lu}.*?)??By"); + private static final Pattern PREFIX_TEMPLATE = Pattern.compile("^(find|read|get|count|query)(\\p{Lu}.*?)??By"); /* * We look for a pattern of: keyword followed by diff --git a/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java b/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java index a47a79715..18df79616 100644 --- a/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java +++ b/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java @@ -44,7 +44,7 @@ import org.springframework.data.repository.query.parser.PartTree.OrPart; */ public class PartTreeUnitTests { - private String[] PREFIXES = { "find", "read", "get" }; + private String[] PREFIXES = { "find", "read", "get", "query" }; @Test(expected = IllegalArgumentException.class) public void rejectsNullSource() throws Exception { @@ -417,6 +417,19 @@ public class PartTreeUnitTests { assertThat(tree.isCountProjection(), is(true)); } + /** + * @see DATACMNS-399 + */ + @Test + public void queryPrefixShouldBeSupportedInRepositoryQueryMethods() { + + PartTree tree = new PartTree("queryByFirstnameAndLastname", User.class); + Iterable parts = tree.getParts(); + + assertThat(parts, hasItem(part("firstname"))); + assertThat(parts, hasItem(part("lastname"))); + } + /** * @see DATACMNS-303 */