T
- The type of aggregate this repository stores.public interface Repository<T> extends ScopeAware
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.
Modifier and Type | Method and Description |
---|---|
Aggregate<T> |
load(String aggregateIdentifier)
Load the aggregate with the given unique identifier.
|
Aggregate<T> |
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.
|
Aggregate<T> |
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. |
canResolve, send
Aggregate<T> load(@Nonnull String aggregateIdentifier)
aggregateIdentifier
- The identifier of the aggregate to loadAggregateNotFoundException
- if aggregate with given id cannot be foundAggregate<T> load(@Nonnull String aggregateIdentifier, @Nullable Long expectedVersion)
aggregateIdentifier
- The identifier of the aggregate to loadexpectedVersion
- The expected version of the loaded aggregateAggregateNotFoundException
- if aggregate with given id cannot be foundAggregate<T> newInstance(@Nonnull Callable<T> factoryMethod) throws Exception
factoryMethod
to instantiate the aggregate's root.factoryMethod
- The method to create the aggregate's root instanceException
- when the factoryMethod throws an exceptiondefault Aggregate<T> newInstance(Callable<T> factoryMethod, Consumer<Aggregate<T>> initMethod) throws Exception
factoryMethod
to instantiate the
aggregate's root, and then applying the initMethod
consumer to it to perform additional
initialization.factoryMethod
- The method to create the aggregate's root instanceinitMethod
- The consumer to initialize the aggregate instance furtherException
- when the factoryMethod throws an exceptiondefault Aggregate<T> loadOrCreate(@Nonnull String aggregateIdentifier, @Nonnull Callable<T> factoryMethod) throws Exception
factoryMethod
.aggregateIdentifier
- The identifier of the aggregate to loadfactoryMethod
- The method to create the aggregate's root instanceException
Copyright © 2010–2024. All rights reserved.