T - a generic specifying the Aggregate type contained in this
Repository implementationpublic static class EventSourcingRepository.Builder<T>
extends org.axonframework.modelling.command.AbstractRepository.Builder<T>
EventSourcingRepository. Can also be used to instantiate a
CachingEventSourcingRepository. This Builder will check whether a Cache is provided. If this
holds, the build() function returns a CachingEventSourcingRepository instead of an
EventSourcingRepository.
The LockFactory is defaulted to an PessimisticLockFactory and the
SnapshotTriggerDefinition to a NoSnapshotTriggerDefinition implementation.
A goal of this Builder goal is to create an AggregateModel specifying generic T as the aggregate
type to be stored. All aggregates in this repository must be instanceOf this aggregate type. To
instantiate this AggregateModel, either an AggregateModel can be provided directly or an
aggregateType of type Class can be used. The latter will internally resolve to an AggregateModel.
Thus, either the AggregateModel or the aggregateType should be provided.
The same criteria holds for the AggregateFactory. Either the AggregateFactory can be set directly or it
will be instantiated internally based on the aggregateType. Hence, one of both is a hard requirement.
Additionally, the EventStore is a hard requirement and as such should be provided.
| Modifier and Type | Field and Description |
|---|---|
protected org.axonframework.common.caching.Cache |
cache |
protected EventStore |
eventStore |
protected org.axonframework.modelling.command.RepositoryProvider |
repositoryProvider |
protected SnapshotTriggerDefinition |
snapshotTriggerDefinition |
| Modifier | Constructor and Description |
|---|---|
protected |
Builder(Class<T> aggregateType)
Creates a builder for a Repository for given
aggregateType. |
| Modifier and Type | Method and Description |
|---|---|
EventSourcingRepository.Builder<T> |
aggregateFactory(AggregateFactory<T> aggregateFactory)
Sets the
AggregateFactory used to create new Aggregate instances. |
EventSourcingRepository.Builder<T> |
aggregateModel(org.axonframework.modelling.command.inspection.AggregateModel<T> aggregateModel) |
<R extends EventSourcingRepository<T>> |
build()
Initializes a
EventSourcingRepository or CachingEventSourcingRepository as specified through
this Builder. |
EventSourcingRepository.Builder<T> |
cache(org.axonframework.common.caching.Cache cache)
Sets the
Cache which services repositories for specific aggregate types. |
EventSourcingRepository.Builder<T> |
eventStore(EventStore eventStore)
Sets the
EventStore that holds the event stream this repository needs to event source an Aggregate. |
EventSourcingRepository.Builder<T> |
handlerDefinition(org.axonframework.messaging.annotation.HandlerDefinition handlerDefinition) |
EventSourcingRepository.Builder<T> |
lockFactory(org.axonframework.common.lock.LockFactory lockFactory)
If this Builder is used to instantiate a
CachingEventSourcingRepository, do note that an optimistic
locking strategy is not compatible with a caching approach. |
EventSourcingRepository.Builder<T> |
parameterResolverFactory(org.axonframework.messaging.annotation.ParameterResolverFactory parameterResolverFactory) |
EventSourcingRepository.Builder<T> |
repositoryProvider(org.axonframework.modelling.command.RepositoryProvider repositoryProvider)
Sets the
RepositoryProvider which services repositories for specific aggregate types. |
EventSourcingRepository.Builder<T> |
snapshotTriggerDefinition(SnapshotTriggerDefinition snapshotTriggerDefinition)
Sets the
SnapshotTriggerDefinition specifying when to trigger a snapshot for an Aggregate contained
in this repository. |
protected void |
validate() |
protected EventStore eventStore
protected SnapshotTriggerDefinition snapshotTriggerDefinition
protected org.axonframework.modelling.command.RepositoryProvider repositoryProvider
protected org.axonframework.common.caching.Cache cache
public EventSourcingRepository.Builder<T> parameterResolverFactory(org.axonframework.messaging.annotation.ParameterResolverFactory parameterResolverFactory)
public EventSourcingRepository.Builder<T> handlerDefinition(org.axonframework.messaging.annotation.HandlerDefinition handlerDefinition)
public EventSourcingRepository.Builder<T> aggregateModel(org.axonframework.modelling.command.inspection.AggregateModel<T> aggregateModel)
public EventSourcingRepository.Builder<T> lockFactory(org.axonframework.common.lock.LockFactory lockFactory)
CachingEventSourcingRepository, do note that an optimistic
locking strategy is not compatible with a caching approach.public EventSourcingRepository.Builder<T> eventStore(EventStore eventStore)
EventStore that holds the event stream this repository needs to event source an Aggregate.eventStore - an EventStore that holds the event stream this repository needs to event source
an Aggregatepublic EventSourcingRepository.Builder<T> snapshotTriggerDefinition(SnapshotTriggerDefinition snapshotTriggerDefinition)
SnapshotTriggerDefinition specifying when to trigger a snapshot for an Aggregate contained
in this repository.snapshotTriggerDefinition - a SnapshotTriggerDefinition specifying when to trigger a snapshot
for an Aggregate contained in this repositorypublic EventSourcingRepository.Builder<T> aggregateFactory(AggregateFactory<T> aggregateFactory)
AggregateFactory used to create new Aggregate instances.aggregateFactory - the AggregateFactory used to create new Aggregate instancespublic EventSourcingRepository.Builder<T> repositoryProvider(org.axonframework.modelling.command.RepositoryProvider repositoryProvider)
RepositoryProvider which services repositories for specific aggregate types.repositoryProvider - a RepositoryProvider servicing repositories for specific aggregate typespublic EventSourcingRepository.Builder<T> cache(org.axonframework.common.caching.Cache cache)
Cache which services repositories for specific aggregate types.cache - a Cache servicing repositories for specific aggregate typespublic <R extends EventSourcingRepository<T>> R build()
EventSourcingRepository or CachingEventSourcingRepository as specified through
this Builder. Will return a CachingEventSourcingRepository if cache(Cache) has been set. Otherwise
builds a regular EventSourcingRepositoryR - a generic extending EventSourcingRepository, so allowing both an EventSourcingRepository
and CachingEventSourcingRepository return typeEventSourcingRepository or CachingEventSourcingRepository (if cache(Cache)
has been set) as specified through this Builderprotected void validate()
validate in class org.axonframework.modelling.command.AbstractRepository.Builder<T>Copyright © 2010–2019. All rights reserved.