Class AggregateState<ID,EVENT_TYPE extends Event<ID>>
java.lang.Object
dk.cloudcreate.essentials.components.eventsourced.aggregates.stateful.classic.state.AggregateState<ID,EVENT_TYPE>
- Type Parameters:
ID- the aggregate id typeEVENT_TYPE- the type of event
Base class for the state object associated with
When this is combined with the
AggregateRootWithState.When this is combined with the
AggregateRootWithState when the AggregateRootWithState
will contain the command methods and the AggregateState contains the state fields and the
EventHandler annotated methods.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidapply(EVENT_TYPE event) Apply a new non persisted/uncommitted Event to this aggregate instance.
If it is the very FIRSTEventthat is being applied thenEvent.aggregateId()MUST return the ID of the aggregate the event relates to
Every consecutiveEventapplied will have itsEvent.aggregateId(Object)method called IF it doesn't already have a value.protected voidapplyEventToTheAggregate(Event<ID> event) Apply the event to the aggregate instance to reflect the event as a state change to the aggregate
The default implementation will automatically call any (private) methods annotated withEventHandlerfinal dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrderGet theof the last {}@link Eventthat was applied to theAggregateRoot(either usingrehydrate(Stream)or usingapply(Event)dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrderdk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrderbooleanHasrehydrate(Stream)been usedprotected final booleanIs the event being supplied toapplyEventToTheAggregate(Event)a historic eventvoidResets theuncommittedChanges()- effectively marking them as having been persisted and committed to the underlyingEventStorevoidrehydrate(Stream<EVENT_TYPE> previousEvents) The the events that have been applied to this aggregate instance but not yet persisted to the underlyingEventStore
-
Constructor Details
-
AggregateState
public AggregateState()
-
-
Method Details
-
rehydrate
-
getEventOrderOfLastAppliedEvent
public dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder getEventOrderOfLastAppliedEvent() -
getEventOrderOfLastRehydratedEvent
public dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder getEventOrderOfLastRehydratedEvent() -
apply
Apply a new non persisted/uncommitted Event to this aggregate instance.
If it is the very FIRSTEventthat is being applied thenEvent.aggregateId()MUST return the ID of the aggregate the event relates to
Every consecutiveEventapplied will have itsEvent.aggregateId(Object)method called IF it doesn't already have a value. I.e. you can be lazy and skip setting the aggregate id on the Event if you don't want to.The
AggregateRootautomatically keeps track of theEvent.eventOrder()value and will set it for you and ensure that it's growing consecutively.- Parameters:
event- the event to apply
-
aggregateId
-
hasBeenRehydrated
public boolean hasBeenRehydrated()Hasrehydrate(Stream)been used -
isRehydrating
protected final boolean isRehydrating()Is the event being supplied toapplyEventToTheAggregate(Event)a historic event -
applyEventToTheAggregate
Apply the event to the aggregate instance to reflect the event as a state change to the aggregate
The default implementation will automatically call any (private) methods annotated withEventHandler- Parameters:
event- the event to apply to the aggregate- See Also:
-
eventOrderOfLastAppliedEvent
public final dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder eventOrderOfLastAppliedEvent()Get theof the last {}@link Eventthat was applied to theAggregateRoot(either usingrehydrate(Stream)or usingapply(Event)- Returns:
- the event order of the last applied
EventorEventOrder.NO_EVENTS_PREVIOUSLY_PERSISTEDin case no events has ever been applied to the aggregate
-
uncommittedChanges
The the events that have been applied to this aggregate instance but not yet persisted to the underlyingEventStore -
markChangesAsCommitted
public void markChangesAsCommitted()Resets theuncommittedChanges()- effectively marking them as having been persisted and committed to the underlyingEventStore
-