Class ConcreteEntityMetamodel<E>
- Type Parameters:
E- The type of the entity this metamodel describes.
- All Implemented Interfaces:
DescribableComponent,EntityMetamodel<E>,EntityEvolver<E>
EntityMetamodel interface that enables the definition of command handlers and child
entities for a given entity type E. Optionally, an EntityEvolver can be provided to evolve the entity
state based on events. If no EntityEvolver is provided, state can exclusively be changed through command
handlers.
During the handling of commands, handlers defined in child entities take precedence over the parent entity's command handlers. Event handlers are invoked on both the parent and child models, with child models being invoked first.
- Since:
- 5.0.0
- Author:
- Mitchell Herrijgers
-
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.Returns theClassof the entity this metamodel describes.evolve(E entity, EventMessage event, ProcessingContext context) Evolve the givenentityby applying the giveneventto it.static <E> EntityMetamodelBuilder<E> forEntityClass(Class<E> entityType) Creates abuilderfor the specified 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.toString()
-
Method Details
-
forEntityClass
Creates abuilderfor the specified entity type. This builder provides a fluent API for defining and constructing anEntityMetamodelfor the given entity class, allowing the registration of command handlers, child entities, and an optional entity evolver.- Type Parameters:
E- The type of the entity for which the metamodel is being built.- Parameters:
entityType- TheClassobject representing the entity type.- Returns:
- A
ConcreteEntityMetamodel.Builderinstance configured for the specified entity type.
-
supportedCommands
Description copied from interface:EntityMetamodelReturns the set of allQualifiedNamesthat this metamodel supports for command handlers, both creational and instance commands. This is the union of theEntityMetamodel.supportedCreationalCommands()andEntityMetamodel.supportedInstanceCommands()methods.- Specified by:
supportedCommandsin interfaceEntityMetamodel<E>- Returns:
- A set of
QualifiedNameinstances representing the supported command names.
-
supportedCreationalCommands
Description copied from interface:EntityMetamodelReturns 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 theEntityMetamodel.handleCreate(org.axonframework.messaging.commandhandling.CommandMessage, org.axonframework.messaging.core.unitofwork.ProcessingContext)method.- Specified by:
supportedCreationalCommandsin interfaceEntityMetamodel<E>- Returns:
- A set of
QualifiedNameinstances representing the supported command names.
-
supportedInstanceCommands
Description copied from interface:EntityMetamodelReturns 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 theEntityMetamodel.handleInstance(org.axonframework.messaging.commandhandling.CommandMessage, E, org.axonframework.messaging.core.unitofwork.ProcessingContext)method.- Specified by:
supportedInstanceCommandsin interfaceEntityMetamodel<E>- Returns:
- A set of
QualifiedNameinstances representing the supported command names.
-
handleCreate
@Nonnull public MessageStream.Single<CommandResultMessage> handleCreate(@Nonnull CommandMessage message, @Nonnull ProcessingContext context) Description copied from interface:EntityMetamodelHandles 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
EntityMetamodel.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.- Specified by:
handleCreatein interfaceEntityMetamodel<E>- 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 public MessageStream.Single<CommandResultMessage> handleInstance(@Nonnull CommandMessage message, @Nonnull E entity, @Nonnull ProcessingContext context) Description copied from interface:EntityMetamodelHandles 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
EntityMetamodel.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.- Specified by:
handleInstancein interfaceEntityMetamodel<E>- 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.
-
evolve
@Nullable public E evolve(@Nonnull E entity, @Nonnull EventMessage event, @Nonnull ProcessingContext context) Description copied from interface:EntityEvolverEvolve the givenentityby applying the giveneventto it.- Specified by:
evolvein interfaceEntityEvolver<E>- 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.
-
entityType
Description copied from interface:EntityMetamodelReturns theClassof the entity this metamodel describes.- Specified by:
entityTypein interfaceEntityMetamodel<E>- Returns:
- The
Classof the entity this metamodel describes.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-
toString
-