Annotation Type AggregateId


  • @Documented
    @Retention(RUNTIME)
    @Target({METHOD,ANNOTATION_TYPE})
    public @interface AggregateId
    When FluentAssembler DSL needs to get an aggregate from repository (i.e. when the fromRepository() method is used), this annotation allows to specify a matching between a DTO getter and the identifier of the aggregate.

    Example 1: single aggregate, simple identifier

     public class OrderDto {
        @AggregateId
         public String getId() {...}
     }
    
     public class Order extends BaseAggregateRoot<String> {
     }
     

    Example 2: single aggregate, composite identifier

     public class CustomerDto {
        @AggregateId(index = 0)
         public String getFirstName() {...}
    
        @AggregateId(index = 1)
         public String getLastName() {...}
    
         // No annotation here as the birth date is not part of the customer id
         public Date getBirthDate() {...}
     }
    
     public class CustomerId extends BaseValueObject {
         public CustomerId(String firstName, String lastName) {...}
     }
    
     public class Customer extends BaseAggregateRoot<CustomerId> {
     }
     

    Example 3: tuple of aggregates, one with composite identifier, the other with simple identifier

     public class RecipeDto {
        @MatchingEntityId(aggregateIndex = 0, index = 0)
         public String getCustomerFirstName() {...}
    
        @MatchingEntityId(aggregateIndex = 0, index = 1)
         public String getCustomerLastName() {...}
    
        @MatchingEntityId(aggregateIndex = 1)
         public int getOrderId() {...}
     }
    
     public class CustomerId extends BaseValueObject {
         public CustomerId(String firstName, String lastName) {...}
     }
    
     public class Customer extends BaseAggregateRoot<CustomerId> {
     }
    
     public class Order extends BaseAggregateRoot<Integer> {
     }
     
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      int aggregateIndex
      When using a tuple assembler, i.e.
      int index
      If the aggregate root id is composite, i.e it is a value object, this method indicates constructor parameter of the value object associated to the annotated method.
    • Element Detail

      • aggregateIndex

        int aggregateIndex
        When using a tuple assembler, i.e. when assembling a DTO to tuple of aggregate roots. This index indicates to which aggregate root this id belongs.
        Returns:
        the aggregate index
        Default:
        -1
      • index

        int index
        If the aggregate root id is composite, i.e it is a value object, this method indicates constructor parameter of the value object associated to the annotated method.
        Returns:
        the parameter index in the id constructor.
        Default:
        -1