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
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 TypeMethodDescriptionLoad the aggregate with the given unique identifier.Load the aggregate with the given unique identifier.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 givenfactoryMethodto instantiate the aggregate's root.Creates a new managed instance for the aggregate, using the givenfactoryMethodto instantiate the aggregate's root, and then applying theinitMethodconsumer to it to perform additional initialization.Methods inherited from interface org.axonframework.messaging.ScopeAware
canResolve, send
-
Method Details
-
load
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
Load the aggregate with the given unique identifier.- Parameters:
aggregateIdentifier- The identifier of the aggregate to loadexpectedVersion- 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
Creates a new managed instance for the aggregate, using the givenfactoryMethodto 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 givenfactoryMethodto instantiate the aggregate's root, and then applying theinitMethodconsumer to it to perform additional initialization.- Parameters:
factoryMethod- The method to create the aggregate's root instanceinitMethod- 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 specifiedfactoryMethod.- Parameters:
aggregateIdentifier- The identifier of the aggregate to loadfactoryMethod- The method to create the aggregate's root instance- Returns:
- The aggregate root with the given identifier.
- Throws:
Exception
-