Class EventsToPersist<ID,​EVENT_TYPE>

  • Type Parameters:
    ID - the aggregate id type
    EVENT_TYPE - the type of event

    public class EventsToPersist<ID,​EVENT_TYPE>
    extends Object
    Wrapper object that captures the results of any command handling (e.g. static constructor method or instance command methods in FlexAggregate/AggregateRoot sub classes).
    The purpose of this wrapper is to wrap information about the aggregate-id, event-order of last applied historic event (if any) and any events that were a side effect of the command method invocation
    • Constructor Detail

      • EventsToPersist

        public EventsToPersist​(ID aggregateId,
                               dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder eventOrderOfLastRehydratedEvent,
                               List<EVENT_TYPE> events)
        Parameters:
        aggregateId - the aggregate id this relates to
        eventOrderOfLastRehydratedEvent - (Zero based event order) contains the eventOrder for the last (previous/historic) event applied during AggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream). See EventOrder.NO_EVENTS_PREVIOUSLY_PERSISTED
        events - the events to persist, which will be the result/side-effect of a command method invocation in an FlexAggregate).
      • EventsToPersist

        public EventsToPersist​(ID aggregateId,
                               dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder eventOrderOfLastRehydratedEvent,
                               EVENT_TYPE... events)
        Parameters:
        aggregateId - the aggregate id this relates to
        eventOrderOfLastRehydratedEvent - (Zero based event order) contains the eventOrder for the last (previous/historic) event applied during AggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream). See EventOrder.NO_EVENTS_PREVIOUSLY_PERSISTED
        events - the events to persist, which will be the result/side-effect of a command method invocation in an FlexAggregate).
    • Method Detail

      • initialAggregateEvents

        public static <ID,​EVENT_TYPE> EventsToPersist<ID,​EVENT_TYPE> initialAggregateEvents​(ID aggregateId,
                                                                                                        EVENT_TYPE... eventsToPersist)
        Wrap the events that should be persisted for this new aggregate
        Type Parameters:
        ID - the aggregate id type
        Parameters:
        aggregateId - the aggregate id this relates to
        eventsToPersist - the events to persist, which will be the result/side-effect of a command method invocation in an FlexAggregate). May be empty if the command method invocation didn't result in any events (e.g. due to idempotency checks)
      • events

        public static <ID,​EVENT_TYPE> EventsToPersist<ID,​EVENT_TYPE> events​(ID aggregateId,
                                                                                        dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder eventOrderOfLastRehydratedEvent,
                                                                                        EVENT_TYPE... eventsToPersist)
        Wrap the events that should be persisted for this existing aggregate
        Type Parameters:
        ID - the aggregate id type
        Parameters:
        aggregateId - the aggregate id this relates to
        eventOrderOfLastRehydratedEvent - (Zero based event order) contains the eventOrder for the last (previous/historic) event applied during AggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream). See EventOrder.NO_EVENTS_PREVIOUSLY_PERSISTED
        eventsToPersist - the events to persist, which will be the result/side-effect of a command method invocation in an FlexAggregate). May be empty if the command method invocation didn't result in any events (e.g. due to idempotency checks)
      • events

        public static <ID,​EVENT_TYPE,​AGGREGATE_TYPE extends FlexAggregate<ID,​AGGREGATE_TYPE>> EventsToPersist<ID,​EVENT_TYPE> events​(FlexAggregate<ID,​AGGREGATE_TYPE> aggregate,
                                                                                                                                                            EVENT_TYPE... eventsToPersist)
        Wrap the events that should be persisted relates to the given aggregate's command handling
        Type Parameters:
        ID - the aggregate id type
        AGGREGATE_TYPE - the aggregate type
        Parameters:
        aggregate - the easy aggregate instance that the eventsToPersist
        eventsToPersist - the events to persist, which will be the result/side-effect of a command method invocation in an FlexAggregate). May be empty if the command method invocation didn't result in any events (e.g. due to idempotency checks)
      • noEvents

        public static <ID,​EVENT_TYPE> EventsToPersist<ID,​EVENT_TYPE> noEvents​(ID aggregateId)
        Creates an empty EventsToPersist which is handy for a commanded method didn't have a side-effect (e.g. due to idempotent handling)
        Type Parameters:
        ID - the aggregate id type
        Parameters:
        aggregateId - the aggregate id this relates to
      • noEvents

        public static <ID,​EVENT_TYPE,​AGGREGATE_TYPE extends FlexAggregate<ID,​AGGREGATE_TYPE>> EventsToPersist<ID,​EVENT_TYPE> noEvents​(FlexAggregate<ID,​AGGREGATE_TYPE> aggregate)
        Creates an empty EventsToPersist which is handy for a commanded method didn't have a side-effect (e.g. due to idempotent handling)
        Type Parameters:
        ID - the aggregate id type
        AGGREGATE_TYPE - the aggregate type
        Parameters:
        aggregate - the easy aggregate instance
      • markEventsAsCommitted

        public void markEventsAsCommitted()
      • isCommitted

        public boolean isCommitted()
      • isEmpty

        public boolean isEmpty()
        Is the events empty
        Returns:
        Is the events empty
      • size

        public int size()
        Number of events. Shorthand for {@link #events#size()}
        Returns:
        Shorthand for {@link #events#size()}
      • get

        public Object get​(int index)
        Get event at index. Shorthand for {@link #events#get(int)}
        Parameters:
        index - the index on the events list
        Returns:
        Shorthand for {@link #events#get(int)}