Class EventSourcingRepository.Builder<T>
- Type Parameters:
T- a generic specifying the Aggregate type contained in thisRepositoryimplementation
- Enclosing class:
EventSourcingRepository<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,
RepositorySpanFactory is defaulted to a
DefaultRepositorySpanFactory backed by a
NoOpSpanFactory 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Cacheprotected EventStoreprotected Predicate<? super DomainEventMessage<?>> protected RepositoryProviderprotected SnapshotTriggerDefinitionFields inherited from class org.axonframework.modelling.command.AbstractRepository.Builder
aggregateType, subtypes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaggregateFactory(AggregateFactory<T> aggregateFactory) Sets theAggregateFactoryused to create new Aggregate instances.aggregateModel(AggregateModel<T> aggregateModel) Sets theAggregateModelof generic typeT, describing the structure of the aggregate thisRepositorywill store.<R extends EventSourcingRepository<T>>
Rbuild()Initializes aEventSourcingRepositoryorCachingEventSourcingRepositoryas specified through this Builder.Sets theCachewhich services repositories for specific aggregate types.eventStore(EventStore eventStore) Sets theEventStorethat holds the event stream this repository needs to event source an Aggregate.eventStreamFilter(Predicate<? super DomainEventMessage<?>> filter) Sets thePredicateused to filter events when reading from the EventStore.Configures a filter that rejects events with a different Aggregate type than the one specified by this Repository'sAggregateModel.handlerDefinition(HandlerDefinition handlerDefinition) Sets theHandlerDefinitionused to create concrete handlers for the givenaggregateType.lockFactory(LockFactory lockFactory) Sets theLockFactoryused to lock an aggregate.parameterResolverFactory(ParameterResolverFactory parameterResolverFactory) Sets theParameterResolverFactoryused to resolve parameters for annotated handlers contained in the Aggregate.repositoryProvider(RepositoryProvider repositoryProvider) Sets theRepositoryProviderwhich services repositories for specific aggregate types.snapshotTriggerDefinition(SnapshotTriggerDefinition snapshotTriggerDefinition) Sets theSnapshotTriggerDefinitionspecifying when to trigger a snapshot for an Aggregate contained in this repository.spanFactory(RepositorySpanFactory spanFactory) Sets theRepositorySpanFactoryimplementation to use for providing tracing capabilities.spanFactory(SpanFactory spanFactory) Deprecated.Sets a subtype of theaggregate typerepresented by thisRepository.Sets the subtypes of theaggregate typerepresented by thisRepository.protected voidvalidate()Validates whether the fields contained in this Builder are set accordingly.Methods inherited from class org.axonframework.modelling.command.AbstractRepository.Builder
buildAggregateModel
-
Field Details
-
eventStore
-
snapshotTriggerDefinition
-
repositoryProvider
-
cache
-
eventStreamFilter
-
-
Constructor Details
-
Builder
Creates a builder for a Repository for givenaggregateType.- Parameters:
aggregateType- theaggregateTypespecifying the type of aggregate thisRepositorywill store
-
-
Method Details
-
parameterResolverFactory
public EventSourcingRepository.Builder<T> parameterResolverFactory(@Nonnull ParameterResolverFactory parameterResolverFactory) Description copied from class:AbstractRepository.BuilderSets theParameterResolverFactoryused to resolve parameters for annotated handlers contained in the Aggregate. Only used if theaggregateTypeapproach is selected to create anAggregateModel.- Overrides:
parameterResolverFactoryin classLockingRepository.Builder<T>- Parameters:
parameterResolverFactory- aParameterResolverFactoryused to resolve parameters for annotated handlers contained in the Aggregate- Returns:
- the current Builder instance, for fluent interfacing
-
handlerDefinition
public EventSourcingRepository.Builder<T> handlerDefinition(@Nonnull HandlerDefinition handlerDefinition) Description copied from class:AbstractRepository.BuilderSets theHandlerDefinitionused to create concrete handlers for the givenaggregateType. Only used if theaggregateTypeapproach is selected to create anAggregateModel.- Overrides:
handlerDefinitionin classLockingRepository.Builder<T>- Parameters:
handlerDefinition- aHandlerDefinitionused to create concrete handlers for the givenaggregateType.- Returns:
- the current Builder instance, for fluent interfacing
-
aggregateModel
Description copied from class:AbstractRepository.BuilderSets theAggregateModelof generic typeT, describing the structure of the aggregate thisRepositorywill store.- Overrides:
aggregateModelin classLockingRepository.Builder<T>- Parameters:
aggregateModel- theAggregateModelof generic typeTof the aggregate thisRepositorywill store- Returns:
- the current Builder instance, for fluent interfacing
-
lockFactory
Sets theLockFactoryused to lock an aggregate. Defaults to a pessimistic locking strategy, implemented in thePessimisticLockFactory. If this Builder is used to instantiate aCachingEventSourcingRepository, do note that an optimistic locking strategy is not compatible with a caching approach.- Overrides:
lockFactoryin classLockingRepository.Builder<T>- Parameters:
lockFactory- aLockFactoryused to lock an aggregate- Returns:
- the current Builder instance, for fluent interfacing
-
subtypes
Description copied from class:AbstractRepository.BuilderSets the subtypes of theaggregate typerepresented by thisRepository. Defining subtypes indicates thisRepositorysupports polymorphic aggregate structure.Only used if the
aggregate modelis not explicitly set. Defaults to an emptySet.- Overrides:
subtypesin classLockingRepository.Builder<T>- Parameters:
subtypes- The subtypes of theaggregate typerepresented by thisRepository.- Returns:
- The current Builder instance, for fluent interfacing.
-
subtype
Description copied from class:AbstractRepository.BuilderSets a subtype of theaggregate typerepresented by thisRepository. Defining a subtype indicates thisRepositorysupports a polymorphic aggregate structure.Only used if the
aggregate modelis not explicitly set.- Overrides:
subtypein classLockingRepository.Builder<T>- Parameters:
subtype- A subtypes of theaggregate typerepresented by thisRepository.- Returns:
- The current Builder instance, for fluent interfacing.
-
spanFactory
Deprecated.Description copied from class:AbstractRepository.BuilderSets theSpanFactoryimplementation to use for providing tracing capabilities. Defaults to aNoOpSpanFactoryby default, which provides no tracing capabilities.- Overrides:
spanFactoryin classLockingRepository.Builder<T>- Parameters:
spanFactory- TheSpanFactoryimplementation- Returns:
- The current Builder instance, for fluent interfacing.
-
spanFactory
Description copied from class:AbstractRepository.BuilderSets theRepositorySpanFactoryimplementation to use for providing tracing capabilities. Defaults to aDefaultRepositorySpanFactorybacked by aNoOpSpanFactory, which provides no tracing capabilities.- Overrides:
spanFactoryin classAbstractRepository.Builder<T>- Parameters:
spanFactory- TheSpanFactoryimplementation- Returns:
- The current Builder instance, for fluent interfacing.
-
eventStore
Sets theEventStorethat holds the event stream this repository needs to event source an Aggregate.- Parameters:
eventStore- anEventStorethat holds the event stream this repository needs to event source an Aggregate- Returns:
- the current Builder instance, for fluent interfacing
-
snapshotTriggerDefinition
public EventSourcingRepository.Builder<T> snapshotTriggerDefinition(SnapshotTriggerDefinition snapshotTriggerDefinition) Sets theSnapshotTriggerDefinitionspecifying when to trigger a snapshot for an Aggregate contained in this repository.- Parameters:
snapshotTriggerDefinition- aSnapshotTriggerDefinitionspecifying when to trigger a snapshot for an Aggregate contained in this repository- Returns:
- the current Builder instance, for fluent interfacing
-
aggregateFactory
Sets theAggregateFactoryused to create new Aggregate instances.- Parameters:
aggregateFactory- theAggregateFactoryused to create new Aggregate instances- Returns:
- the current Builder instance, for fluent interfacing
-
repositoryProvider
Sets theRepositoryProviderwhich services repositories for specific aggregate types.- Parameters:
repositoryProvider- aRepositoryProviderservicing repositories for specific aggregate types- Returns:
- the current Builder instance, for fluent interfacing
-
cache
Sets theCachewhich services repositories for specific aggregate types.- Parameters:
cache- aCacheservicing repositories for specific aggregate types- Returns:
- the current Builder instance, for fluent interfacing
-
eventStreamFilter
public EventSourcingRepository.Builder<T> eventStreamFilter(Predicate<? super DomainEventMessage<?>> filter) Sets thePredicateused to filter events when reading from the EventStore. By default, all events with the Aggregate identifier passed toEventSourcingRepository.readEvents(String)are returned. Calls tofilterByAggregateType()will overwrite this configuration and vice versa.- Parameters:
filter- aPredicatethat may return false to discard events.
-
filterByAggregateType
Configures a filter that rejects events with a different Aggregate type than the one specified by this Repository'sAggregateModel. This may be used to enable multiple Aggregate types to share overlapping Aggregate identifiers. Calls toeventStreamFilter(Predicate)will overwrite this configuration and vice versa.If the caller supplies an explicit
AggregateModelto this Builder, that must be done before calling this method. -
build
Initializes aEventSourcingRepositoryorCachingEventSourcingRepositoryas specified through this Builder. Will return a CachingEventSourcingRepository ifcache(Cache)has been set. Otherwise builds a regular EventSourcingRepository- Type Parameters:
R- a generic extendingEventSourcingRepository, so allowing both an EventSourcingRepository andCachingEventSourcingRepositoryreturn type- Returns:
- a
EventSourcingRepositoryorCachingEventSourcingRepository(ifcache(Cache)has been set) as specified through this Builder
-
validate
protected void validate()Description copied from class:AbstractRepository.BuilderValidates whether the fields contained in this Builder are set accordingly.- Overrides:
validatein classAbstractRepository.Builder<T>
-