-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for JdbcAggregateTemplate.
Closes #1841
- Loading branch information
Showing
4 changed files
with
69 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/antora/modules/ROOT/pages/commons/criteria-methods.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
=== Methods for the Criteria Class | ||
|
||
The `Criteria` class provides the following methods, all of which correspond to SQL operators: | ||
|
||
* `Criteria` *and* `(String column)`: Adds a chained `Criteria` with the specified `property` to the current `Criteria` and returns the newly created one. | ||
* `Criteria` *or* `(String column)`: Adds a chained `Criteria` with the specified `property` to the current `Criteria` and returns the newly created one. | ||
* `Criteria` *greaterThan* `(Object o)`: Creates a criterion by using the `>` operator. | ||
* `Criteria` *greaterThanOrEquals* `(Object o)`: Creates a criterion by using the `>=` operator. | ||
* `Criteria` *in* `(Object... o)`: Creates a criterion by using the `IN` operator for a varargs argument. | ||
* `Criteria` *in* `(Collection<?> collection)`: Creates a criterion by using the `IN` operator using a collection. | ||
* `Criteria` *is* `(Object o)`: Creates a criterion by using column matching (`property = value`). | ||
* `Criteria` *isNull* `()`: Creates a criterion by using the `IS NULL` operator. | ||
* `Criteria` *isNotNull* `()`: Creates a criterion by using the `IS NOT NULL` operator. | ||
* `Criteria` *lessThan* `(Object o)`: Creates a criterion by using the `<` operator. | ||
* `Criteria` *lessThanOrEquals* `(Object o)`: Creates a criterion by using the `<=` operator. | ||
* `Criteria` *like* `(Object o)`: Creates a criterion by using the `LIKE` operator without escape character processing. | ||
* `Criteria` *not* `(Object o)`: Creates a criterion by using the `!=` operator. | ||
* `Criteria` *notIn* `(Object... o)`: Creates a criterion by using the `NOT IN` operator for a varargs argument. | ||
* `Criteria` *notIn* `(Collection<?> collection)`: Creates a criterion by using the `NOT IN` operator using a collection. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[[jdbc.template]] | ||
= Template API | ||
|
||
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. | ||
Repositories use to a large extend the `JdbcAggregateTemplate` to implement their features. | ||
|
||
This section will highlight only the most interesting parts of the `JdbcAggregateTemplate`. | ||
For a more complete overview see the JavaDoc of `JdbcAggregateTemplate`. | ||
|
||
== Accessing the JdbcAggregateTemplate | ||
|
||
`JdbcAggregateTemplate` is intended to be used as Spring bean. | ||
If you have set up your application including Spring Data JDBC you may configure a dependency on `JdbcAggregateTemplate` in any Spring bean and the Spring Framework will inject a properly configured instance. | ||
|
||
This includes fragments you use to implement custom methods for your Spring Data Repositories, allowing you to use `JdbcAggregateTemplate` to customize and extend your repositories. | ||
|
||
== Persisting | ||
|
||
`JdbcAggregateTemplate offers three types of methods for persisting entities: `save`, `insert`, and `update`. | ||
Each comes in two flavors: | ||
Operating on single aggregates, named exactly as mentioned above, and with a `All` suffix operation on an `Iterable`. | ||
|
||
`save` does the same as the method of same name in a repository. | ||
|
||
`insert` and `update` skip the test if the entity is new and assume a new or existing aggregate as indicated by their name. | ||
|
||
== Querying | ||
|
||
`JdbcAggregateTemplate` offers a considerable array of methods for querying aggregates and about collections of aggregates. | ||
There is one type of method that requires special attention. | ||
That's the methods taking a `Query` as an argument. | ||
They allow the execution of programmatically constructed queries as shown in the following example. | ||
|
||
[source,java] | ||
---- | ||
CriteriaDefinition criteria = CriteriaDefinition.from(Criteria.where("name").is("Gandalf")); | ||
Query query = Query.query(criteria); | ||
Optional<SimpleListParent> reloadedById = template.findOne(query, Person.class); | ||
---- | ||
|
||
The javadoc:org.springframework.data.relational.core.query.Query[] defines the list of columns to select, a where-clause through a `CriteriaDefinition` and specification of limit and offset clauses. | ||
For details of the `Query` class see its JavaDoc. | ||
|
||
The javadoc:org.springframework.data.relational.core.query.Criteria[] class provides implementations of org.springframework.data.relational.core.query.CriteriaDefinition[, which represent the where-clause of the query. | ||
|
||
[[jdbc.criteria]] | ||
include::../commons/criteria-methods.adoc[] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters