Class JpaEventStorageEngine.Builder

Enclosing class:
JpaEventStorageEngine

public static class JpaEventStorageEngine.Builder extends BatchingEventStorageEngine.Builder
Builder class to instantiate a JpaEventStorageEngine.

The following configurable fields have defaults:

The event and snapshot Serializer, the EntityManagerProvider and TransactionManager are hard requirements and as such should be provided.

  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • snapshotSerializer

      public JpaEventStorageEngine.Builder snapshotSerializer(Serializer snapshotSerializer)
      Description copied from class: AbstractEventStorageEngine.Builder
      Sets the Serializer used to serialize and deserialize snapshots.
      Overrides:
      snapshotSerializer in class BatchingEventStorageEngine.Builder
      Parameters:
      snapshotSerializer - a Serializer used to serialize and deserialize snapshots
      Returns:
      the current Builder instance, for fluent interfacing
    • upcasterChain

      public JpaEventStorageEngine.Builder upcasterChain(EventUpcaster upcasterChain)
      Description copied from class: AbstractEventStorageEngine.Builder
      Sets the EventUpcaster used to deserialize events of older revisions. Defaults to a NoOpEventUpcaster.
      Overrides:
      upcasterChain in class BatchingEventStorageEngine.Builder
      Parameters:
      upcasterChain - an EventUpcaster used to deserialize events of older revisions
      Returns:
      the current Builder instance, for fluent interfacing
    • persistenceExceptionResolver

      public JpaEventStorageEngine.Builder persistenceExceptionResolver(PersistenceExceptionResolver persistenceExceptionResolver)
      Description copied from class: AbstractEventStorageEngine.Builder
      Sets the PersistenceExceptionResolver used to detect concurrency exceptions from the backing database. If the persistenceExceptionResolver is not specified, persistence exceptions are not explicitly resolved.
      Overrides:
      persistenceExceptionResolver in class BatchingEventStorageEngine.Builder
      Parameters:
      persistenceExceptionResolver - the PersistenceExceptionResolver used to detect concurrency exceptions from the backing database
      Returns:
      the current Builder instance, for fluent interfacing
    • eventSerializer

      public JpaEventStorageEngine.Builder eventSerializer(Serializer eventSerializer)
      Description copied from class: AbstractEventStorageEngine.Builder
      Sets the Serializer used to serialize and deserialize the Event Message's payload and MetaData with.
      Overrides:
      eventSerializer in class BatchingEventStorageEngine.Builder
      Parameters:
      eventSerializer - The serializer to serialize the Event Message's payload and MetaData with
      Returns:
      the current Builder instance, for fluent interfacing
    • finalAggregateBatchPredicate

      public JpaEventStorageEngine.Builder finalAggregateBatchPredicate(Predicate<List<? extends DomainEventData<?>>> finalAggregateBatchPredicate)
      Defines the predicate to use to recognize the terminal batch when reading an event stream for an aggregate. The default behavior is implementation-specific.

      The JpaEventStorageEngine defaults to using any batch smaller than the batch size as the final batch.

      Overrides:
      finalAggregateBatchPredicate in class BatchingEventStorageEngine.Builder
      Parameters:
      finalAggregateBatchPredicate - The predicate that indicates whether a given batch is to be considered the final batch of an event stream.
      Returns:
      the current Builder instance, for fluent interfacing
    • snapshotFilter

      @Deprecated public JpaEventStorageEngine.Builder snapshotFilter(Predicate<? super DomainEventData<?>> snapshotFilter)
      Deprecated.
      Sets the snapshotFilter deciding whether to take a snapshot into account. Can be set to filter out specific snapshot revisions which should not be applied. Defaults to a Predicate which returns true regardless.
      Overrides:
      snapshotFilter in class BatchingEventStorageEngine.Builder
      Parameters:
      snapshotFilter - a Predicate which decides whether to take a snapshot into account
      Returns:
      the current Builder instance, for fluent interfacing
    • snapshotFilter

      public JpaEventStorageEngine.Builder snapshotFilter(SnapshotFilter snapshotFilter)
      Description copied from class: AbstractEventStorageEngine.Builder
      Sets the snapshotFilter deciding whether to take a snapshot into account. Can be set to filter out specific snapshot revisions which should not be applied. Defaults to SnapshotFilter.allowAll().

      Note that SnapshotFilter instances can be combined and should return true if they handle a snapshot they wish to ignore.

      Overrides:
      snapshotFilter in class BatchingEventStorageEngine.Builder
      Parameters:
      snapshotFilter - a SnapshotFilter which decides whether to take a snapshot into account
      Returns:
      the current Builder instance, for fluent interfacing
    • batchSize

      public JpaEventStorageEngine.Builder batchSize(int batchSize)
      Description copied from class: BatchingEventStorageEngine.Builder
      Sets the batchSize specifying the number of events that should be read at each database access. When more than this number of events must be read to rebuild an aggregate's state, the events are read in batches of this size. Defaults to an integer of 100.

      Tip: if you use a snapshotter, make sure to choose snapshot trigger and batch size such that a single batch will generally retrieve all events required to rebuild an aggregate's state.

      Overrides:
      batchSize in class BatchingEventStorageEngine.Builder
      Parameters:
      batchSize - an int specifying the number of events that should be read at each database access
      Returns:
      the current Builder instance, for fluent interfacing
    • dataSource

      public JpaEventStorageEngine.Builder dataSource(DataSource dataSource) throws SQLException
      Sets the PersistenceExceptionResolver as a SQLErrorCodesResolver, using the provided DataSource to resolve the error codes. Note that the provided DataSource sole purpose in this EventStorageEngine implementation is to be used for instantiating the PersistenceExceptionResolver.
      Parameters:
      dataSource - the DataSource used to instantiate a SQLErrorCodesResolver(DataSource) as the PersistenceExceptionResolver
      Returns:
      the current Builder instance, for fluent interfacing
      Throws:
      SQLException - if creation of the SQLErrorCodesResolver fails
    • entityManagerProvider

      public JpaEventStorageEngine.Builder entityManagerProvider(EntityManagerProvider entityManagerProvider)
      Sets the EntityManagerProvider which provides the EntityManager used to access the underlying database for this EventStorageEngine implementation.
      Parameters:
      entityManagerProvider - a EntityManagerProvider which provides the EntityManager used to access the underlying database
      Returns:
      the current Builder instance, for fluent interfacing
    • transactionManager

      public JpaEventStorageEngine.Builder transactionManager(TransactionManager transactionManager)
      Sets the TransactionManager used to manage transaction around fetching event data. Required by certain databases for reading blob data.
      Parameters:
      transactionManager - a TransactionManager used to manage transaction around fetching event data
      Returns:
      the current Builder instance, for fluent interfacing
    • explicitFlush

      public JpaEventStorageEngine.Builder explicitFlush(boolean explicitFlush)
      Sets the explicitFlush field specifying whether to explicitly call EntityManager.flush() after inserting the Events published in this Unit of Work. If false, this instance relies on the TransactionManager to flush data. Note that the persistenceExceptionResolver may not be able to translate exceptions anymore. false should only be used to optimize performance for batch operations. In other cases, true is recommended, which is also the default.
      Parameters:
      explicitFlush - a boolean specifying whether to explicitly call EntityManager.flush() after inserting the Events published in this Unit of Work
      Returns:
      the current Builder instance, for fluent interfacing
    • maxGapOffset

      public JpaEventStorageEngine.Builder maxGapOffset(int maxGapOffset)
      Sets the maxGapOffset specifying the maximum distance in sequence numbers between a missing event and the event with the highest known index. If the gap is bigger it is assumed that the missing event will not be committed to the store anymore. This event storage engine will no longer look for those events the next time a batch is fetched. Defaults to an integer of 10000 (JpaEventStorageEngine.DEFAULT_MAX_GAP_OFFSET.
      Parameters:
      maxGapOffset - an int specifying the maximum distance in sequence numbers between a missing event and the event with the highest known index
      Returns:
      the current Builder instance, for fluent interfacing
    • lowestGlobalSequence

      public JpaEventStorageEngine.Builder lowestGlobalSequence(long lowestGlobalSequence)
      Sets the lowestGlobalSequence specifying the first expected auto generated sequence number. For most data stores this is 1 unless the table has contained entries before. Defaults to a long of 1 (JpaEventStorageEngine.DEFAULT_LOWEST_GLOBAL_SEQUENCE).
      Parameters:
      lowestGlobalSequence - a long specifying the first expected auto generated sequence number
      Returns:
      the current Builder instance, for fluent interfacing
    • gapTimeout

      public JpaEventStorageEngine.Builder gapTimeout(int gapTimeout)
      Sets the amount of time until a 'gap' in a TrackingToken may be considered timed out. This setting will affect the cleaning process of gaps. Gaps that have timed out will be removed from Tracking Tokens to improve performance of reading events. Defaults to an integer of 60000 (JpaEventStorageEngine.DEFAULT_GAP_TIMEOUT), thus 1 minute.
      Parameters:
      gapTimeout - an int specifying the amount of time in milliseconds until a 'gap' in a TrackingToken may be considered timed out
      Returns:
      the current Builder instance, for fluent interfacing
    • gapCleaningThreshold

      public JpaEventStorageEngine.Builder gapCleaningThreshold(int gapCleaningThreshold)
      Sets the threshold of number of gaps in a token before an attempt to clean gaps up is taken. Defaults to an integer of 250 (JpaEventStorageEngine.DEFAULT_GAP_CLEANING_THRESHOLD).
      Parameters:
      gapCleaningThreshold - an int specifying the threshold of number of gaps in a token before an attempt to clean gaps up is taken
      Returns:
      the current Builder instance, for fluent interfacing
    • build

      public JpaEventStorageEngine build()
      Initializes a JpaEventStorageEngine as specified through this Builder.
      Returns:
      a JpaEventStorageEngine as specified through this Builder
    • validate

      protected void validate() throws AxonConfigurationException
      Validates whether the fields contained in this Builder are set accordingly.
      Overrides:
      validate in class BatchingEventStorageEngine.Builder
      Throws:
      AxonConfigurationException - if one field is asserted to be incorrect according to the Builder's specifications