Class AbstractEntityChildMetamodel<C,P>

java.lang.Object
org.axonframework.modelling.entity.child.AbstractEntityChildMetamodel<C,P>
Type Parameters:
C - the type of the child entity
P - the type of the parent entity
All Implemented Interfaces:
EntityChildMetamodel<C,P>, EntityEvolver<P>
Direct Known Subclasses:
ListEntityChildMetamodel, MapEntityChildMetamodel, SingleEntityChildMetamodel

@Internal public abstract class AbstractEntityChildMetamodel<C,P> extends Object implements EntityChildMetamodel<C,P>
Abstract EntityChildMetamodel that implements common functionality for most implementations.

It defines how to handle commands and events for a child entity. The implementor is responsible for defining how to resolve the child entities from the parent, keyed by an implementation-specific identity (getChildEntities(Object)), and how to apply the evolved child entities to the parent (applyEvolvedChildEntities(Object, Map)).

The keys returned by getChildEntities(Object) are opaque to this class; they only exist so that evolve(Object, EventMessage, ProcessingContext) can preserve the association between a child entity and its identity when a child is evolved or removed, regardless of whether the parent stores its children in a List (keyed by index), as a single field (keyed by a constant), or in a Map (keyed by the map's own keys).

Since:
5.0.0
Author:
Mitchell Herrijgers, Steven van Beelen
  • Field Details

  • Constructor Details

  • Method Details

    • supportedCommands

      public Set<QualifiedName> supportedCommands()
      Description copied from interface: EntityChildMetamodel
      Returns the set of all QualifiedNames that this metamodel supports for command handlers.
      Specified by:
      supportedCommands in interface EntityChildMetamodel<C,P>
      Returns:
      a set of QualifiedName instances representing the supported command names
    • canHandle

      public boolean canHandle(CommandMessage message, P parentEntity, ProcessingContext context)
      Description copied from interface: EntityChildMetamodel
      Checks if this child can handle the given CommandMessage for the given parent entity, and a child entity is available to handle it.
      Specified by:
      canHandle in interface EntityChildMetamodel<C,P>
      Parameters:
      message - the CommandMessage to check
      parentEntity - the parent entity instance to check against
      context - the ProcessingContext for the command
      Returns:
      true if this child can handle the command, false otherwise
    • handle

      public MessageStream.Single<CommandResultMessage> handle(CommandMessage message, P parentEntity, ProcessingContext context)
      Description copied from interface: EntityChildMetamodel
      Handles the given CommandMessage for the given child entity, using the provided parent entity.
      Specified by:
      handle in interface EntityChildMetamodel<C,P>
      Parameters:
      message - the CommandMessage to handle
      parentEntity - the child entity instance to handle the command for
      context - the ProcessingContext for the command
      Returns:
      the result of the command handling, which may be a CommandResultMessage or an error message
    • evolve

      public P evolve(P entity, EventMessage event, ProcessingContext context)
      Description copied from interface: EntityEvolver
      Evolve the given entity by applying the given event to it.
      Specified by:
      evolve in interface EntityEvolver<C>
      Parameters:
      entity - The current entity to evolve with the given event.
      event - The event that might adjust the entity.
      context - The context within which to evolve the entity by the given event.
      Returns:
      The evolved entity based on the given event, or the same entity when nothing happened.
    • getChildEntities

      protected abstract Map<Object,C> getChildEntities(P parent)
      Resolves the child entities of the given parent, keyed by an implementation-specific identity.

      The returned immutable Map must preserve iteration order (e.g. LinkedHashMap), as that order determines the order in which candidates are offered to the CommandTargetResolver and EventTargetMatcher.

      Parameters:
      parent - the parent entity to resolve the child entities from
      Returns:
      the child entities of the given parent, keyed by an implementation-specific identity
    • applyEvolvedChildEntities

      protected abstract P applyEvolvedChildEntities(P entity, Map<Object,C> evolvedChildEntities)
      Applies the evolved child entities, keyed by the same implementation-specific identity returned by getChildEntities(Object), to the given entity. A key that was present in getChildEntities(Object) but is absent from evolvedChildEntities indicates that the corresponding child entity was evolved to null and should be removed.
      Parameters:
      entity - the parent entity to apply the evolved child entities to
      evolvedChildEntities - the evolved child entities, keyed by the same identity as getChildEntities(Object)
      Returns:
      the evolved parent entity
    • entityType

      public Class<C> entityType()
      Description copied from interface: EntityChildMetamodel
      Returns the Class of the child entity this metamodel describes.
      Specified by:
      entityType in interface EntityChildMetamodel<C,P>
      Returns:
      the Class of the child entity this metamodel describes