spring-projects / spring-projects/spring-data-relational
Use event interface in entity class
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 827
- Forks
- 394
- PR merge metrics
- No merged PRs in 30d
Description
The current event model requests the creation of a bean component to implement the child AbstractRelationalEvent (AfterSaveEvent / BeforeConvertEvent / ...)
If the event logic is strongly related to the entity, then now you have to divide them into classes, perhaps make some private attributes public.
You can add processing logic if the entity itself implements these interfaces. Do not publish the event (or with publish), but call the method on the entity
If the event model will check the implementation of the interface and call it instead of or together with sending the event, then it will be possible to combine the entity and its reaction to events in one class
for example something like this:
package org.springframework.data.jdbc.core;
...
public class JdbcAggregateTemplate implements JdbcAggregateOperations {
...
private <T> T triggerBeforeConvert(T aggregateRoot) {
if (aggregateRoot instanceof BeforeConvertCallback) {
return ((BeforeConvertCallback<T>) aggregateRoot).onBeforeConvert(aggregateRoot);
}
eventDelegate.publishEvent(() -> new BeforeConvertEvent<>(aggregateRoot));
return entityCallbacks.callback(BeforeConvertCallback.class, aggregateRoot);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with JdbcAggregateTemplate and the BeforeConvertEvent, AfterSaveEvent, and related callback interfaces named in the issue. Trace how eventDelegate and entityCallbacks currently process an aggregate, then determine the expected behavior when the entity implements an event interface. Done should be defined by tests showing entity-provided event handling works without requiring a separate bean component.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100