Interface Repository<T>

Type Parameters:
T - The type of aggregate this repository stores.
All Superinterfaces:
ScopeAware
All Known Implementing Classes:
AbstractRepository, CachingEventSourcingRepository, EventSourcingRepository, GenericJpaRepository, GenericJpaRepository, LockingRepository

public interface Repository<T> extends ScopeAware
The Repository provides an abstraction of the storage of aggregates.

When interacting with the Repository the framework expects an active UnitOfWork containing a CommandMessage implementation on the invoking thread to be present. If there is no active UnitOfWork an IllegalStateException is thrown.

Since:
0.1
Author:
Allard Buijze
  • Method Summary

    Modifier and Type
    Method
    Description
    load(String aggregateIdentifier)
    Load the aggregate with the given unique identifier.
    load(String aggregateIdentifier, Long expectedVersion)
    Load the aggregate with the given unique identifier.
    default Aggregate<T>
    loadOrCreate(String aggregateIdentifier, Callable<T> factoryMethod)
    Loads an aggregate from the repository.
    newInstance(Callable<T> factoryMethod)
    Creates a new managed instance for the aggregate, using the given factoryMethod to instantiate the aggregate's root.
    default Aggregate<T>
    newInstance(Callable<T> factoryMethod, Consumer<Aggregate<T>> initMethod)
    Creates a new managed instance for the aggregate, using the given factoryMethod to instantiate the aggregate's root, and then applying the initMethod consumer to it to perform additional initialization.

    Methods inherited from interface org.axonframework.messaging.ScopeAware

    canResolve, send
  • Method Details

    • load

      Aggregate<T> load(@Nonnull String aggregateIdentifier)
      Load the aggregate with the given unique identifier. No version checks are done when loading an aggregate, meaning that concurrent access will not be checked for.
      Parameters:
      aggregateIdentifier - The identifier of the aggregate to load
      Returns:
      The aggregate root with the given identifier.
      Throws:
      AggregateNotFoundException - if aggregate with given id cannot be found
    • load

      Aggregate<T> load(@Nonnull String aggregateIdentifier, @Nullable Long expectedVersion)
      Load the aggregate with the given unique identifier.
      Parameters:
      aggregateIdentifier - The identifier of the aggregate to load
      expectedVersion - The expected version of the loaded aggregate
      Returns:
      The aggregate root with the given identifier.
      Throws:
      AggregateNotFoundException - if aggregate with given id cannot be found
    • newInstance

      Aggregate<T> newInstance(@Nonnull Callable<T> factoryMethod) throws Exception
      Creates a new managed instance for the aggregate, using the given factoryMethod to instantiate the aggregate's root.
      Parameters:
      factoryMethod - The method to create the aggregate's root instance
      Returns:
      an Aggregate instance describing the aggregate's state
      Throws:
      Exception - when the factoryMethod throws an exception
    • newInstance

      default Aggregate<T> newInstance(Callable<T> factoryMethod, Consumer<Aggregate<T>> initMethod) throws Exception
      Creates a new managed instance for the aggregate, using the given factoryMethod to instantiate the aggregate's root, and then applying the initMethod consumer to it to perform additional initialization.
      Parameters:
      factoryMethod - The method to create the aggregate's root instance
      initMethod - The consumer to initialize the aggregate instance further
      Returns:
      an Aggregate instance describing the aggregate's state
      Throws:
      Exception - when the factoryMethod throws an exception
    • loadOrCreate

      default Aggregate<T> loadOrCreate(@Nonnull String aggregateIdentifier, @Nonnull Callable<T> factoryMethod) throws Exception
      Loads an aggregate from the repository. If the aggregate is not found it creates the aggregate using the specified factoryMethod.
      Parameters:
      aggregateIdentifier - The identifier of the aggregate to load
      factoryMethod - The method to create the aggregate's root instance
      Returns:
      The aggregate root with the given identifier.
      Throws:
      Exception