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 create
E - the type of the entity to create

@Internal public class InitializingEntityEvolver<I,E> extends Object
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 Details

  • Method Details

    • initialize

      public E initialize(I identifier, ProcessingContext context)
      Creates an empty entity E.
      Parameters:
      identifier - the entity's identifier, cannot be null
      context - a ProcessingContext, cannot be null
      Returns:
      a new entity of type E
    • evolve

      public E evolve(I identifier, @Nullable E entity, EventMessage message, ProcessingContext context)
      Initializes or evolves the given entity using the given message. If the entity is null, creates the entity using the given message, otherwise evolves it.
      Parameters:
      identifier - the entity's identifier, cannot be null
      entity - the current state, can be null
      message - an event message to initialize or evolve the entity with, cannot be null
      context - a ProcessingContext, cannot be null
      Returns:
      an entity in its new state, never null