Interface BeforeSaveCallback<T>
- All Superinterfaces:
EntityCallback<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
An
EntityCallback
that gets invoked before changes are applied to the database, after the aggregate was
converted to a database change.
The persisting process works as follows:
- A decision is made, if the aggregate is new and therefore should be inserted or if it is not new and therefore should be updated.
BeforeConvertCallback
andBeforeConvertEvent
get published.- An
AggregateChange
object is created for the aggregate. It includes theDbAction
instances to be executed. This means that all the deletes, updates and inserts to be performed are determined. These actions reference entities of the aggregates in order to access values to be used in the SQL statements. This step also determines if the id of an entity gets passed to the database or if the database is expected to generate that id. BeforeSaveCallback
andBeforeSaveEvent
get published.- SQL statements get applied to the database.
AfterSaveCallback
andAfterSaveEvent
get published.
- Since:
- 1.1
- Author:
- Jens Schauder, Mark Paluch
-
Method Summary
Modifier and TypeMethodDescriptiononBeforeSave
(T aggregate, MutableAggregateChange<T> aggregateChange) Entity callback method invoked before an aggregate root is saved.
-
Method Details
-
onBeforeSave
Entity callback method invoked before an aggregate root is saved. Can return either the same or a modified instance of the aggregate and can modifyMutableAggregateChange
contents. This method is called after converting theaggregate
toMutableAggregateChange
. Changes to the aggregate are not taken into account to decide whether the change will be an insert or update. Use theBeforeConvertCallback
to change the persistent the entity before being converted.- Parameters:
aggregate
- the aggregate.aggregateChange
- the associatedMutableAggregateChange
.- Returns:
- the aggregate object to be persisted.
-