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/asciidoc/repositories.adoc
+26-7Lines changed: 26 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -342,11 +342,13 @@ The following strategies are available for the repository infrastructure to reso
342
342
[[repositories.query-methods.query-creation]]
343
343
=== Query Creation
344
344
345
-
The query builder mechanism built into the Spring Data repository infrastructure is useful for building constraining queries over entities of the repository. The mechanism strips the `find…By`, `read…By`, `query…By`, `count…By`, and `get…By` prefixes 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 `By` acts as a delimiter to indicate the start of the actual criteria. At a very basic level, you can define conditions on entity properties and concatenate them with `And` and `Or`. The following example shows how to create a number of queries:
345
+
The query builder mechanism built into the Spring Data repository infrastructure is useful for building constraining queries over entities of the repository.
346
+
347
+
The following example shows how to create a number of queries:
The actual result of parsing the method depends on the persistence store for which you create the query. However, there are some general things to notice:
373
+
Parsing query method names is divided into subject and predicate.
374
+
The first part (`find…By`, `exists…By`) defines the subject of the query, the second part forms the predicate.
375
+
The introducing clause (subject) can contain further expressions.
376
+
Any text between `find` (or other introducing keywords) and `By` is considered to be descriptive unless using one of the result-limiting keywords such as a `Distinct` to set a distinct flag on the query to be created or <<repositories.limit-query-result,`Top`/`First` to limit query results>>.
377
+
378
+
The appendix contains the <<appendix.query.method.subject,full list of query method subject keywords>> and <<appendix.query.method.predicate,query method predicate keywords including sorting and letter-casing modifiers>>.
379
+
However, the first `By` acts as a delimiter to indicate the start of the actual criteria predicate.
380
+
At a very basic level, you can define conditions on entity properties and concatenate them with `And` and `Or`.
381
+
382
+
The actual result of parsing the method depends on the persistence store for which you create the query.
383
+
However, there are some general things to notice:
372
384
373
-
- The expressions are usually property traversals combined with operators that can be concatenated. You can combine property expressions with `AND` and `OR`. You also get support for operators such as `Between`, `LessThan`, `GreaterThan`, and `Like` for the property expressions. The supported operators can vary by datastore, so consult the appropriate part of your reference documentation.
385
+
- The expressions are usually property traversals combined with operators that can be concatenated.
386
+
You can combine property expressions with `AND` and `OR`.
387
+
You also get support for operators such as `Between`, `LessThan`, `GreaterThan`, and `Like` for the property expressions.
388
+
The supported operators can vary by datastore, so consult the appropriate part of your reference documentation.
374
389
375
-
- The method parser supports setting an `IgnoreCase` flag for individual properties (for example, `findByLastnameIgnoreCase(…)`) or for all properties of a type that supports ignoring case (usually `String` instances -- for example, `findByLastnameAndFirstnameAllIgnoreCase(…)`). Whether ignoring cases is supported may vary by store, so consult the relevant sections in the reference documentation for the store-specific query method.
390
+
- The method parser supports setting an `IgnoreCase` flag for individual properties (for example, `findByLastnameIgnoreCase(…)`) or for all properties of a type that supports ignoring case (usually `String` instances -- for example, `findByLastnameAndFirstnameAllIgnoreCase(…)`).
391
+
Whether ignoring cases is supported may vary by store, so consult the relevant sections in the reference documentation for the store-specific query method.
376
392
377
-
- You can apply static ordering by appending an `OrderBy` clause to the query method that references a property and by providing a sorting direction (`Asc` or `Desc`). To create a query method that supports dynamic sorting, see "`<<repositories.special-parameters>>`".
393
+
- You can apply static ordering by appending an `OrderBy` clause to the query method that references a property and by providing a sorting direction (`Asc` or `Desc`).
394
+
To create a query method that supports dynamic sorting, see "`<<repositories.special-parameters>>`".
The limiting expressions also support the `Distinct` keyword. Also, for the queries that limit the result set to one instance, wrapping the result into with the `Optional` keyword is supported.
516
+
The limiting expressions also support the `Distinct` keyword for datastores that support distinct queries.
517
+
Also, for the queries that limit the result set to one instance, wrapping the result into with the `Optional` keyword is supported.
500
518
501
519
If pagination or slicing is applied to a limiting query pagination (and the calculation of the number of available pages), it is applied within the limited result.
502
520
@@ -507,6 +525,7 @@ NOTE: Limiting the results in combination with dynamic sorting by using a `Sort`
507
525
508
526
Query methods that return multiple results can use standard Java `Iterable`, `List`, and `Set`.
509
527
Beyond that, we support returning Spring Data's `Streamable`, a custom extension of `Iterable`, as well as collection types provided by https://www.vavr.io/[Vavr].
528
+
Refer to the appendix explaining all possible <<appendix.query.return.types,query method return types>>.
Copy file name to clipboardExpand all lines: src/main/asciidoc/repository-query-keywords-reference.adoc
+36-4Lines changed: 36 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,32 @@
2
2
[appendix]
3
3
= Repository query keywords
4
4
5
-
== Supported query keywords
6
-
The following table lists the keywords generally supported by the Spring Data repository query derivation mechanism. However, consult the store-specific documentation for the exact list of supported keywords, because some keywords listed here might not be supported in a particular store.
5
+
[[appendix.query.method.subject]]
6
+
== Supported query method subject keywords
7
7
8
-
.Query keywords
9
-
[options="header", cols="1,3"]
8
+
The following table lists the subject keywords generally supported by the Spring Data repository query derivation mechanism to express the predicate.
9
+
Consult the store-specific documentation for the exact list of supported keywords, because some keywords listed here might not be supported in a particular store.
10
+
11
+
.Query subject keywords
12
+
[options="header",cols="1,3"]
13
+
|===============
14
+
|Keyword | Description
15
+
|`find…By`, `read…By`, `get…By`, `query…By`, `search…By`, `stream…By`| General query method returning typically the repository type, a `Collection` or `Streamable` subtype or a result wrapper such as `Page`, `GeoResults` or any other store-specific result wrapper. Can be used as `findBy…`, `findMyDomainTypeBy…` or in combination with additional keywords.
16
+
|`exists…By`| Exists projection, returning typically a `boolean` result.
17
+
|`count…By`| Count projection returning a numeric result.
18
+
|`delete…By`, `remove…By`| Delete query method returning either no result (`void`) or the delete count.
19
+
|`…First<number>…`, `…Top<number>…`| Limit the query results to the first `<number>` of results. This keyword can occur in any place of the subject between `find` (and the other keywords) and `by`.
20
+
|`…Distinct…`| Use a distinct query to return only unique results. Consult the store-specific documentation whether that feature is supported. This keyword can occur in any place of the subject between `find` (and the other keywords) and `by`.
21
+
|===============
22
+
23
+
[[appendix.query.method.predicate]]
24
+
== Supported query method predicate keywords and modifiers
25
+
26
+
The following table lists the predicate keywords generally supported by the Spring Data repository query derivation mechanism.
27
+
However, consult the store-specific documentation for the exact list of supported keywords, because some keywords listed here might not be supported in a particular store.
28
+
29
+
.Query predicate keywords
30
+
[options="header",cols="1,3"]
10
31
|===============
11
32
|Logical keyword|Keyword expressions
12
33
|`AND`|`And`
@@ -38,3 +59,14 @@ The following table lists the keywords generally supported by the Spring Data re
38
59
|`TRUE`|`True`, `IsTrue`
39
60
|`WITHIN`|`Within`, `IsWithin`
40
61
|===============
62
+
63
+
In addition to filter predicates, the following list of modifiers is supported:
64
+
65
+
.Query predicate modifier keywords
66
+
[options="header",cols="1,3"]
67
+
|===============
68
+
|Keyword | Description
69
+
|`IgnoreCase`, `IgnoringCase`| Used with a predicate keyword for case-insensitive comparison.
70
+
|`AllIgnoreCase`, `AllIgnoringCase`| Ignore case for all suitable properties. Used somewhere in the query method predicate.
71
+
|`OrderBy…`| Specify a static sorting order followed by the property path and direction (e. g. `OrderByFirstnameAscLastnameDesc`).
Copy file name to clipboardExpand all lines: src/main/asciidoc/repository-query-return-types-reference.adoc
+7-3Lines changed: 7 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,17 @@
2
2
[[repository-query-return-types]]
3
3
= Repository query return types
4
4
5
+
[[appendix.query.return.types]]
5
6
== Supported Query Return Types
6
-
The following table lists the return types generally supported by Spring Data repositories. However, consult the store-specific documentation for the exact list of supported return types, because some types listed here might not be supported in a particular store.
7
+
8
+
The following table lists the return types generally supported by Spring Data repositories.
9
+
However, consult the store-specific documentation for the exact list of supported return types, because some types listed here might not be supported in a particular store.
7
10
8
11
NOTE: Geospatial types (such as `GeoResult`, `GeoResults`, and `GeoPage`) are available only for data stores that support geospatial queries.
12
+
Some store modules may define their own result wrapper types.
9
13
10
14
.Query return types
11
-
[options="header",cols="1,3"]
15
+
[options="header",cols="1,3"]
12
16
|===============
13
17
|Return type|Description
14
18
|`void`|Denotes no return value.
@@ -27,7 +31,7 @@ NOTE: Geospatial types (such as `GeoResult`, `GeoResults`, and `GeoPage`) are av
27
31
|`Future<T>`|A `Future`. Expects a method to be annotated with `@Async` and requires Spring's asynchronous method execution capability to be enabled.
28
32
|`CompletableFuture<T>`|A Java 8 `CompletableFuture`. Expects a method to be annotated with `@Async` and requires Spring's asynchronous method execution capability to be enabled.
29
33
|`ListenableFuture`|A `org.springframework.util.concurrent.ListenableFuture`. Expects a method to be annotated with `@Async` and requires Spring's asynchronous method execution capability to be enabled.
30
-
|`Slice`|A sized chunk of data with an indication of whether there is more data available. Requires a `Pageable` method parameter.
34
+
|`Slice<T>`|A sized chunk of data with an indication of whether there is more data available. Requires a `Pageable` method parameter.
31
35
|`Page<T>`|A `Slice` with additional information, such as the total number of results. Requires a `Pageable` method parameter.
32
36
|`GeoResult<T>`|A result entry with additional information, such as the distance to a reference location.
33
37
|`GeoResults<T>`|A list of `GeoResult<T>` with additional information, such as the average distance to a reference location.
0 commit comments