Class EventsToPersist<ID,EVENT_TYPE>
- java.lang.Object
-
- dk.cloudcreate.essentials.components.eventsourced.aggregates.EventsToPersist<ID,EVENT_TYPE>
-
- Type Parameters:
ID- the aggregate id typeEVENT_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 inFlexAggregate/AggregateRootsub 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
-
-
Field Summary
Fields Modifier and Type Field Description IDaggregateIdThe id of the aggregate this relates todk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrdereventOrderOfLastRehydratedEvent(Zero based event order) contains the eventOrder for the last (previous/historic) event applied duringAggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream).List<EVENT_TYPE>events
-
Constructor Summary
Constructors Constructor Description EventsToPersist(ID aggregateId, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder eventOrderOfLastRehydratedEvent, EVENT_TYPE... events)EventsToPersist(ID aggregateId, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder eventOrderOfLastRehydratedEvent, List<EVENT_TYPE> events)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description EventsToPersist<ID,EVENT_TYPE>append(EventsToPersist<ID,EVENT_TYPE> appendEventsToPersist)Immutable method that appends all events inappendEventsToPersistto theeventsin this instance.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 handlingstatic <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 aggregateObjectget(int index)Get event at index.static <ID,EVENT_TYPE>
EventsToPersist<ID,EVENT_TYPE>initialAggregateEvents(ID aggregateId, EVENT_TYPE... eventsToPersist)Wrap the events that should be persisted for this new aggregatebooleanisCommitted()booleanisEmpty()Is theeventsemptyvoidmarkEventsAsCommitted()static <ID,EVENT_TYPE,AGGREGATE_TYPE extends FlexAggregate<ID,AGGREGATE_TYPE>>
EventsToPersist<ID,EVENT_TYPE>noEvents(FlexAggregate<ID,AGGREGATE_TYPE> aggregate)Creates an emptyEventsToPersistwhich is handy for a commanded method didn't have a side-effect (e.g.static <ID,EVENT_TYPE>
EventsToPersist<ID,EVENT_TYPE>noEvents(ID aggregateId)Creates an emptyEventsToPersistwhich is handy for a commanded method didn't have a side-effect (e.g.intsize()Number of events.Stream<EVENT_TYPE>stream()StringtoString()
-
-
-
Field Detail
-
aggregateId
public final ID aggregateId
The id of the aggregate this relates to
-
eventOrderOfLastRehydratedEvent
public final dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder eventOrderOfLastRehydratedEvent
(Zero based event order) contains the eventOrder for the last (previous/historic) event applied duringAggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream). SeeEventOrder.NO_EVENTS_PREVIOUSLY_PERSISTED
-
events
public final List<EVENT_TYPE> events
-
-
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 toeventOrderOfLastRehydratedEvent- (Zero based event order) contains the eventOrder for the last (previous/historic) event applied duringAggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream). SeeEventOrder.NO_EVENTS_PREVIOUSLY_PERSISTEDevents- the events to persist, which will be the result/side-effect of a command method invocation in anFlexAggregate).
-
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 toeventOrderOfLastRehydratedEvent- (Zero based event order) contains the eventOrder for the last (previous/historic) event applied duringAggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream). SeeEventOrder.NO_EVENTS_PREVIOUSLY_PERSISTEDevents- the events to persist, which will be the result/side-effect of a command method invocation in anFlexAggregate).
-
-
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 toeventsToPersist- the events to persist, which will be the result/side-effect of a command method invocation in anFlexAggregate). 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 toeventOrderOfLastRehydratedEvent- (Zero based event order) contains the eventOrder for the last (previous/historic) event applied duringAggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream). SeeEventOrder.NO_EVENTS_PREVIOUSLY_PERSISTEDeventsToPersist- the events to persist, which will be the result/side-effect of a command method invocation in anFlexAggregate). 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 typeAGGREGATE_TYPE- the aggregate type- Parameters:
aggregate- the easy aggregate instance that theeventsToPersisteventsToPersist- the events to persist, which will be the result/side-effect of a command method invocation in anFlexAggregate). 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 emptyEventsToPersistwhich 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 emptyEventsToPersistwhich is handy for a commanded method didn't have a side-effect (e.g. due to idempotent handling)- Type Parameters:
ID- the aggregate id typeAGGREGATE_TYPE- the aggregate type- Parameters:
aggregate- the easy aggregate instance
-
markEventsAsCommitted
public void markEventsAsCommitted()
-
isCommitted
public boolean isCommitted()
-
append
public EventsToPersist<ID,EVENT_TYPE> append(EventsToPersist<ID,EVENT_TYPE> appendEventsToPersist)
Immutable method that appends all events inappendEventsToPersistto theeventsin this instance. The result is returned as a NEWEventsToPersistinstance that contains the combined list of events- Parameters:
appendEventsToPersist- the events to append to this instance- Returns:
- The result is returned as a NEW
EventsToPersistinstance that contains the combined list of events. The newEventsToPersistretains the original value of theeventOrderOfLastRehydratedEvent
-
stream
public Stream<EVENT_TYPE> stream()
-
size
public int size()
Number of events. Shorthand for {@link #events#size()}- Returns:
- Shorthand for {@link #events#size()}
-
-