Package org.seedstack.business.assembler
Annotation Type AggregateId
-
@Documented @Retention(RUNTIME) @Target({METHOD,ANNOTATION_TYPE}) public @interface AggregateId
WhenFluentAssemblerDSL needs to get an aggregate from repository (i.e. when thefromRepository()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 intaggregateIndexWhen using a tuple assembler, i.e.intindexIf 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.
-