Class AggregateState<ID,EVENT_TYPE,AGGREGATE_TYPE extends AggregateRoot<ID,EVENT_TYPE,AGGREGATE_TYPE>>
java.lang.Object
dk.cloudcreate.essentials.components.eventsourced.aggregates.stateful.modern.AggregateState<ID,EVENT_TYPE,AGGREGATE_TYPE>
- Type Parameters:
ID- the type of idEVENT_TYPE- the type of eventAGGREGATE_TYPE- the aggregate root type
public abstract class AggregateState<ID,EVENT_TYPE,AGGREGATE_TYPE extends AggregateRoot<ID,EVENT_TYPE,AGGREGATE_TYPE>>
extends Object
Aggregate state object associated with a given
Example:
AggregateRoot instance (see getAggregate())Example:
public class OrderState extends AggregateState<OrderId, OrderEvent, Order> {
private Map<ProductId, Integer> productAndQuantity;
private boolean accepted;
@EventHandler
private void on(OrderEvent.OrderAdded e) {
productAndQuantity = new HashMap<>();
}
@EventHandler
private void on(OrderEvent.ProductAddedToOrder e) {
var existingQuantity = productAndQuantity.get(e.productId);
productAndQuantity.put(e.productId, e.quantity + (existingQuantity != null ? existingQuantity : 0));
}
@EventHandler
private void on(OrderEvent.ProductOrderQuantityAdjusted e) {
productAndQuantity.put(e.productId, e.newQuantity);
}
@EventHandler
private void on(OrderEvent.ProductRemovedFromOrder e) {
productAndQuantity.remove(e.productId);
}
@EventHandler
private void on(OrderEvent.OrderAccepted e) {
accepted = true;
}
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final AGGREGATE_TYPEGet access to the aggregate instance this state object is associated with
-
Constructor Details
-
AggregateState
public AggregateState()
-
-
Method Details
-
getAggregate
Get access to the aggregate instance this state object is associated with- Returns:
- the aggregate instance this state object is associated with
-