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 Details

    • AbstractAggregateRoot

      public AbstractAggregateRoot()
      Default constructor.
  • Method Details

    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getUncommittedChanges

      public final List<DomainEvent<?>> getUncommittedChanges()
      Description copied from interface: AggregateRoot
      Returns a list of uncommitted changes.
      Specified by:
      getUncommittedChanges in interface AggregateRoot<ID extends AggregateRootId>
      Returns:
      List of events that were not persisted yet.
    • hasUncommitedChanges

      public final boolean hasUncommitedChanges()
      Description copied from interface: AggregateRoot
      Returns the information if the aggregate has uncommited changes.
      Specified by:
      hasUncommitedChanges in interface AggregateRoot<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: AggregateRoot
      Clears the internal change list and sets the new version number.
      Specified by:
      markChangesAsCommitted in interface AggregateRoot<ID extends AggregateRootId>
    • getVersion

      public final int getVersion()
      Description copied from interface: AggregateRoot
      Returns the current version of the aggregate.
      Specified by:
      getVersion in interface AggregateRoot<ID extends AggregateRootId>
      Returns:
      Current version that does NOT included uncommitted changes.
    • getNextVersion

      public final int getNextVersion()
      Description copied from interface: AggregateRoot
      Returns the next version of the aggregate.
      Specified by:
      getNextVersion in interface AggregateRoot<ID extends AggregateRootId>
      Returns:
      Next version that includes all currently uncommitted changes.
    • getNextApplyVersion

      public final AggregateVersion getNextApplyVersion()
      Description copied from interface: AggregateRoot
      Returns the next version useful when creating an event for being applied:
      apply(new MyEvent( ... , getNextApplyVersion())).
      Specified by:
      getNextApplyVersion in interface AggregateRoot<ID extends AggregateRootId>
      Returns:
      Version for the event.
    • loadFromHistory

      public final void loadFromHistory(DomainEvent<?>... history)
      Description copied from interface: AggregateRoot
      Loads the aggregate with historic events.
      Specified by:
      loadFromHistory in interface AggregateRoot<ID extends AggregateRootId>
      Parameters:
      history - List of historic events.
    • loadFromHistory

      public final void loadFromHistory(List<DomainEvent<?>> history)
      Description copied from interface: AggregateRoot
      Loads the aggregate with historic events.
      Specified by:
      loadFromHistory in interface AggregateRoot<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.