Package org.fuin.ddd4j.ddd
Class AbstractAggregateRoot<ID extends AggregateRootId>
- java.lang.Object
-
- org.fuin.ddd4j.ddd.AbstractAggregateRoot<ID>
-
- Type Parameters:
ID- Aggregate identifier.
- All Implemented Interfaces:
AggregateRoot<ID>,Entity<ID>
public abstract class AbstractAggregateRoot<ID extends AggregateRootId> extends Object implements AggregateRoot<ID>
Base class for aggregate roots.
-
-
Constructor Summary
Constructors Constructor Description AbstractAggregateRoot()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidapply(@NotNull DomainEvent<?> event)Applies the given new event.booleanequals(Object obj)protected List<Class<? extends DomainEvent<?>>>getIgnoredEvents()Returns a list of old / ignored events.AggregateVersiongetNextApplyVersion()Returns the next version useful when creating an event for being applied:
apply(new MyEvent( ...intgetNextVersion()Returns the next version of the aggregate.List<DomainEvent<?>>getUncommittedChanges()Returns a list of uncommitted changes.intgetVersion()Returns the current version of the aggregate.inthashCode()booleanhasUncommitedChanges()Returns the information if the aggregate has uncommited changes.voidloadFromHistory(List<DomainEvent<?>> history)Loads the aggregate with historic events.voidloadFromHistory(DomainEvent<?>... history)Loads the aggregate with historic events.voidmarkChangesAsCommitted()Clears the internal change list and sets the new version number.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.fuin.ddd4j.ddd.AggregateRoot
getId
-
-
-
-
Method Detail
-
getUncommittedChanges
public final List<DomainEvent<?>> getUncommittedChanges()
Description copied from interface:AggregateRootReturns a list of uncommitted changes.- Specified by:
getUncommittedChangesin interfaceAggregateRoot<ID extends AggregateRootId>- Returns:
- List of events that were not persisted yet.
-
hasUncommitedChanges
public final boolean hasUncommitedChanges()
Description copied from interface:AggregateRootReturns the information if the aggregate has uncommited changes.- Specified by:
hasUncommitedChangesin interfaceAggregateRoot<ID extends AggregateRootId>- Returns:
- TRUE if the aggregate will return a non-empty list for
AggregateRoot.getUncommittedChanges(), else FALSE.
-
markChangesAsCommitted
public final void markChangesAsCommitted()
Description copied from interface:AggregateRootClears the internal change list and sets the new version number.- Specified by:
markChangesAsCommittedin interfaceAggregateRoot<ID extends AggregateRootId>
-
getVersion
public final int getVersion()
Description copied from interface:AggregateRootReturns the current version of the aggregate.- Specified by:
getVersionin interfaceAggregateRoot<ID extends AggregateRootId>- Returns:
- Current version that does NOT included uncommitted changes.
-
getNextVersion
public final int getNextVersion()
Description copied from interface:AggregateRootReturns the next version of the aggregate.- Specified by:
getNextVersionin interfaceAggregateRoot<ID extends AggregateRootId>- Returns:
- Next version that includes all currently uncommitted changes.
-
getNextApplyVersion
public final AggregateVersion getNextApplyVersion()
Description copied from interface:AggregateRootReturns the next version useful when creating an event for being applied:
apply(new MyEvent( ... , getNextApplyVersion())).- Specified by:
getNextApplyVersionin interfaceAggregateRoot<ID extends AggregateRootId>- Returns:
- Version for the event.
-
loadFromHistory
public final void loadFromHistory(DomainEvent<?>... history)
Description copied from interface:AggregateRootLoads the aggregate with historic events.- Specified by:
loadFromHistoryin interfaceAggregateRoot<ID extends AggregateRootId>- Parameters:
history- List of historic events.
-
loadFromHistory
public final void loadFromHistory(List<DomainEvent<?>> history)
Description copied from interface:AggregateRootLoads the aggregate with historic events.- Specified by:
loadFromHistoryin interfaceAggregateRoot<ID extends AggregateRootId>- Parameters:
history- List of historic events.
-
getIgnoredEvents
protected final List<Class<? extends DomainEvent<?>>> getIgnoredEvents()
Returns a list of old / ignored events. Sub classes can overwrite this method to ignore historic events that are not needed any more.- Returns:
- Events that can be safely ignored.
-
apply
protected final void apply(@NotNull @NotNull DomainEvent<?> event)Applies the given new event. CAUTION: Don't use this method for applying historic events!- Parameters:
event- Event to dispatch to the appropriate event handler method.
-
-