Skip to content

Commit 0da3401

Browse files
committed
Add documentation for JdbcAggregateTemplate.
Closes #1841 Original pull request #1854
1 parent 7e6f548 commit 0da3401

File tree

3 files changed

+66
-20
lines changed

3 files changed

+66
-20
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== Methods for the Criteria Class
2+
3+
The `Criteria` class provides the following methods, all of which correspond to SQL operators:
4+
5+
* `Criteria` *and* `(String column)`: Adds a chained `Criteria` with the specified `property` to the current `Criteria` and returns the newly created one.
6+
* `Criteria` *or* `(String column)`: Adds a chained `Criteria` with the specified `property` to the current `Criteria` and returns the newly created one.
7+
* `Criteria` *greaterThan* `(Object o)`: Creates a criterion by using the `>` operator.
8+
* `Criteria` *greaterThanOrEquals* `(Object o)`: Creates a criterion by using the `>=` operator.
9+
* `Criteria` *in* `(Object... o)`: Creates a criterion by using the `IN` operator for a varargs argument.
10+
* `Criteria` *in* `(Collection<?> collection)`: Creates a criterion by using the `IN` operator using a collection.
11+
* `Criteria` *is* `(Object o)`: Creates a criterion by using column matching (`property = value`).
12+
* `Criteria` *isNull* `()`: Creates a criterion by using the `IS NULL` operator.
13+
* `Criteria` *isNotNull* `()`: Creates a criterion by using the `IS NOT NULL` operator.
14+
* `Criteria` *lessThan* `(Object o)`: Creates a criterion by using the `<` operator.
15+
* `Criteria` *lessThanOrEquals* `(Object o)`: Creates a criterion by using the `<=` operator.
16+
* `Criteria` *like* `(Object o)`: Creates a criterion by using the `LIKE` operator without escape character processing.
17+
* `Criteria` *not* `(Object o)`: Creates a criterion by using the `!=` operator.
18+
* `Criteria` *notIn* `(Object... o)`: Creates a criterion by using the `NOT IN` operator for a varargs argument.
19+
* `Criteria` *notIn* `(Collection<?> collection)`: Creates a criterion by using the `NOT IN` operator using a collection.

src/main/antora/modules/ROOT/pages/jdbc/entity-persistence.adoc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,52 @@ NOTE: While Single Query Loading can be abbreviated as SQL, but we highly discou
5353

5454
include::partial$id-generation.adoc[]
5555

56+
[[jdbc.template]]
57+
== Template API
58+
59+
As an alternative to repositories Spring Data JDBC offers the javadoc:org.springframework.data.jdbc.core.JdbcAggregateTemplate[] as a more direct means to load and persist entities in a relational database.
60+
To a large extent, repositories use `JdbcAggregateTemplate` to implement their features.
61+
62+
This section highlights only the most interesting parts of the `JdbcAggregateTemplate`.
63+
For a more complete overview, see the JavaDoc of `JdbcAggregateTemplate`.
64+
65+
=== Accessing the JdbcAggregateTemplate
66+
67+
`JdbcAggregateTemplate` is intended to be used as a Spring bean.
68+
If you have set up your application to include Spring Data JDBC, you can configure a dependency on `JdbcAggregateTemplate` in any Spring bean, and the Spring Framework injects a properly configured instance.
69+
70+
This includes fragments you use to implement custom methods for your Spring Data Repositories, letting you to use `JdbcAggregateTemplate` to customize and extend your repositories.
71+
72+
=== Persisting
73+
74+
`JdbcAggregateTemplate offers three types of methods for persisting entities: `save`, `insert`, and `update`.
75+
Each comes in two flavors:
76+
Operating on single aggregates, named exactly as mentioned above, and with an `All` suffix operation on an `Iterable`.
77+
78+
`save` does the same as the method of same name in a repository.
79+
80+
`insert` and `update` skip the test if the entity is new and assume a new or existing aggregate as indicated by their name.
81+
82+
=== Querying
83+
84+
`JdbcAggregateTemplate` offers a considerable array of methods for querying aggregates and about collections of aggregates.
85+
There is one type of method that requires special attention.
86+
That's the methods taking a `Query` as an argument.
87+
They allow the execution of programmatically constructed queries, as follows:
88+
89+
[source,java]
90+
----
91+
template.findOne(query(where("name").is("Gandalf")), Person.class);
92+
----
93+
94+
The javadoc:org.springframework.data.relational.core.query.Query[] returned by the `query` method defines the list of columns to select, a where clause (through a CriteriaDefinition), and specification of limit and offset clauses.
95+
For details of the `Query` class, see its JavaDoc.
96+
97+
The javadoc:org.springframework.data.relational.core.query.Criteria[] class, of which `where` is a static member, provides implementations of org.springframework.data.relational.core.query.CriteriaDefinition[], which represent the where-clause of the query.
98+
99+
[[jdbc.criteria]]
100+
include::../commons/criteria-methods.adoc[]
101+
56102
[[jdbc.entity-persistence.optimistic-locking]]
57103
== Optimistic Locking
58104

src/main/antora/modules/ROOT/pages/r2dbc/entity-persistence.adoc

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,7 @@ The fluent API style let you chain together multiple methods while having easy-t
103103
To improve readability, you can use static imports that let you avoid using the 'new' keyword for creating `Criteria` instances.
104104

105105
[[r2dbc.datbaseclient.fluent-api.criteria]]
106-
=== Methods for the Criteria Class
107-
108-
The `Criteria` class provides the following methods, all of which correspond to SQL operators:
109-
110-
* `Criteria` *and* `(String column)`: Adds a chained `Criteria` with the specified `property` to the current `Criteria` and returns the newly created one.
111-
* `Criteria` *or* `(String column)`: Adds a chained `Criteria` with the specified `property` to the current `Criteria` and returns the newly created one.
112-
* `Criteria` *greaterThan* `(Object o)`: Creates a criterion by using the `>` operator.
113-
* `Criteria` *greaterThanOrEquals* `(Object o)`: Creates a criterion by using the `>=` operator.
114-
* `Criteria` *in* `(Object... o)`: Creates a criterion by using the `IN` operator for a varargs argument.
115-
* `Criteria` *in* `(Collection<?> collection)`: Creates a criterion by using the `IN` operator using a collection.
116-
* `Criteria` *is* `(Object o)`: Creates a criterion by using column matching (`property = value`).
117-
* `Criteria` *isNull* `()`: Creates a criterion by using the `IS NULL` operator.
118-
* `Criteria` *isNotNull* `()`: Creates a criterion by using the `IS NOT NULL` operator.
119-
* `Criteria` *lessThan* `(Object o)`: Creates a criterion by using the `<` operator.
120-
* `Criteria` *lessThanOrEquals* `(Object o)`: Creates a criterion by using the `<=` operator.
121-
* `Criteria` *like* `(Object o)`: Creates a criterion by using the `LIKE` operator without escape character processing.
122-
* `Criteria` *not* `(Object o)`: Creates a criterion by using the `!=` operator.
123-
* `Criteria` *notIn* `(Object... o)`: Creates a criterion by using the `NOT IN` operator for a varargs argument.
124-
* `Criteria` *notIn* `(Collection<?> collection)`: Creates a criterion by using the `NOT IN` operator using a collection.
125-
106+
include::../commons/criteria-methods.adoc[]
126107
You can use `Criteria` with `SELECT`, `UPDATE`, and `DELETE` queries.
127108

128109
[[r2dbc.entityoperations.fluent-api.insert]]

0 commit comments

Comments
 (0)