Class InitializingEntityEvolver<I,E>
java.lang.Object
org.axonframework.eventsourcing.handler.InitializingEntityEvolver<I,E>
- Type Parameters:
I- the type of the identifier of the entity to createE- the type of the entity to create
Combines an
EventSourcedEntityFactory and an EntityEvolver
to ensure an entity exists and apply state transitions.
If the given entity is null, a new instance is created using the
factory. The resulting entity is then passed to the evolver to apply the
given event (if any).
This effectively provides "initialize or evolve" semantics.
- Since:
- 5.1.0
- Author:
- John Hendrikx
-
Constructor Summary
ConstructorsConstructorDescriptionInitializingEntityEvolver(EventSourcedEntityFactory<I, E> entityFactory, EntityEvolver<E> entityEvolver) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionevolve(I identifier, @Nullable E entity, EventMessage message, ProcessingContext context) Initializes or evolves the given entity using the given message.initialize(I identifier, ProcessingContext context) Creates an empty entityE.
-
Constructor Details
-
InitializingEntityEvolver
public InitializingEntityEvolver(EventSourcedEntityFactory<I, E> entityFactory, EntityEvolver<E> entityEvolver) Creates a new instance.- Parameters:
entityFactory- anEventSourcedEntityFactory, cannot benullentityEvolver- anEntityEvolver, cannot benull
-
-
Method Details
-
initialize
Creates an empty entityE.- Parameters:
identifier- the entity's identifier, cannot benullcontext- aProcessingContext, cannot benull- Returns:
- a new entity of type
E
-
evolve
Initializes or evolves the given entity using the given message. If the entity isnull, creates the entity using the given message, otherwise evolves it.- Parameters:
identifier- the entity's identifier, cannot benullentity- the current state, can benullmessage- an event message to initialize or evolve the entity with, cannot benullcontext- aProcessingContext, cannot benull- Returns:
- an entity in its new state, never
null
-