You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/main/antora/modules/ROOT/pages/mongodb/repositories/repositories.adoc
-226
Original file line number
Diff line number
Diff line change
@@ -211,229 +211,3 @@ class PersonRepositoryTests {
211
211
The preceding example creates an application context with Spring's unit test support, which performs annotation-based dependency injection into test cases.
212
212
Inside the test method, we use the repository to query the datastore.
213
213
We hand the repository a `PageRequest` instance that requests the first page of `Person` objects at a page size of 10.
214
-
215
-
[[mongodb.repositories.queries.type-safe]]
216
-
== Type-safe Query Methods with Querydsl
217
-
218
-
MongoDB repository and its reactive counterpart integrates with the http://www.querydsl.com/[Querydsl] project, which provides a way to perform type-safe queries.
219
-
220
-
[quote, Querydsl Team]
221
-
Instead of writing queries as inline strings or externalizing them into XML files they are constructed via a fluent API.
222
-
223
-
It provides the following features:
224
-
225
-
* Code completion in the IDE (all properties, methods, and operations can be expanded in your favorite Java IDE).
226
-
* Almost no syntactically invalid queries allowed (type-safe on all levels).
227
-
* Domain types and properties can be referenced safely -- no strings involved!
228
-
* Adapts better to refactoring changes in domain types.
229
-
* Incremental query definition is easier.
230
-
231
-
See the http://www.querydsl.com/static/querydsl/latest/reference/html/[QueryDSL documentation] for how to bootstrap your environment for APT-based code generation using Maven or Ant.
232
-
233
-
QueryDSL lets you write queries such as the following:
Flux<Person> result = repository.findAll(person.address.zipCode.eq("C0123"));
255
-
----
256
-
======
257
-
258
-
`QPerson` is a class that is generated by the Java annotation processor.
259
-
See xref:#mongodb.repositories.queries.type-safe.apt[Setting up Annotation Processing] for how to setup Annotation Processing with your Build System.
260
-
It is a `Predicate` that lets you write type-safe queries.
261
-
Notice that there are no strings in the query other than the `C0123` value.
262
-
263
-
You can use the generated `Predicate` class by using the `QuerydslPredicateExecutor` / `ReactiveQuerydslPredicateExecutor` interface, which the following listing shows:
To use this in your repository implementation, add it to the list of repository interfaces from which your interface inherits, as the following example shows:
NOTE: Please note that joins (DBRef's) are not supported with Reactive MongoDB support.
346
-
====
347
-
======
348
-
349
-
[[mongodb.repositories.queries.type-safe.apt]]
350
-
=== Setting up Annotation Processing
351
-
352
-
To use Querydsl with Spring Data MongoDB, you need to set up annotation processing in your build system that generates the `Q` classes.
353
-
While you could write the `Q` classes by hand, it is recommended to use the Querydsl annotation processor to generate them for you to keep your `Q` classes in sync with your domain model.
354
-
355
-
Spring Data MongoDB ships with an annotation processor javadoc:org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor[] that isn't registered by default.
356
-
Typically, annotation processors are registered through Java's service loader via `META-INF/services/javax.annotation.processing.Processor` that also activates these once you have them on the class path.
357
-
Most Spring Data users do not use Querydsl, so it does not make sense to require additional mandatory dependencies for projects that would not benefit from Querydsl.
358
-
Hence, you need to activate annotation processing in your build system.
359
-
360
-
The following example shows how to set up annotation processing by mentioning dependencies and compiler config changes in Maven and Gradle:
0 commit comments