Class GenericJpaRepository.Builder<T>

Type Parameters:
T - a generic specifying the Aggregate type contained in this Repository implementation
Enclosing class:
GenericJpaRepository<T>

public static class GenericJpaRepository.Builder<T> extends LockingRepository.Builder<T>
Builder class to instantiate a 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.

  • Constructor Details

    • Builder

      protected Builder(Class<T> aggregateType)
      Creates a builder for a Repository for given aggregateType.
      Parameters:
      aggregateType - the aggregateType specifying the type of aggregate this Repository will store
  • Method Details

    • parameterResolverFactory

      public GenericJpaRepository.Builder<T> parameterResolverFactory(@Nonnull org.axonframework.messaging.annotation.ParameterResolverFactory parameterResolverFactory)
      Description copied from class: AbstractRepository.Builder
      Sets the ParameterResolverFactory used to resolve parameters for annotated handlers contained in the Aggregate. Only used if the aggregateType approach is selected to create an AggregateModel.
      Overrides:
      parameterResolverFactory in class LockingRepository.Builder<T>
      Parameters:
      parameterResolverFactory - a ParameterResolverFactory used 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 org.axonframework.messaging.annotation.HandlerDefinition handlerDefinition)
      Description copied from class: AbstractRepository.Builder
      Sets the HandlerDefinition used to create concrete handlers for the given aggregateType. Only used if the aggregateType approach is selected to create an AggregateModel.
      Overrides:
      handlerDefinition in class LockingRepository.Builder<T>
      Parameters:
      handlerDefinition - a HandlerDefinition used to create concrete handlers for the given aggregateType.
      Returns:
      the current Builder instance, for fluent interfacing
    • aggregateModel

      public GenericJpaRepository.Builder<T> aggregateModel(@Nonnull AggregateModel<T> aggregateModel)
      Description copied from class: AbstractRepository.Builder
      Sets the AggregateModel of generic type T, describing the structure of the aggregate this Repository will store.
      Overrides:
      aggregateModel in class LockingRepository.Builder<T>
      Parameters:
      aggregateModel - the AggregateModel of generic type T of the aggregate this Repository will store
      Returns:
      the current Builder instance, for fluent interfacing
    • lockFactory

      public GenericJpaRepository.Builder<T> lockFactory(org.axonframework.common.lock.LockFactory lockFactory)
      Description copied from class: LockingRepository.Builder
      Sets the LockFactory used to lock an aggregate. Defaults to a pessimistic locking strategy, implemented in the PessimisticLockFactory.
      Overrides:
      lockFactory in class LockingRepository.Builder<T>
      Parameters:
      lockFactory - a LockFactory used to lock an aggregate
      Returns:
      the current Builder instance, for fluent interfacing
    • subtypes

      public GenericJpaRepository.Builder<T> subtypes(@Nonnull Set<Class<? extends T>> subtypes)
      Description copied from class: AbstractRepository.Builder
      Sets the subtypes of the 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.

      Overrides:
      subtypes in class LockingRepository.Builder<T>
      Parameters:
      subtypes - The subtypes of the aggregate type represented by this Repository.
      Returns:
      The current Builder instance, for fluent interfacing.
    • subtype

      public GenericJpaRepository.Builder<T> subtype(@Nonnull Class<? extends T> subtype)
      Description copied from class: AbstractRepository.Builder
      Sets a subtype of the 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.

      Overrides:
      subtype in class LockingRepository.Builder<T>
      Parameters:
      subtype - A subtypes of the aggregate type represented by this Repository.
      Returns:
      The current Builder instance, for fluent interfacing.
    • spanFactory

      @Deprecated public GenericJpaRepository.Builder<T> spanFactory(org.axonframework.tracing.SpanFactory spanFactory)
      Deprecated.
      Description copied from class: AbstractRepository.Builder
      Sets the SpanFactory implementation to use for providing tracing capabilities. Defaults to a NoOpSpanFactory by default, which provides no tracing capabilities.
      Overrides:
      spanFactory in class LockingRepository.Builder<T>
      Parameters:
      spanFactory - The SpanFactory implementation
      Returns:
      The current Builder instance, for fluent interfacing.
    • spanFactory

      public GenericJpaRepository.Builder<T> spanFactory(RepositorySpanFactory spanFactory)
      Description copied from class: AbstractRepository.Builder
      Sets the RepositorySpanFactory implementation to use for providing tracing capabilities. Defaults to a DefaultRepositorySpanFactory backed by a NoOpSpanFactory, which provides no tracing capabilities.
      Overrides:
      spanFactory in class AbstractRepository.Builder<T>
      Parameters:
      spanFactory - The SpanFactory implementation
      Returns:
      The current Builder instance, for fluent interfacing.
    • entityManagerProvider

      public GenericJpaRepository.Builder<T> entityManagerProvider(org.axonframework.common.jpa.EntityManagerProvider entityManagerProvider)
      Sets the EntityManagerProvider which provides the EntityManager instance for this repository.
      Parameters:
      entityManagerProvider - a EntityManagerProvider which provides the EntityManager instance for this repository
      Returns:
      the current Builder instance, for fluent interfacing
    • eventBus

      public GenericJpaRepository.Builder<T> eventBus(org.axonframework.eventhandling.EventBus eventBus)
      Sets the EventBus to which events are published.
      Parameters:
      eventBus - an EventBus to which events are published
      Returns:
      the current Builder instance, for fluent interfacing
    • repositoryProvider

      public GenericJpaRepository.Builder<T> repositoryProvider(RepositoryProvider repositoryProvider)
      Sets the RepositoryProvider which services repositories for specific aggregate types.
      Parameters:
      repositoryProvider - a RepositoryProvider servicing repositories for specific aggregate types
      Returns:
      the current Builder instance, for fluent interfacing
    • identifierConverter

      public GenericJpaRepository.Builder<T> identifierConverter(Function<String,?> identifierConverter)
      Sets the Function which converts a String based identifier to the Identifier object used in the Entity.
      Parameters:
      identifierConverter - a Function of input type String and return type ? which converts the String based identifier to the Identifier object used in the Entity
      Returns:
      the current Builder instance, for fluent interfacing
    • disableSequenceNumberGeneration

      public GenericJpaRepository.Builder<T> disableSequenceNumberGeneration()
      Disables sequence number generation within this 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.

      Returns:
      The current Builder instance, for fluent interfacing.
    • build

      public GenericJpaRepository<T> build()
      Initializes a GenericJpaRepository as specified through this Builder.
      Returns:
      a GenericJpaRepository as specified through this Builder
    • validate

      protected void validate()
      Description copied from class: AbstractRepository.Builder
      Validates whether the fields contained in this Builder are set accordingly.
      Overrides:
      validate in class AbstractRepository.Builder<T>