Class AbstractAggregateRoot<A extends AbstractAggregateRoot<A>>

java.lang.Object
org.springframework.data.domain.AbstractAggregateRoot<A>

public class AbstractAggregateRoot<A extends AbstractAggregateRoot<A>> extends Object
Convenience base class for aggregate roots that exposes a registerEvent(Object) to capture domain events and expose them via domainEvents(). The implementation is using the general event publication mechanism implied by DomainEvents and AfterDomainEventPublication. If in doubt or need to customize anything here, rather build your own base class and use the annotations directly.
Since:
1.13
Author:
Oliver Gierke, Christoph Strobl
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final A
    Adds the given event to the aggregate for later publication when calling a Spring Data repository's save or delete method.
    protected final A
    andEventsFrom(A aggregate)
    Adds all events contained in the given aggregate to the current one.
    protected void
    Clears all domain events currently held.
    protected Collection<Object>
    All domain events currently captured by the aggregate.
    protected <T> T
    registerEvent(T event)
    Registers the given event object for publication on a call to a Spring Data repository's save or delete methods.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractAggregateRoot

      public AbstractAggregateRoot()
  • Method Details

    • registerEvent

      protected <T> T registerEvent(T event)
      Registers the given event object for publication on a call to a Spring Data repository's save or delete methods.
      Parameters:
      event - must not be null.
      Returns:
      the event that has been added.
      See Also:
    • clearDomainEvents

      protected void clearDomainEvents()
      Clears all domain events currently held. Usually invoked by the infrastructure in place in Spring Data repositories.
    • domainEvents

      protected Collection<Object> domainEvents()
      All domain events currently captured by the aggregate.
    • andEventsFrom

      protected final A andEventsFrom(A aggregate)
      Adds all events contained in the given aggregate to the current one.
      Parameters:
      aggregate - must not be null.
      Returns:
      the aggregate
    • andEvent

      protected final A andEvent(Object event)
      Adds the given event to the aggregate for later publication when calling a Spring Data repository's save or delete method. Does the same as registerEvent(Object) but returns the aggregate instead of the event.
      Parameters:
      event - must not be null.
      Returns:
      the aggregate
      See Also: