Module org.fuin.ddd4j
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidapply(@NotNull DomainEvent<?> event) Applies the given new event.final booleanprotected final List<Class<? extends DomainEvent<?>>>Returns a list of old / ignored events.final AggregateVersionReturns the next version useful when creating an event for being applied:
apply(new MyEvent( ...final intReturns the next version of the aggregate.final List<DomainEvent<?>>Returns a list of uncommitted changes.final intReturns the current version of the aggregate.final inthashCode()final booleanReturns the information if the aggregate has uncommited changes.final voidloadFromHistory(List<DomainEvent<?>> history) Loads the aggregate with historic events.final voidloadFromHistory(DomainEvent<?>... history) Loads the aggregate with historic events.final voidClears 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, waitMethods inherited from interface org.fuin.ddd4j.ddd.AggregateRoot
getId
-
Constructor Details
-
AbstractAggregateRoot
public AbstractAggregateRoot()Default constructor.
-
-
Method Details
-
hashCode
public final int hashCode() -
equals
-
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
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
Description copied from interface:AggregateRootLoads the aggregate with historic events.- Specified by:
loadFromHistoryin interfaceAggregateRoot<ID extends AggregateRootId>- Parameters:
history- List of historic events.
-
loadFromHistory
Description copied from interface:AggregateRootLoads the aggregate with historic events.- Specified by:
loadFromHistoryin interfaceAggregateRoot<ID extends AggregateRootId>- Parameters:
history- List of historic events.
-
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
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.
-