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 id
EVENT_TYPE - the type of event
AGGREGATE_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 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 Details

    • AggregateState

      public AggregateState()
  • Method Details

    • getAggregate

      protected final AGGREGATE_TYPE getAggregate()
      Get access to the aggregate instance this state object is associated with
      Returns:
      the aggregate instance this state object is associated with