Skip to content

Commit 569cae2

Browse files
DATACMNS-830 - Add documentation section on Querydsl.
Original Pull Request: #158
1 parent c760465 commit 569cae2

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/main/asciidoc/repositories.adoc

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,58 @@ A corresponding attribute is available in the XML namespace.
741741

742742
This section documents a set of Spring Data extensions that enable Spring Data usage in a variety of contexts. Currently most of the integration is targeted towards Spring MVC.
743743

744+
[[core.extensions.querydsl]]
745+
=== Querydsl Extension
746+
747+
http://www.querydsl.com/[Querydsl] is a framework which enables the construction of statically typed SQL-like queries via its fluent API.
748+
749+
Several Spring Data modules offer integration with Querydsl via `QueryDslPredicateExecutor`.
750+
751+
.QueryDslPredicateExecutor interface
752+
====
753+
[source, java]
754+
----
755+
public interface QueryDslPredicateExecutor<T> {
756+
757+
T findOne(Predicate predicate); <1>
758+
759+
Iterable<T> findAll(Predicate predicate); <2>
760+
761+
long count(Predicate predicate); <3>
762+
763+
boolean exists(Predicate predicate); <4>
764+
765+
// … more functionality omitted.
766+
}
767+
----
768+
<1> Finds and returns a single entity matching the `Predicate`.
769+
<2> Finds and returns all entities matching the `Predicate`.
770+
<3> Returns the number of entities matching the `Predicate`.
771+
<4> Returns if an entity that matches the `Predicate` exists.
772+
====
773+
774+
To make use of Querydsl support simply extend `QueryDslPredicateExecutor` on your repository interface.
775+
776+
.Querydsl integration on repositories
777+
====
778+
[source, java]
779+
----
780+
interface UserRepository extends CrudRepository<User, Long>, QueryDslPredicateExecutor<User> {
781+
782+
}
783+
----
784+
====
785+
786+
The above enables to write typesafe queries using Querydsl `Predicate` s.
787+
788+
[source, java]
789+
----
790+
Predicate predicate = user.firstname.equalsIgnoreCase("dave")
791+
.and(user.lastname.startsWithIgnoreCase("mathews"));
792+
793+
userRepository.findAll(predicate);
794+
----
795+
744796
[[core.web]]
745797
=== Web support
746798

@@ -908,7 +960,7 @@ Assume we have 30 Person instances in the database. You can now trigger a reques
908960
You see that the assembler produced the correct URI and also picks up the default configuration present to resolve the parameters into a `Pageable` for an upcoming request. This means, if you change that configuration, the links will automatically adhere to the change. By default the assembler points to the controller method it was invoked in but that can be customized by handing in a custom `Link` to be used as base to build the pagination links to overloads of the `PagedResourcesAssembler.toResource(…)` method.
909961

910962
[[core.web.type-safe]]
911-
==== QueryDSL web support
963+
==== Querydsl web support
912964

913965
For those stores having http://www.querydsl.com/[QueryDSL] integration it is possible to derive queries from the attributes contained in a `Request` query string.
914966

0 commit comments

Comments
 (0)