Interface EntityMetamodel<E>
- Type Parameters:
E- The type of the entity supported by this metamodel.
- All Superinterfaces:
DescribableComponent,EntityEvolver<E>
- All Known Implementing Classes:
AnnotatedEntityMetamodel,ConcreteEntityMetamodel,PolymorphicEntityMetamodel
E, containing the information needed to handle commands and events. An
EntityMetamodel can be created through the builder by using the forEntityType(Class) method. The
metamodel can then be used to handle commands and events for an entity. If the entity already exists, the
handleInstance(org.axonframework.messaging.commandhandling.CommandMessage, E, org.axonframework.messaging.core.unitofwork.ProcessingContext) method should be used to handle commands for the entity. If the entity is new, the
handleCreate(org.axonframework.messaging.commandhandling.CommandMessage, org.axonframework.messaging.core.unitofwork.ProcessingContext) method should be used to handle commands for creating the entity.- Since:
- 5.0.0
- Author:
- Mitchell Herrijgers
-
Method Summary
Modifier and TypeMethodDescriptionReturns theClassof the entity this metamodel describes.static <E> EntityMetamodelBuilder<E> forEntityType(Class<E> entityType) Starts a newEntityMetamodelBuilderfor the given entity type.static <E> PolymorphicEntityMetamodelBuilder<E> forPolymorphicEntityType(Class<E> entityType) Starts a newPolymorphicEntityMetamodelBuilderfor the given entity type.handleCreate(CommandMessage message, ProcessingContext context) Handles the givenCommandMessageas the creation of a new entity.handleInstance(CommandMessage message, E entity, ProcessingContext context) Handles the givenCommandMessagefor the givenentity.Returns the set of allQualifiedNamesthat this metamodel supports for command handlers, both creational and instance commands.Returns the set of allQualifiedNamesthat this metamodel supports for creating entities.Returns the set of allQualifiedNamesthat this metamodel supports for instance commands.Methods inherited from interface org.axonframework.common.infra.DescribableComponent
describeToMethods inherited from interface org.axonframework.modelling.EntityEvolver
evolve
-
Method Details
-
forEntityType
Starts a newEntityMetamodelBuilderfor the given entity type. The builder can be used to add command handlers and child entities to the metamodel.- Type Parameters:
E- The type of the entity to create a metamodel for.- Parameters:
entityType- The type of the entity to create a metamodel for.- Returns:
- A new
EntityMetamodelBuilderfor the given entity type.
-
forPolymorphicEntityType
@Nonnull static <E> PolymorphicEntityMetamodelBuilder<E> forPolymorphicEntityType(@Nonnull Class<E> entityType) Starts a newPolymorphicEntityMetamodelBuilderfor the given entity type. The builder can be used to add command handlers and child entities to the metamodel, specifically for polymorphic entities. The builder also supports adding concrete entity types that extend the given entity type, throughPolymorphicEntityMetamodelBuilder.addConcreteType(EntityMetamodel). The required concrete metamodel can be created withforEntityType(Class).- Type Parameters:
E- The type of the entity to create a metamodel for.- Parameters:
entityType- The type of the entity to create a metamodel for.- Returns:
- A new
PolymorphicEntityMetamodelBuilderfor the given entity type.
-
entityType
Returns theClassof the entity this metamodel describes.- Returns:
- The
Classof the entity this metamodel describes.
-
handleCreate
@Nonnull MessageStream.Single<CommandResultMessage> handleCreate(@Nonnull CommandMessage message, @Nonnull ProcessingContext context) Handles the givenCommandMessageas the creation of a new entity. It is up to the registered command handler to create the entity.This method is used to handle commands for new entities. If you want to handle commands for existing entities, use the
handleInstance(org.axonframework.messaging.commandhandling.CommandMessage, E, org.axonframework.messaging.core.unitofwork.ProcessingContext)method instead. If the command handler is only known as an instance command handler and this method is called, it will result in a failed message stream.- Parameters:
message- TheCommandMessageto handle.context- TheProcessingContextfor the command.- Returns:
- A stream with a message containing the result of the command handling, which may be a
CommandResultMessageor an error message.
-
handleInstance
@Nonnull MessageStream.Single<CommandResultMessage> handleInstance(@Nonnull CommandMessage message, @Nonnull E entity, @Nonnull ProcessingContext context) Handles the givenCommandMessagefor the givenentity. If any of its children can handle the command, it will be delegated to them. Otherwise, the command will be handled by this metamodel. If the command is not handled by this metamodel or any of its children, anMessageStream.failed(Throwable)will be returned.This method is used to handle commands for existing entities. If you want to handle commands for new entities, use the
handleCreate(org.axonframework.messaging.commandhandling.CommandMessage, org.axonframework.messaging.core.unitofwork.ProcessingContext)method instead. If the command handler is only known as a creational command handler and this method is called, it will result in a failed message stream.- Parameters:
message- TheCommandMessageto handle.entity- The entity instance to handle the command for.context- TheProcessingContextfor the command.- Returns:
- A stream with a message containing the result of the command handling, which may be a
CommandResultMessageor an error message.
-
supportedCreationalCommands
Returns the set of allQualifiedNamesthat this metamodel supports for creating entities. These are the command types that can be used to create an entity of this type through thehandleCreate(org.axonframework.messaging.commandhandling.CommandMessage, org.axonframework.messaging.core.unitofwork.ProcessingContext)method.- Returns:
- A set of
QualifiedNameinstances representing the supported command names.
-
supportedInstanceCommands
Returns the set of allQualifiedNamesthat this metamodel supports for instance commands. These are the command types that can be used on entity instances of this type through thehandleInstance(org.axonframework.messaging.commandhandling.CommandMessage, E, org.axonframework.messaging.core.unitofwork.ProcessingContext)method.- Returns:
- A set of
QualifiedNameinstances representing the supported command names.
-
supportedCommands
Returns the set of allQualifiedNamesthat this metamodel supports for command handlers, both creational and instance commands. This is the union of thesupportedCreationalCommands()andsupportedInstanceCommands()methods.- Returns:
- A set of
QualifiedNameinstances representing the supported command names.
-