Class GenericJpaRepository.Builder<T>
- Type Parameters:
T- a generic specifying the Aggregate type contained in thisRepositoryimplementation
- Enclosing class:
GenericJpaRepository<T>
GenericJpaRepository for aggregate type T.
The LockFactory is defaulted to an NullLockFactory, thus providing no additional locking, the
identifierConverter to Function.identity(), the RepositorySpanFactory defaults to a
DefaultRepositorySpanFactory backed by a NoOpSpanFactory, and sequence
number generation is enabled.
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.
Additionally, the EntityManagerProvider and EventBus are hard requirements and as such
should be provided.
-
Field Summary
Fields inherited from class org.axonframework.modelling.command.AbstractRepository.Builder
aggregateType, subtypes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaggregateModel(AggregateModel<T> aggregateModel) Sets theAggregateModelof generic typeT, describing the structure of the aggregate thisRepositorywill store.build()Initializes aGenericJpaRepositoryas specified through this Builder.Disables sequence number generation within thisRepositoryimplementation.entityManagerProvider(EntityManagerProvider entityManagerProvider) Sets theEntityManagerProviderwhich provides theEntityManagerinstance for this repository.Sets theEventBusto which events are published.handlerDefinition(HandlerDefinition handlerDefinition) Sets theHandlerDefinitionused to create concrete handlers for the givenaggregateType.identifierConverter(Function<String, ?> identifierConverter) 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.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
-
Constructor Details
-
Builder
Creates a builder for a Repository for givenaggregateType.- Parameters:
aggregateType- theaggregateTypespecifying the type of aggregate thisRepositorywill store
-
-
Method Details
-
parameterResolverFactory
public GenericJpaRepository.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 GenericJpaRepository.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
Description copied from class:LockingRepository.BuilderSets theLockFactoryused to lock an aggregate. Defaults to a pessimistic locking strategy, implemented in thePessimisticLockFactory.- 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.
-
entityManagerProvider
public GenericJpaRepository.Builder<T> entityManagerProvider(EntityManagerProvider entityManagerProvider) Sets theEntityManagerProviderwhich provides theEntityManagerinstance for this repository.- Parameters:
entityManagerProvider- aEntityManagerProviderwhich provides theEntityManagerinstance for this repository- Returns:
- the current Builder instance, for fluent interfacing
-
eventBus
Sets theEventBusto which events are published.- Parameters:
eventBus- anEventBusto which events are published- 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
-
identifierConverter
-
disableSequenceNumberGeneration
Disables sequence number generation within thisRepositoryimplementation.Disabling this feature allows reuse of Aggregate identifiers after removal of the Aggregate instance referred to with said identifier. This opportunity arises from the fact that events published within an Aggregate require a sequence number to change into so-called domain events. These domain events are constrained in the Event Store to have a unique combination of Aggregate identifier to sequence number. Thus, when reusing an Aggregate identifier for which sequences were enabled, will have the Event Store complain with this uniqueness constraint.
So disabling sequence number generation will resolve the uniqueness complaints from the Event Store. And, in doing so, allows reuse of an Aggregate identifier.
Disabling sequence number generation comes with another cost, though. The events published within a state-stored Aggregate will no longer refer to the Aggregate they originate from.
- Returns:
- The current Builder instance, for fluent interfacing.
-
build
Initializes aGenericJpaRepositoryas specified through this Builder.- Returns:
- a
GenericJpaRepositoryas 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>
-