An `EntityCallback` works very similar to an `ApplicationEvent` but returns a potentially changed instance.
The returned instance will be used in further processing which enables proper event handling for immutable classes.
Auditing was changed to use a callback making it work also with immutable objects.
Original pull request: #161.
@ -62,6 +62,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -62,6 +62,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@ -90,6 +92,13 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -90,6 +92,13 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@ -100,11 +109,11 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -100,11 +109,11 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
Assert.notNull(instance,"Aggregate instance must not be null!");
@ -120,11 +129,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -120,11 +129,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
Assert.notNull(instance,"Aggregate instance must not be null!");
@ -140,11 +146,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -140,11 +146,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
Assert.notNull(instance,"Aggregate instance must not be null!");
@ -171,7 +174,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -171,7 +174,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
Tentity=accessStrategy.findById(id,domainType);
if(entity!=null){
publishAfterLoad(id,entity);
returntriggerAfterLoad(id,entity);
}
returnentity;
}
@ -199,8 +202,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -199,8 +202,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
Assert.notNull(domainType,"Domain type must not be null!");
@ -214,8 +216,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -214,8 +216,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
Assert.notNull(domainType,"Domain type must not be null!");
@ -260,16 +261,20 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -260,16 +261,20 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@ -277,31 +282,26 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -277,31 +282,26 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
Assert.notNull(identifier,"After saving the identifier must not be null!");
@ -324,9 +324,9 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -324,9 +324,9 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@ -338,18 +338,96 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@@ -338,18 +338,96 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
@ -53,6 +54,7 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
@@ -53,6 +54,7 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
@ -117,7 +119,13 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
@@ -117,7 +119,13 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
@ -147,4 +155,9 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
@@ -147,4 +155,9 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
@ -54,6 +55,7 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
@@ -54,6 +55,7 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
@ -85,6 +87,7 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
@@ -85,6 +87,7 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
@ -151,10 +154,16 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
@@ -151,10 +154,16 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
Assert.state(this.converter!=null,"RelationalConverter is required and must not be null!");
if(this.operations==null){
Assert.state(beanFactory!=null,"If no JdbcOperations are set a BeanFactory must be available.");
@ -168,6 +177,10 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
@@ -168,6 +177,10 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
@ -99,10 +104,23 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
@@ -99,10 +104,23 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
@ -118,11 +136,20 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
@@ -118,11 +136,20 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
@ -134,12 +161,19 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
@@ -134,12 +161,19 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
@ -36,7 +36,7 @@ public class AfterDeleteEvent extends RelationalEventWithId {
@@ -36,7 +36,7 @@ public class AfterDeleteEvent extends RelationalEventWithId {
@ -35,7 +35,7 @@ public class BeforeDeleteEvent extends RelationalEventWithId {
@@ -35,7 +35,7 @@ public class BeforeDeleteEvent extends RelationalEventWithId {
@ -32,7 +32,7 @@ public class RelationalEventWithId extends SimpleRelationalEvent implements With
@@ -32,7 +32,7 @@ public class RelationalEventWithId extends SimpleRelationalEvent implements With
@ -563,9 +563,9 @@ Note that the type used for prefixing the statement name is the name of the aggr
@@ -563,9 +563,9 @@ Note that the type used for prefixing the statement name is the name of the aggr
|===
[[jdbc.events]]
== Events
== Events and Callback
Spring Data JDBC triggers events that get published to any matching `ApplicationListener` in the application context.
Spring Data JDBC triggers events that get published to any matching `ApplicationListener` and `EntityCallback` beans in the application context.
For example, the following listener gets invoked before an aggregate gets saved:
====
@ -586,27 +586,34 @@ public ApplicationListener<BeforeSave> timeStampingSaveTime() {
@@ -586,27 +586,34 @@ public ApplicationListener<BeforeSave> timeStampingSaveTime() {
----
====
The following table describes the available events:
The following table describes the available events and callbacks:
| Before an aggregate root gets saved (that is, inserted or updated but after the decision about whether if it gets updated or deleted was made).
The event has a reference to an {javadoc-base}/org/springframework/data/relational/core/conversion/AggregateChange.html[`AggregateChange`] instance.
The instance can be modified by adding or removing {javadoc-base}/org/springframework/data/relational/core/conversion/DbAction.html[`DbAction`] instances.