T
- a generic specifying the Aggregate type contained in this
Repository
implementationpublic static class EventSourcingRepository.Builder<T> extends LockingRepository.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 Cache |
cache |
protected EventStore |
eventStore |
protected Predicate<? super DomainEventMessage<?>> |
eventStreamFilter |
protected RepositoryProvider |
repositoryProvider |
protected SnapshotTriggerDefinition |
snapshotTriggerDefinition |
aggregateType
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(AggregateModel<T> aggregateModel)
Sets the
AggregateModel of generic type T , describing the structure of the aggregate this
Repository will store. |
<R extends EventSourcingRepository<T>> |
build()
Initializes a
EventSourcingRepository or CachingEventSourcingRepository as specified through
this Builder. |
EventSourcingRepository.Builder<T> |
cache(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> |
eventStreamFilter(Predicate<? super DomainEventMessage<?>> filter)
Sets the
Predicate used to filter events when reading from the EventStore. |
EventSourcingRepository.Builder<T> |
filterByAggregateType()
Configures a filter that rejects events with a different Aggregate type than the one specified by this
Repository's
AggregateModel . |
EventSourcingRepository.Builder<T> |
handlerDefinition(HandlerDefinition handlerDefinition)
Sets the
HandlerDefinition used to create concrete handlers for the given aggregateType . |
EventSourcingRepository.Builder<T> |
lockFactory(LockFactory lockFactory)
Sets the
LockFactory used to lock an aggregate. |
EventSourcingRepository.Builder<T> |
parameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
Sets the
ParameterResolverFactory used to resolve parameters for annotated handlers contained in the
Aggregate. |
EventSourcingRepository.Builder<T> |
repositoryProvider(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()
Validates whether the fields contained in this Builder are set accordingly.
|
buildAggregateModel
protected EventStore eventStore
protected SnapshotTriggerDefinition snapshotTriggerDefinition
protected RepositoryProvider repositoryProvider
protected Cache cache
protected Predicate<? super DomainEventMessage<?>> eventStreamFilter
protected Builder(Class<T> aggregateType)
aggregateType
.aggregateType
- the aggregateType
specifying the type of aggregate this Repository
will
storepublic EventSourcingRepository.Builder<T> parameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
AbstractRepository.Builder
ParameterResolverFactory
used to resolve parameters for annotated handlers contained in the
Aggregate. Only used if the aggregateType
approach is selected to create an AggregateModel
.parameterResolverFactory
in class LockingRepository.Builder<T>
parameterResolverFactory
- a ParameterResolverFactory
used to resolve parameters for annotated
handlers contained in the Aggregatepublic EventSourcingRepository.Builder<T> handlerDefinition(HandlerDefinition handlerDefinition)
AbstractRepository.Builder
HandlerDefinition
used to create concrete handlers for the given aggregateType
.
Only used if the aggregateType
approach is selected to create an AggregateModel
.handlerDefinition
in class LockingRepository.Builder<T>
handlerDefinition
- a HandlerDefinition
used to create concrete handlers for the given
aggregateType
.public EventSourcingRepository.Builder<T> aggregateModel(AggregateModel<T> aggregateModel)
AbstractRepository.Builder
AggregateModel
of generic type T
, describing the structure of the aggregate this
Repository
will store.aggregateModel
in class LockingRepository.Builder<T>
aggregateModel
- the AggregateModel
of generic type T
of the aggregate this
Repository
will storepublic EventSourcingRepository.Builder<T> lockFactory(LockFactory lockFactory)
LockFactory
used to lock an aggregate. Defaults to a pessimistic locking strategy,
implemented in the PessimisticLockFactory
.
If this Builder is used to instantiate a CachingEventSourcingRepository
, do note that an optimistic
locking strategy is not compatible with a caching approach.lockFactory
in class LockingRepository.Builder<T>
lockFactory
- a LockFactory
used to lock an aggregatepublic 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(RepositoryProvider repositoryProvider)
RepositoryProvider
which services repositories for specific aggregate types.repositoryProvider
- a RepositoryProvider
servicing repositories for specific aggregate typespublic EventSourcingRepository.Builder<T> cache(Cache cache)
Cache
which services repositories for specific aggregate types.cache
- a Cache
servicing repositories for specific aggregate typespublic EventSourcingRepository.Builder<T> eventStreamFilter(Predicate<? super DomainEventMessage<?>> filter)
Predicate
used to filter events when reading from the EventStore. By default, all
events with the Aggregate identifier passed to EventSourcingRepository.readEvents(String)
are
returned. Calls to filterByAggregateType()
will overwrite this configuration and vice versa.filter
- a Predicate
that may return false to discard events.public EventSourcingRepository.Builder<T> filterByAggregateType()
AggregateModel
. This may be used to enable multiple Aggregate types to share
overlapping Aggregate identifiers. Calls to eventStreamFilter(Predicate)
will overwrite this configuration
and vice versa.
If the caller supplies an explicit AggregateModel
to this Builder, that must be done before
calling this method.
public <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()
AbstractRepository.Builder
validate
in class AbstractRepository.Builder<T>
Copyright © 2010–2022. All rights reserved.