Class AggregateAnnotationCommandHandler.Builder<T>

java.lang.Object
org.axonframework.modelling.command.AggregateAnnotationCommandHandler.Builder<T>
Type Parameters:
T - the type of aggregate this AggregateAnnotationCommandHandler handles commands for
Enclosing class:
AggregateAnnotationCommandHandler<T>

public static class AggregateAnnotationCommandHandler.Builder<T> extends Object
Builder class to instantiate a AggregateAnnotationCommandHandler.

The CommandTargetResolver is defaulted to an AnnotationCommandTargetResolver The Repository is a hard requirement and as such should be provided. Next to that, this Builder's goal is to provide an AggregateModel (describing the structure of a given aggregate). To instantiate this AggregateModel, either an AggregateModel can be provided directly or an aggregateType of type Class can be used. The latter will internally resolve to an AggregateModel. Thus, either the AggregateModel or the aggregateType should be provided.

  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • repository

      public AggregateAnnotationCommandHandler.Builder<T> repository(Repository<T> repository)
      Sets the Repository used to add and load Aggregate instances of generic type T upon handling commands for it.
      Parameters:
      repository - a Repository used to add and load Aggregate instances of generic type T upon handling commands for it
      Returns:
      the current Builder instance, for fluent interfacing
    • commandTargetResolver

      public AggregateAnnotationCommandHandler.Builder<T> commandTargetResolver(CommandTargetResolver commandTargetResolver)
      Sets the CommandTargetResolver used to resolve the command handling target. Defaults to an AnnotationCommandTargetResolver.
      Parameters:
      commandTargetResolver - a CommandTargetResolver used to resolve the command handling target
      Returns:
      the current Builder instance, for fluent interfacing
    • aggregateType

      public AggregateAnnotationCommandHandler.Builder<T> aggregateType(Class<T> aggregateType)
      Sets the aggregateType as a Class, specifying the type of aggregate an AggregateModel should be created for. Either this field or the aggregateModel(AggregateModel) should be provided to correctly instantiate an AggregateAnnotationCommandHandler.
      Parameters:
      aggregateType - the aggregateType specifying the type of aggregate an AggregateModel should be instantiated for
      Returns:
      the current Builder instance, for fluent interfacing
    • parameterResolverFactory

      public AggregateAnnotationCommandHandler.Builder<T> parameterResolverFactory(org.axonframework.messaging.annotation.ParameterResolverFactory parameterResolverFactory)
      Sets the ParameterResolverFactory used to resolve parameters for annotated handlers contained in the Aggregate. Only used if the aggregateType approach is selected to create an AggregateModel.
      Parameters:
      parameterResolverFactory - a ParameterResolverFactory used to resolve parameters for annotated handlers contained in the Aggregate
      Returns:
      the current Builder instance, for fluent interfacing
    • handlerDefinition

      public AggregateAnnotationCommandHandler.Builder<T> handlerDefinition(org.axonframework.messaging.annotation.HandlerDefinition handlerDefinition)
      Sets the HandlerDefinition used to create concrete handlers for the given aggregateType. Only used if the aggregateType approach is selected to create an AggregateModel.
      Parameters:
      handlerDefinition - a HandlerDefinition used to create concrete handlers for the given aggregateType
      Returns:
      the current Builder instance, for fluent interfacing
    • aggregateModel

      public AggregateAnnotationCommandHandler.Builder<T> aggregateModel(AggregateModel<T> aggregateModel)
      Sets the AggregateModel of generic type T, describing the structure of the aggregate the AnnotationCommandHandlerAdapter will handle. Either this field or the aggregateType(Class) should be provided to correctly instantiate an AggregateAnnotationCommandHandler.
      Parameters:
      aggregateModel - the AggregateModel of generic type T of the aggregate this Repository will store
      Returns:
      the current Builder instance, for fluent interfacing
    • creationPolicyAggregateFactory

      public AggregateAnnotationCommandHandler.Builder<T> creationPolicyAggregateFactory(CreationPolicyAggregateFactory<T> creationPolicyAggregateFactory)
      Sets the CreationPolicyAggregateFactory<T> for generic type T.

      The aggregate factory must produce a new instance of the aggregate root based on the supplied identifier. When dealing with a polymorphic aggregate, the given creationPolicyAggregateFactory will be used for every type.

      Parameters:
      creationPolicyAggregateFactory - The CreationPolicyAggregateFactory the constructs an aggregate instance based on an identifier.
      Returns:
      The current Builder instance, for fluent interfacing.
    • build

      Initializes a AggregateAnnotationCommandHandler as specified through this Builder.
      Returns:
      a AggregateAnnotationCommandHandler as specified through this Builder
    • validate

      protected void validate() throws org.axonframework.common.AxonConfigurationException
      Validates whether the fields contained in this Builder are set accordingly.
      Throws:
      org.axonframework.common.AxonConfigurationException - if one field is asserted to be incorrect according to the Builder's specifications