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
public abstract class AggregateState<ID,EVENT_TYPE extends Event<ID>> extends Object
Base class for the state object associated withAggregateRootWithState.
When this is combined with theAggregateRootWithStatewhen theAggregateRootWithStatewill contain the command methods and theAggregateStatecontains the state fields and theEventHandlerannotated methods.
-
-
Constructor Summary
Constructors Constructor Description AggregateState()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IDaggregateId()protected 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 withEventHandlerdk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrdereventOrderOfLastAppliedEvent()Get theof the last {}@link Eventthat was applied to theAggregateRoot(either usingrehydrate(Stream)or usingapply(Event)dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrdergetEventOrderOfLastAppliedEvent()dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrdergetEventOrderOfLastRehydratedEvent()booleanhasBeenRehydrated()Hasrehydrate(Stream)been usedprotected booleanisRehydrating()Is the event being supplied toapplyEventToTheAggregate(Event)a historic eventvoidmarkChangesAsCommitted()Resets theuncommittedChanges()- effectively marking them as having been persisted and committed to the underlyingEventStorevoidrehydrate(Stream<EVENT_TYPE> previousEvents)List<EVENT_TYPE>uncommittedChanges()The the events that have been applied to this aggregate instance but not yet persisted to the underlyingEventStore
-
-
-
Method Detail
-
rehydrate
public void rehydrate(Stream<EVENT_TYPE> previousEvents)
-
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
protected final void apply(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. 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
public ID 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
protected void applyEventToTheAggregate(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 withEventHandler- Parameters:
event- the event to apply to the aggregate- See Also:
isRehydrating()
-
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
public List<EVENT_TYPE> 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
-
-