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
Wrapper object that captures the results of any command handling (e.g. static constructor method or instance command methods in
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
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal IDThe id of the aggregate this relates tofinal EventOrder(Zero based event order) contains the eventOrder for the last (previous/historic) event applied duringAggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream).final List<EVENT_TYPE> -
Constructor Summary
ConstructorsConstructorDescriptionEventsToPersist(ID aggregateId, EventOrder eventOrderOfLastRehydratedEvent, EVENT_TYPE... events) EventsToPersist(ID aggregateId, EventOrder eventOrderOfLastRehydratedEvent, List<EVENT_TYPE> events) -
Method Summary
Modifier and TypeMethodDescriptionappend(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, EventOrder eventOrderOfLastRehydratedEvent, EVENT_TYPE... eventsToPersist) Wrap the events that should be persisted for this existing aggregateget(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 aggregatebooleanbooleanisEmpty()Is theeventsemptyvoidstatic <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()toString()
-
Field Details
-
aggregateId
The id of the aggregate this relates to -
eventOrderOfLastRehydratedEvent
(Zero based event order) contains the eventOrder for the last (previous/historic) event applied duringAggregateRoot.rehydrate(AggregateEventStream)/FlexAggregate.rehydrate(AggregateEventStream). SeeEventOrder.NO_EVENTS_PERSISTED -
events
-
-
Constructor Details
-
EventsToPersist
public EventsToPersist(ID aggregateId, 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_PERSISTEDevents- the events to persist, which will be the result/side-effect of a command method invocation in anFlexAggregate).
-
EventsToPersist
public EventsToPersist(ID aggregateId, 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_PERSISTEDevents- the events to persist, which will be the result/side-effect of a command method invocation in anFlexAggregate).
-
-
Method Details
-
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, 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_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, EventsToPersist<ID,AGGREGATE_TYPE extends FlexAggregate<ID, AGGREGATE_TYPE>> 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
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, EventsToPersist<ID,AGGREGATE_TYPE extends FlexAggregate<ID, AGGREGATE_TYPE>> 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
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
-
toString
-
isEmpty
public boolean isEmpty()Is theeventsempty- Returns:
- Is the
eventsempty
-
stream
-
size
public int size()Number of events. Shorthand for {@link #events#size()}- Returns:
- Shorthand for {@link #events#size()}
-
get
Get event at index. Shorthand for {@link #events#get(int)}- Parameters:
index- the index on theeventslist- Returns:
- Shorthand for {@link #events#get(int)}
-