Class MetaDataCommandTargetResolver
java.lang.Object
org.axonframework.modelling.command.MetaDataCommandTargetResolver
- All Implemented Interfaces:
CommandTargetResolver
CommandTargetResolver implementation that uses MetaData entries to extract the identifier and optionally the version
of the aggregate that the command targets.
While this may require duplication of data (as the identifier is already included in the payload as well), it is a
more performing alternative to a reflection based CommandTargetResolvers.
- Since:
- 2.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionMetaDataCommandTargetResolver(String identifierKey) Initializes the MetaDataCommandTargetResolver to use the givenidentifierKeyas the MetaData key to the aggregate identifier, and anull(ignored) version.MetaDataCommandTargetResolver(String identifierKey, String versionKey) Initializes the MetaDataCommandTargetResolver to use the givenidentifierKeyas the MetaData key to the aggregate identifier, and the givenversionKeyas key to the (optional) version entry. -
Method Summary
Modifier and TypeMethodDescriptionresolveTarget(CommandMessage<?> command) Returns the Aggregate Identifier and optionally the expected version of the aggregate on which the givencommandshould be executed.
-
Constructor Details
-
MetaDataCommandTargetResolver
Initializes the MetaDataCommandTargetResolver to use the givenidentifierKeyas the MetaData key to the aggregate identifier, and anull(ignored) version. When the givenidentifierKeyis not present in a command's MetaData,resolveTarget(CommandMessage)will raise anIllegalArgumentException- Parameters:
identifierKey- The key of the metadata field containing the aggregate identifier
-
MetaDataCommandTargetResolver
Initializes the MetaDataCommandTargetResolver to use the givenidentifierKeyas the MetaData key to the aggregate identifier, and the givenversionKeyas key to the (optional) version entry. When the givenidentifierKeyis not present in a command's MetaData,resolveTarget(CommandMessage)will raise anIllegalArgumentException- Parameters:
identifierKey- The key of the metadata field containing the aggregate identifierversionKey- The key of the metadata field containing the expected aggregate version. Anullvalue may be provided to ignore the version
-
-
Method Details
-
resolveTarget
Description copied from interface:CommandTargetResolverReturns the Aggregate Identifier and optionally the expected version of the aggregate on which the givencommandshould be executed.The version may be
nullif no specific version is required. Furthermore, the returnedVersionedAggregateIdentifiermay be null entirely when the givencommandis targeted towards aCreationPolicyannotated command handler that (optionally) constructs a new aggregate instance.- Specified by:
resolveTargetin interfaceCommandTargetResolver- Parameters:
command- The command from which to extract the identifier and version.- Returns:
- A
VersionedAggregateIdentifierinstance reflecting the aggregate to execute the command on, ornullwhen thecommandis targeted towards aCreationPolicyannotated command handler that constructs a new aggregate instance. - See Also:
-