T
- a generic specifying the Aggregate type contained in this Repository
implementationpublic static class GenericJpaRepository.Builder<T> extends LockingRepository.Builder<T>
GenericJpaRepository
for aggregate type T
.
The LockFactory
is defaulted to an NullLockFactory
, thus providing no additional locking, and the
identifierConverter
to Function.identity()
. The RepositorySpanFactory
is defaulted to a
DefaultRepositorySpanFactory
backed by a
NoOpSpanFactory
.
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.
aggregateType, subtypes
Modifier | Constructor and Description |
---|---|
protected |
Builder(Class<T> aggregateType)
Creates a builder for a Repository for given
aggregateType . |
Modifier and Type | Method and Description |
---|---|
GenericJpaRepository.Builder<T> |
aggregateModel(AggregateModel<T> aggregateModel)
Sets the
AggregateModel of generic type T , describing the structure of the aggregate this
Repository will store. |
GenericJpaRepository<T> |
build()
Initializes a
GenericJpaRepository as specified through this Builder. |
GenericJpaRepository.Builder<T> |
disableSequenceNumberGeneration()
Disables sequence number generation within this
Repository implementation. |
GenericJpaRepository.Builder<T> |
entityManagerProvider(EntityManagerProvider entityManagerProvider)
Sets the
EntityManagerProvider which provides the EntityManager instance for this
repository. |
GenericJpaRepository.Builder<T> |
eventBus(EventBus eventBus)
Sets the
EventBus to which events are published. |
GenericJpaRepository.Builder<T> |
handlerDefinition(HandlerDefinition handlerDefinition)
Sets the
HandlerDefinition used to create concrete handlers for the given aggregateType . |
GenericJpaRepository.Builder<T> |
identifierConverter(Function<String,?> identifierConverter)
|
GenericJpaRepository.Builder<T> |
lockFactory(LockFactory lockFactory)
Sets the
LockFactory used to lock an aggregate. |
GenericJpaRepository.Builder<T> |
parameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
Sets the
ParameterResolverFactory used to resolve parameters for annotated handlers contained in the
Aggregate. |
GenericJpaRepository.Builder<T> |
repositoryProvider(RepositoryProvider repositoryProvider)
Sets the
RepositoryProvider which services repositories for specific aggregate types. |
GenericJpaRepository.Builder<T> |
spanFactory(RepositorySpanFactory spanFactory)
Sets the
RepositorySpanFactory implementation to use for providing tracing capabilities. |
GenericJpaRepository.Builder<T> |
spanFactory(SpanFactory spanFactory)
Deprecated.
|
GenericJpaRepository.Builder<T> |
subtype(Class<? extends T> subtype)
Sets a subtype of the
aggregate type represented by this Repository . |
GenericJpaRepository.Builder<T> |
subtypes(Set<Class<? extends T>> subtypes)
Sets the subtypes of the
aggregate type represented by this Repository . |
protected void |
validate()
Validates whether the fields contained in this Builder are set accordingly.
|
buildAggregateModel
protected Builder(Class<T> aggregateType)
aggregateType
.aggregateType
- the aggregateType
specifying the type of aggregate this Repository
will
storepublic GenericJpaRepository.Builder<T> parameterResolverFactory(@Nonnull 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 GenericJpaRepository.Builder<T> handlerDefinition(@Nonnull 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 GenericJpaRepository.Builder<T> aggregateModel(@Nonnull 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 GenericJpaRepository.Builder<T> lockFactory(LockFactory lockFactory)
LockingRepository.Builder
LockFactory
used to lock an aggregate. Defaults to a pessimistic locking strategy,
implemented in the PessimisticLockFactory
.lockFactory
in class LockingRepository.Builder<T>
lockFactory
- a LockFactory
used to lock an aggregatepublic GenericJpaRepository.Builder<T> subtypes(@Nonnull Set<Class<? extends T>> subtypes)
AbstractRepository.Builder
aggregate type
represented by this Repository
.
Defining subtypes indicates this Repository
supports polymorphic aggregate structure.
Only used if the aggregate model
is not explicitly set. Defaults to
an empty Set
.
subtypes
in class LockingRepository.Builder<T>
subtypes
- The subtypes of the aggregate type
represented by this
Repository
.public GenericJpaRepository.Builder<T> subtype(@Nonnull Class<? extends T> subtype)
AbstractRepository.Builder
aggregate type
represented by this Repository
.
Defining a subtype indicates this Repository
supports a polymorphic aggregate structure.
Only used if the aggregate model
is not explicitly set.
subtype
in class LockingRepository.Builder<T>
subtype
- A subtypes of the aggregate type
represented by this
Repository
.@Deprecated public GenericJpaRepository.Builder<T> spanFactory(SpanFactory spanFactory)
AbstractRepository.Builder
SpanFactory
implementation to use for providing tracing capabilities. Defaults to a
NoOpSpanFactory
by default, which provides no tracing capabilities.spanFactory
in class LockingRepository.Builder<T>
spanFactory
- The SpanFactory
implementationpublic GenericJpaRepository.Builder<T> spanFactory(RepositorySpanFactory spanFactory)
AbstractRepository.Builder
RepositorySpanFactory
implementation to use for providing tracing capabilities. Defaults to a
DefaultRepositorySpanFactory
backed by a NoOpSpanFactory
, which provides no tracing capabilities.spanFactory
in class AbstractRepository.Builder<T>
spanFactory
- The SpanFactory
implementationpublic GenericJpaRepository.Builder<T> entityManagerProvider(EntityManagerProvider entityManagerProvider)
EntityManagerProvider
which provides the EntityManager
instance for this
repository.entityManagerProvider
- a EntityManagerProvider
which provides the EntityManager
instance for this repositorypublic GenericJpaRepository.Builder<T> eventBus(EventBus eventBus)
EventBus
to which events are published.eventBus
- an EventBus
to which events are publishedpublic GenericJpaRepository.Builder<T> repositoryProvider(RepositoryProvider repositoryProvider)
RepositoryProvider
which services repositories for specific aggregate types.repositoryProvider
- a RepositoryProvider
servicing repositories for specific aggregate typespublic GenericJpaRepository.Builder<T> identifierConverter(Function<String,?> identifierConverter)
public GenericJpaRepository.Builder<T> disableSequenceNumberGeneration()
Repository
implementation.
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.
public GenericJpaRepository<T> build()
GenericJpaRepository
as specified through this Builder.GenericJpaRepository
as specified through this Builderprotected void validate()
AbstractRepository.Builder
validate
in class AbstractRepository.Builder<T>
Copyright © 2010–2024. All rights reserved.