@Retention(value=RUNTIME) @Target(value=METHOD) public @interface MatchingEntityId
fromRepository() method of the assembler DSL. If you don't use
this DSL feature, this annotated is unnecessary.
It binds the DTO annotated method to the aggregate root id. If the id is a value object, it binds the method to one of the constructor parameters. This allows the assembler DSL to find (or create) the aggregate root id in order to load the aggregate root from the repository.
It also handle the case of a DTO assembled from a tuple of aggregate roots.
Case 1: Basic use case.
public class OrderDto {
@MatchingEntityId
public int getId() {...}
}
public class OrderAssembler extends BaseTupleAssembler<Order, OrderDto> { ... }
public class Order {
private int orderId;
public Integer getEntityId() {
return orderId;
}
}
Case 1: Basic use case.
public class CustomerDto {
@MatchingEntityId(index = 0)
public String getFirstName() {...}
@MatchingEntityId(index = 1)
public String getLastName() {...}
// No need for annotation here as the birth date is not part of the customer id
public Date getBirthDate() {...}
}
public class RecipeAssembler extends BaseAssembler<Customer, CustomerDto> { ... }
public class CustomerId {
public CustomerId(String firstName, String lastName) {...}
}
Case 2: The DTO is an assembly of multiple aggregates.
public class RecipeDto {
@MatchingEntityId(index = 0, typeIndex = 0)
public String getCustomerFirstName() {...}
@MatchingEntityId(index = 1, typeIndex = 0)
public String getCustomerLastName() {...}
@MatchingEntityId(typeIndex = 1) // no need for index as OrderId is not a value object
public int getOrderId() {...}
}
public class RecipeAssembler extends BaseTupleAssembler<Pair<Customer, Order>, RecipeDto> { ... }
public class CustomerId {
public CustomerId(String firstName, String lastName) {...}
}
public class Order {
private int orderId;
public Integer getEntityId() {
return orderId;
}
}
| Modifier and Type | Optional Element and Description |
|---|---|
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.
|
int |
typeIndex
When using a tuple assembler, i.e.
|
public abstract int index
public abstract int typeIndex
BaseTupleAssemblerCopyright © 2013-2016–2016 SeedStack. All rights reserved.