Class AbstractEntityChildMetamodel<C,P>
- Type Parameters:
C- the type of the child entityP- the type of the parent entity
- All Implemented Interfaces:
EntityChildMetamodel<C,,P> EntityEvolver<P>
- Direct Known Subclasses:
ListEntityChildMetamodel,MapEntityChildMetamodel,SingleEntityChildMetamodel
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CommandTargetResolver<C> protected final EventTargetMatcher<C> protected final EntityMetamodel<C> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractEntityChildMetamodel(EntityMetamodel<C> metamodel, CommandTargetResolver<C> commandTargetResolver, EventTargetMatcher<C> eventTargetMatcher) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract PapplyEvolvedChildEntities(P entity, Map<Object, C> evolvedChildEntities) Applies the evolved child entities, keyed by the same implementation-specific identity returned bygetChildEntities(Object), to the givenentity.booleancanHandle(CommandMessage message, P parentEntity, ProcessingContext context) Checks if this child can handle the givenCommandMessagefor the given parent entity, and a child entity is available to handle it.Returns theClassof the child entity this metamodel describes.evolve(P entity, EventMessage event, ProcessingContext context) Evolve the givenentityby applying the giveneventto it.getChildEntities(P parent) Resolves the child entities of the givenparent, keyed by an implementation-specific identity.handle(CommandMessage message, P parentEntity, ProcessingContext context) Handles the givenCommandMessagefor the given child entity, using the provided parent entity.Returns the set of allQualifiedNamesthat this metamodel supports for command handlers.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.modelling.entity.child.EntityChildMetamodel
entityMetamodel
-
Field Details
-
metamodel
-
commandTargetResolver
-
eventTargetMatcher
-
-
Constructor Details
-
AbstractEntityChildMetamodel
protected AbstractEntityChildMetamodel(EntityMetamodel<C> metamodel, CommandTargetResolver<C> commandTargetResolver, EventTargetMatcher<C> eventTargetMatcher)
-
-
Method Details
-
supportedCommands
Description copied from interface:EntityChildMetamodelReturns the set of allQualifiedNamesthat this metamodel supports for command handlers.- Specified by:
supportedCommandsin interfaceEntityChildMetamodel<C,P> - Returns:
- a set of
QualifiedNameinstances representing the supported command names
-
canHandle
Description copied from interface:EntityChildMetamodelChecks if this child can handle the givenCommandMessagefor the given parent entity, and a child entity is available to handle it.- Specified by:
canHandlein interfaceEntityChildMetamodel<C,P> - Parameters:
message- theCommandMessageto checkparentEntity- the parent entity instance to check againstcontext- theProcessingContextfor the command- Returns:
trueif this child can handle the command,falseotherwise
-
handle
public MessageStream.Single<CommandResultMessage> handle(CommandMessage message, P parentEntity, ProcessingContext context) Description copied from interface:EntityChildMetamodelHandles the givenCommandMessagefor the given child entity, using the provided parent entity.- Specified by:
handlein interfaceEntityChildMetamodel<C,P> - Parameters:
message- theCommandMessageto handleparentEntity- the child entity instance to handle the command forcontext- theProcessingContextfor the command- Returns:
- the result of the command handling, which may be a
CommandResultMessageor an error message
-
evolve
Description copied from interface:EntityEvolverEvolve the givenentityby applying the giveneventto it.- Specified by:
evolvein interfaceEntityEvolver<C>- Parameters:
entity- The current entity to evolve with the givenevent.event- The event that might adjust theentity.context- The context within which to evolve theentityby the givenevent.- Returns:
- The evolved
entitybased on the givenevent, or the sameentitywhen nothing happened.
-
getChildEntities
Resolves the child entities of the givenparent, keyed by an implementation-specific identity.The returned immutable
Mapmust preserve iteration order (e.g.LinkedHashMap), as that order determines the order in which candidates are offered to theCommandTargetResolverandEventTargetMatcher.- 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
Applies the evolved child entities, keyed by the same implementation-specific identity returned bygetChildEntities(Object), to the givenentity. A key that was present ingetChildEntities(Object)but is absent fromevolvedChildEntitiesindicates that the corresponding child entity was evolved tonulland should be removed.- Parameters:
entity- the parent entity to apply the evolved child entities toevolvedChildEntities- the evolved child entities, keyed by the same identity asgetChildEntities(Object)- Returns:
- the evolved parent entity
-
entityType
Description copied from interface:EntityChildMetamodelReturns theClassof the child entity this metamodel describes.- Specified by:
entityTypein interfaceEntityChildMetamodel<C,P> - Returns:
- the
Classof the child entity this metamodel describes
-