org.axonframework.commandhandling
Class MetaDataCommandTargetResolver

java.lang.Object
  extended by org.axonframework.commandhandling.MetaDataCommandTargetResolver
All Implemented Interfaces:
CommandTargetResolver

public class MetaDataCommandTargetResolver
extends Object
implements 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
MetaDataCommandTargetResolver(String identifierKey)
          Initializes the MetaDataCommandTargetResolver to use the given identifierKey as the MetaData key to the aggregate identifier, and a null (ignored) version.
MetaDataCommandTargetResolver(String identifierKey, String versionKey)
          Initializes the MetaDataCommandTargetResolver to use the given identifierKey as the MetaData key to the aggregate identifier, and the given versionKey as key to the (optional) version entry.
 
Method Summary
 VersionedAggregateIdentifier resolveTarget(CommandMessage<?> command)
          Returns the Aggregate Identifier and optionally the expected version of the aggregate on which the given command should be executed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetaDataCommandTargetResolver

public MetaDataCommandTargetResolver(String identifierKey)
Initializes the MetaDataCommandTargetResolver to use the given identifierKey as the MetaData key to the aggregate identifier, and a null (ignored) version.

When the given identifierKey is not present in a command's MetaData, resolveTarget(CommandMessage) will raise an IllegalArgumentException

Parameters:
identifierKey - The key of the meta data field containing the aggregate identifier

MetaDataCommandTargetResolver

public MetaDataCommandTargetResolver(String identifierKey,
                                     String versionKey)
Initializes the MetaDataCommandTargetResolver to use the given identifierKey as the MetaData key to the aggregate identifier, and the given versionKey as key to the (optional) version entry.

When the given identifierKey is not present in a command's MetaData, resolveTarget(CommandMessage) will raise an IllegalArgumentException

Parameters:
identifierKey - The key of the meta data field containing the aggregate identifier
versionKey - The key of the meta data field containing the expected aggregate version. A null value may be provided to ignore the version
Method Detail

resolveTarget

public VersionedAggregateIdentifier resolveTarget(CommandMessage<?> command)
Description copied from interface: CommandTargetResolver
Returns the Aggregate Identifier and optionally the expected version of the aggregate on which the given command should be executed. The version may be null if no specific version is required.

Specified by:
resolveTarget in interface CommandTargetResolver
Parameters:
command - The command from which to extract the identifier and version
Returns:
a VersionedAggregateIdentifier instance reflecting the aggregate to execute the command on


Copyright © 2010-2016. All Rights Reserved.