From 302f111c56680f7d2cb4e80ee9479c395ee9b4ea Mon Sep 17 00:00:00 2001 From: Mark Pollack Date: Thu, 7 Apr 2011 01:41:37 -0400 Subject: [PATCH] DATADOC-82 - Document QueryDslPredicateExecutor --- src/docbkx/reference/mongo-repositories.xml | 34 +++++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/docbkx/reference/mongo-repositories.xml b/src/docbkx/reference/mongo-repositories.xml index a0cbdd9b2..cb80e7e50 100644 --- a/src/docbkx/reference/mongo-repositories.xml +++ b/src/docbkx/reference/mongo-repositories.xml @@ -304,9 +304,9 @@ public class PersonRepositoryTests { Mongo repository support integrates with the QueryDSL project which provides a - meant to perform type-safe queries (no strings) in Java. To quote from - the project description, "Instead of writing queries as inline strings - or externalizing them into XML files they are constructed via a fluent + means to perform type-safe queries in Java. To quote from the project + description, "Instead of writing queries as inline strings or + externalizing them into XML files they are constructed via a fluent API." It provides the following features @@ -334,22 +334,32 @@ public class PersonRepositoryTests { - This will enable you to write queries as shown below + Please refer to the QueryDSL documentation which describes how to + bootstrap your environment for APT based code generation using + Maven or using + Ant. + + Using QueryDSL you will be able to write queries as shown + below QPerson person = new QPerson("person"); List<Person> result = repository.findAll(person.address.zipCode.eq("C0123")); - Page<Person> page = repository.findAll(person.lastname.contains("a"), new PageRequest(0, 2, Direction.ASC, "lastname")); - QPerson is a class that is generated (via the Java annotation post - processing tool) which is a Predicate that allows you to write type safe + QPerson is a class that is generated (via + the Java annotation post processing tool) which is a + Predicate that allows you to write type safe queries. Notice that there are no strings in the query other than the value "C0123". - The use of the generated Predicate class is made available via the - interface QueryDslPredicateExecutor which is shown below + You can use the generated Predicate class + via the interface + QueryDslPredicateExecutor which is shown + below public interface QueryDslPredicateExecutor<T> { @@ -366,13 +376,17 @@ Page<Person> page = repository.findAll(person.lastname.contains("a"), To use this in your repository implementation, simply inherit from - it as well. This is shown below + it in additiion to other repository interfaces. This is shown + below public interface PersonRepository extends MongoRepository<Person, String>, QueryDslPredicateExecutor<Person> { // additional finder methods go here } + + We think you will find this an extremely powerful tool for writing + MongoDB queries.