From e92284540788a25207c23575a273c83f7468a7b3 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 4 Sep 2012 11:05:55 +0200 Subject: [PATCH] DATACMNS-220, DATAJPA-174 - Updated reference docs on query parsing. Updated the repositories reference documentation section on query parsing to reflect the correct usage of method prefixes, how to use the Distinct, IgnoreCase and OrderBy clauses. --- src/docbkx/repositories.xml | 44 ++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/docbkx/repositories.xml b/src/docbkx/repositories.xml index a97899b7a..6560aecf6 100644 --- a/src/docbkx/repositories.xml +++ b/src/docbkx/repositories.xml @@ -319,12 +319,14 @@ interface UserRepository extends MyBaseRepository<User, Long> { The query builder mechanism built into Spring Data repository infrastructure is useful to build constraining queries over entities - of the repository. We will strip the prefixes findBy, - find, readBy, read, - getBy as well as get from the method and - start parsing the rest of it. At a very basic level you can define - conditions on entity properties and concatenate them with - AND and OR. + of the repository. We will strip the prefixes find…By, + read…By, as well as get…By from the method + and start 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 By + acts as delimiter to indicate the start of the actual criterias. At a + very basic level you can define conditions on entity properties and + concatenate them with AND and OR. Query creation from method names @@ -332,6 +334,19 @@ interface UserRepository extends MyBaseRepository<User, Long> { public interface PersonRepository extends Repository<User, Long> { List<Person> findByEmailAddressAndLastname(EmailAddress emailAddress, String lastname); + + // Enables the distinct flag for the query + List<Person> findDistinctPeopleByLastnameOrFirstname(String lastname, String firstname); + List<Person> findPeopleDistinctByLastnameOrFirstname(String lastname, String firstname); + + // Enabling ignoring case for an individual property + List<Person> findByLastnameIgnoreCase(String lastname); + // Enabling ignoring case for all suitable properties + List<Person> findByLastnameAndFirstnameAllIgnoreCase(String lastname, String firstname); + + // Enabling static ORDER BY for a query + List<Person> findByLastnameOrderByFirstnameAsc(String lastname); + List<Person> findByLastnameOrderByFirstnameDesc(String lastname); } @@ -347,6 +362,23 @@ interface UserRepository extends MyBaseRepository<User, Long> { datastore to datastore please consult the according part of the reference documentation. + As you can see the method parser also supports setting an ignore + case flag for individual properties (e.g. + findByLastnameIgnoreCase(…)) or for all + properties of a type that support ignoring case (i.e. usually + Strings, e.g. + findByLastnameAndFirstnameAllIgnoreCase(…)). + Whether ignoring cases is supported my differ from store to store, so + consult the relevant sections of the store specific query method + reference docs. + + Static ordering can be applied by appending an + OrderBy clause to the query method referencing a property + and providing a sorting direction (Asc or + Desc). To create a query method that supports dynamic + sorting have a look at . +
Property expressions