Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for JdbcAggregateTemplate. #1854

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1841-doc-template-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1841-doc-template-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1841-doc-template-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1841-doc-template-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-r2dbc</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1841-doc-template-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1841-doc-template-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-relational/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-relational</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1841-doc-template-SNAPSHOT</version>

<name>Spring Data Relational</name>
<description>Spring Data Relational support</description>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1841-doc-template-SNAPSHOT</version>
</parent>

<properties>
Expand Down
1 change: 1 addition & 0 deletions src/main/antora/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
** xref:jdbc/entity-persistence.adoc[]
** xref:jdbc/mapping.adoc[]
** xref:jdbc/query-methods.adoc[]
** xref:jdbc/template.adoc[]
** xref:jdbc/mybatis.adoc[]
** xref:jdbc/events.adoc[]
** xref:jdbc/auditing.adoc[]
Expand Down
19 changes: 19 additions & 0 deletions src/main/antora/modules/ROOT/pages/commons/criteria-methods.adoc
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.
48 changes: 48 additions & 0 deletions src/main/antora/modules/ROOT/pages/jdbc/template.adoc
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page adds another variant of documenting Template API's.

I strongly suggest aligning with https://docs.spring.io/spring-data/relational/reference/r2dbc/entity-persistence.html to not introduce yet another variant of Template documentation.

Overall, entity-persistence.html would be a good place to explain the Template API as it fits pretty well in there surrounded by Optimistic Locking and ID generation.

Furthermore, the documentation misses update and delete method documentation.

Repositories use to a large extend the `JdbcAggregateTemplate` to implement their features.
schauder marked this conversation as resolved.
Show resolved Hide resolved

This section will highlight only the most interesting parts of the `JdbcAggregateTemplate`.
schauder marked this conversation as resolved.
Show resolved Hide resolved
For a more complete overview see the JavaDoc of `JdbcAggregateTemplate`.
schauder marked this conversation as resolved.
Show resolved Hide resolved

== Accessing the JdbcAggregateTemplate

`JdbcAggregateTemplate` is intended to be used as Spring bean.
schauder marked this conversation as resolved.
Show resolved Hide resolved
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.
schauder marked this conversation as resolved.
Show resolved Hide resolved

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change allowing you to to letting you


== 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`.

schauder marked this conversation as resolved.
Show resolved Hide resolved
`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.
schauder marked this conversation as resolved.
Show resolved Hide resolved

[source,java]
----
CriteriaDefinition criteria = CriteriaDefinition.from(Criteria.where("name").is("Gandalf"));
Query query = Query.query(criteria);
Optional<SimpleListParent> reloadedById = template.findOne(query, Person.class);
schauder marked this conversation as resolved.
Show resolved Hide resolved
----

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.
schauder marked this conversation as resolved.
Show resolved Hide resolved
For details of the `Query` class see its JavaDoc.
schauder marked this conversation as resolved.
Show resolved Hide resolved

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.
schauder marked this conversation as resolved.
Show resolved Hide resolved

[[jdbc.criteria]]
include::../commons/criteria-methods.adoc[]

21 changes: 1 addition & 20 deletions src/main/antora/modules/ROOT/pages/r2dbc/entity-persistence.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,7 @@ The fluent API style let you chain together multiple methods while having easy-t
To improve readability, you can use static imports that let you avoid using the 'new' keyword for creating `Criteria` instances.

[[r2dbc.datbaseclient.fluent-api.criteria]]
=== 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.

include::../commons/criteria-methods.adoc[]
You can use `Criteria` with `SELECT`, `UPDATE`, and `DELETE` queries.

[[r2dbc.entityoperations.fluent-api.insert]]
Expand Down
Loading