Interface PolymorphicEntityMetamodelBuilder<E>
- Type Parameters:
E- The type of the polymorphic entity this metamodel represents.
- All Superinterfaces:
EntityMetamodelBuilder<E>
EntityMetamodel, where a parent entity can have multiple concrete child
entities. Command handlers of concrete types take precedence over the parent entity's command handlers. Event
handlers are invoked on both, with the super entity's event handlers being invoked first.- Since:
- 5.0.0
- Author:
- Mitchell Herrijgers
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddChild(EntityChildMetamodel<?, E> child) Adds aEntityChildMetamodelto this metamodel.addConcreteType(EntityMetamodel<? extends E> metamodel) Adds a concrete type to this metamodel.creationalCommandHandler(QualifiedName qualifiedName, CommandHandler messageHandler) Adds aCommandHandlerto this metamodel for the givenQualifiedNamethat is in charge of creation of the entity.entityEvolver(EntityEvolver<E> entityEvolver) Adds aEntityEvolverto this metamodel.instanceCommandHandler(QualifiedName qualifiedName, EntityCommandHandler<E> messageHandler) Adds anEntityCommandHandlerto this metamodel for the givenQualifiedName.Methods inherited from interface org.axonframework.modelling.entity.EntityMetamodelBuilder
build
-
Method Details
-
instanceCommandHandler
@Nonnull PolymorphicEntityMetamodelBuilder<E> instanceCommandHandler(@Nonnull QualifiedName qualifiedName, @Nonnull EntityCommandHandler<E> messageHandler) Description copied from interface:EntityMetamodelBuilderAdds anEntityCommandHandlerto this metamodel for the givenQualifiedName. The command handler will be invoked when a command with the givenQualifiedNameis received by the metamodel.The entity should not exist for this command handler to be invoked. A non-null initial state is considered to be an existing entity. As such, only register this command if the
Repository.loadOrCreate(Object, ProcessingContext)will always return a non-null entity for the givenqualifiedNamewhen the entity is not yet created.You can register the same
QualifiedNamefor both instance and creational command handlers. See theEntityMetamodelBuilderclass documentation for more information on how this works.- Specified by:
instanceCommandHandlerin interfaceEntityMetamodelBuilder<E>- Parameters:
qualifiedName- TheQualifiedNameof the command this handler handles.messageHandler- TheEntityCommandHandlerto handle the command.- Returns:
- This builder for further configuration.
-
creationalCommandHandler
@Nonnull PolymorphicEntityMetamodelBuilder<E> creationalCommandHandler(@Nonnull QualifiedName qualifiedName, @Nonnull CommandHandler messageHandler) Description copied from interface:EntityMetamodelBuilderAdds aCommandHandlerto this metamodel for the givenQualifiedNamethat is in charge of creation of the entity. The handler is expected to create the entity.The entity needs to not exist for this command handler to be invoked. A null initial state is considered to be a non-existing entity. As such, only register this command if the
Repository.load(Object, ProcessingContext)will always return a null entity for the givenqualifiedNamewhen the entity is not yet created.You can register the same
QualifiedNamefor both instance and creational command handlers. See theEntityMetamodelBuilderclass documentation for more information on how this works.Note: If this metamodel is added as a child to another entity metamodel and has a creational command handler, it will result in an exception as child entities cannot be created through a creational command handler.
- Specified by:
creationalCommandHandlerin interfaceEntityMetamodelBuilder<E>- Parameters:
qualifiedName- TheQualifiedNameof the command this handler handles.messageHandler- TheCommandHandlerto handle the command.- Returns:
- This builder for further configuration.
-
addChild
Description copied from interface:EntityMetamodelBuilderAdds aEntityChildMetamodelto this metamodel. The child metamodel will be used to handle commands for the child entity. You can build a tree of entities by adding child metamodels to the parent metamodel. Children command handlers take precedence over the parent command handlers. Event handlers will be invoked on both the parent and child metamodels, but the child metamodels will be invoked first.There are various types of children that can be added to an entity metamodel:
- Single instances: For a field with a single instance, use the
EntityChildMetamodel.single(Class, EntityMetamodel). - List instances: For a
list, use theEntityChildMetamodel.list(Class, EntityMetamodel).
When multiple children that can handle the same command are present, the children will be filtered based on
EntityChildMetamodel.canHandle(CommandMessage, Object, ProcessingContext), and thus only invoke the child with a matching entity. If no child can handle the command, an exception will be thrown. If after filtering, multiple children can handle the command, an exception will be thrown.- Specified by:
addChildin interfaceEntityMetamodelBuilder<E>- Parameters:
child- TheEntityChildMetamodelto add.- Returns:
- This builder for further configuration.
- Single instances: For a field with a single instance, use the
-
entityEvolver
@Nonnull PolymorphicEntityMetamodelBuilder<E> entityEvolver(@Nullable EntityEvolver<E> entityEvolver) Description copied from interface:EntityMetamodelBuilderAdds aEntityEvolverto this metamodel. This evolver will be called upon applying an event to the entity. The evolver is responsible for evolving the entity state based on the event. Note that providing an evolver is optional. However, if no evolver is provided, the entity state can only be changed through command handlers.Calling this method a second time will override the previously set evolver.
- Specified by:
entityEvolverin interfaceEntityMetamodelBuilder<E>- Parameters:
entityEvolver- TheEntityEvolverto use.- Returns:
- This builder for further configuration.
-
addConcreteType
@Nonnull PolymorphicEntityMetamodelBuilder<E> addConcreteType(@Nonnull EntityMetamodel<? extends E> metamodel) Adds a concrete type to this metamodel. The concrete type must be a subclass of the parent entity type.- Parameters:
metamodel- TheEntityMetamodelfor the concrete type.- Returns:
- This builder for further configuration.
-