Skip to content

#215 - Add support for EntityCallbacks #397

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.2.0-gh-215-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand Down
25 changes: 9 additions & 16 deletions src/main/asciidoc/new-features.adoc
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
[[new-features]]
= New & Noteworthy

[[new-features.1-1-0-RELEASE]]
== What's New in Spring Data R2DBC 1.1.0 RELEASE
[[new-features.1-2-0]]
== What's New in Spring Data R2DBC 1.2.0

* Support for <<entity-callbacks>>.

[[new-features.1-1-0]]
== What's New in Spring Data R2DBC 1.1.0

* Introduction of `R2dbcEntityTemplate` for entity-oriented operations.
* <<r2dbc.repositories.queries,Query derivation>>.
* Support interface projections with `DatabaseClient.as(…)`.
* <<r2dbc.datbaseclient.filter,Support for `ExecuteFunction` and `StatementFilterFunction` via `DatabaseClient.filter(…)`>>.

[[new-features.1-0-0-RELEASE]]
== What's New in Spring Data R2DBC 1.0.0 RELEASE
[[new-features.1-0-0]]
== What's New in Spring Data R2DBC 1.0.0

* Upgrade to R2DBC 0.8.0.RELEASE.
* `@Modifying` annotation for query methods to consume affected row count.
* Repository `save(…)` with an associated Id terminates with `TransientDataAccessException` if the row does not exist in the database.
* Added `SingleConnectionConnectionFactory` for testing using connection singletons.
* Support for {spring-framework-ref}/core.html#expressions[SpEL expressions] in `@Query`.

[[new-features.1-0-0-RC1]]
== What's New in Spring Data R2DBC 1.0.0 RC1

* `ConnectionFactory` routing through `AbstractRoutingConnectionFactory`.
* Utilities for schema initialization through `ResourceDatabasePopulator` and `ScriptUtils`.
* Propagation and reset of Auto-Commit and Isolation Level control through `TransactionDefinition`.
* Support for Entity-level converters.
* Kotlin extensions for reified generics and <<kotlin.coroutines,Coroutines>>.
* Add pluggable mechanism to register dialects.

[[new-features.1-0-0-M2]]
== What's New in Spring Data R2DBC 1.0.0 M2

* Support for named parameters.

[[new-features.1-0-0-M1]]
== What's New in Spring Data R2DBC 1.0.0 M1

* Initial R2DBC support through `DatabaseClient`.
* Initial Transaction support through `TransactionalDatabaseClient`.
* Initial R2DBC Repository Support through `R2dbcRepository`.
Expand Down
38 changes: 38 additions & 0 deletions src/main/asciidoc/reference/r2dbc-entity-callbacks.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[[r2dbc.entity-callbacks]]
= Store specific EntityCallbacks

Spring Data R2DBC uses the `EntityCallback` API and reacts on the following callbacks.

.Supported Entity Callbacks
[%header,cols="4"]
|===
| Callback
| Method
| Description
| Order

| BeforeConvertCallback
| `onBeforeConvert(T entity, SqlIdentifier table)`
| Invoked before a domain object is converted to `OutboundRow`.
| `Ordered.LOWEST_PRECEDENCE`

| AfterConvertCallback
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the naming of BeforeConvertCallback and AfterConvertCallback highly confusing.

The names suggests that they happen relative to the same process, one before and one after, while in fact they are completely unrelated.

I think AfterLoadCallback would be a much better name for the AfterConvertCallback.

Copy link
Member Author

Choose a reason for hiding this comment

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

AfterLoad is typically used before converting objects into an entity. We should rather stick to this convention for consistency across our modules.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. I don't think we are doing it this way in Spring Data JDBC.

Copy link
Member Author

Choose a reason for hiding this comment

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

Then we should align JDBC to the other stores so we can later on introduce a AfterLoad event/callback that gives users a chance to react to values before materializing an object.

| `onAfterConvert(T entity, SqlIdentifier table)`
| Invoked after a domain object is loaded. +
Can modify the domain object after reading it from a row.
| `Ordered.LOWEST_PRECEDENCE`

| BeforeSaveCallback
| `onBeforeSave(T entity, OutboundRow row, SqlIdentifier table)`
| Invoked before a domain object is saved. +
Can modify the target, to be persisted, `OutboundRow` containing all mapped entity information.
| `Ordered.LOWEST_PRECEDENCE`

| AfterSaveCallback
| `onAfterSave(T entity, OutboundRow row, SqlIdentifier table)`
| Invoked before a domain object is saved. +
Can modify the domain object, to be returned after save, `OutboundRow` containing all mapped entity information.
| `Ordered.LOWEST_PRECEDENCE`

|===

3 changes: 3 additions & 0 deletions src/main/asciidoc/reference/r2dbc-repositories.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,6 @@ With auto-increment columns, this happens automatically, because the ID gets set
:projection-collection: Flux
include::../{spring-data-commons-docs}/repository-projections.adoc[leveloffset=+2]

include::../{spring-data-commons-docs}/entity-callbacks.adoc[leveloffset=+1]
include::./r2dbc-entity-callbacks.adoc[leveloffset=+2]

Loading