Class JpaEventStorageEngine.Builder
java.lang.Object
org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine.Builder
org.axonframework.eventsourcing.eventstore.BatchingEventStorageEngine.Builder
org.axonframework.eventsourcing.eventstore.jpa.JpaEventStorageEngine.Builder
- Enclosing class:
JpaEventStorageEngine
Builder class to instantiate a
JpaEventStorageEngine.
The following configurable fields have defaults:
- The
EventUpcasterdefaults to anNoOpEventUpcaster. - The
PersistenceExceptionResolveris defaulted to aSQLErrorCodesResolver, if theDataSourceis provided - The
snapshotFilterdefaults to aSnapshotFilter.allowAll()instance. - The
batchSizedefaults to an integer of size100. - The
explicitFlushdefaults totrue. - The
maxGapOffsetdefaults to an integer of size10000. - The
lowestGlobalSequencedefaults to a long of size1. - The
gapTimeoutdefaults to an integer of size60000(1 minute). - The
gapCleaningThresholddefaults to an integer of size250.
The event and snapshot Serializer, the EntityManagerProvider and TransactionManager are
hard requirements and as such should be provided.
-
Field Summary
Fields inherited from class org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine.Builder
upcasterChain -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbatchSize(int batchSize) Sets thebatchSizespecifying the number of events that should be read at each database access.build()Initializes aJpaEventStorageEngineas specified through this Builder.dataSource(DataSource dataSource) Sets thePersistenceExceptionResolveras aSQLErrorCodesResolver, using the providedDataSourceto resolve the error codes.entityManagerProvider(EntityManagerProvider entityManagerProvider) Sets theEntityManagerProviderwhich provides theEntityManagerused to access the underlying database for thisEventStorageEngineimplementation.eventSerializer(Serializer eventSerializer) Sets theSerializerused to serialize and deserialize the Event Message's payload andMetaDatawith.explicitFlush(boolean explicitFlush) Sets theexplicitFlushfield specifying whether to explicitly callEntityManager.flush()after inserting the Events published in this Unit of Work.finalAggregateBatchPredicate(Predicate<List<? extends DomainEventData<?>>> finalAggregateBatchPredicate) Defines the predicate to use to recognize the terminal batch when reading an event stream for an aggregate.gapCleaningThreshold(int gapCleaningThreshold) Sets the threshold of number of gaps in a token before an attempt to clean gaps up is taken.gapTimeout(int gapTimeout) Sets the amount of time until a 'gap' in a TrackingToken may be considered timed out.lowestGlobalSequence(long lowestGlobalSequence) Sets thelowestGlobalSequencespecifying the first expected auto generated sequence number.maxGapOffset(int maxGapOffset) Sets themaxGapOffsetspecifying the maximum distance in sequence numbers between a missing event and the event with the highest known index.persistenceExceptionResolver(PersistenceExceptionResolver persistenceExceptionResolver) Sets thePersistenceExceptionResolverused to detect concurrency exceptions from the backing database.snapshotFilter(Predicate<? super DomainEventData<?>> snapshotFilter) Deprecated.snapshotFilter(SnapshotFilter snapshotFilter) Sets thesnapshotFilterdeciding whether to take a snapshot into account.snapshotSerializer(Serializer snapshotSerializer) Sets theSerializerused to serialize and deserialize snapshots.transactionManager(TransactionManager transactionManager) Sets theTransactionManagerused to manage transaction around fetching event data.upcasterChain(EventUpcaster upcasterChain) Sets theEventUpcasterused to deserialize events of older revisions.protected voidvalidate()Validates whether the fields contained in this Builder are set accordingly.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
snapshotSerializer
Description copied from class:AbstractEventStorageEngine.BuilderSets theSerializerused to serialize and deserialize snapshots.- Overrides:
snapshotSerializerin classBatchingEventStorageEngine.Builder- Parameters:
snapshotSerializer- aSerializerused to serialize and deserialize snapshots- Returns:
- the current Builder instance, for fluent interfacing
-
upcasterChain
Description copied from class:AbstractEventStorageEngine.BuilderSets theEventUpcasterused to deserialize events of older revisions. Defaults to aNoOpEventUpcaster.- Overrides:
upcasterChainin classBatchingEventStorageEngine.Builder- Parameters:
upcasterChain- anEventUpcasterused 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.BuilderSets thePersistenceExceptionResolverused to detect concurrency exceptions from the backing database. If thepersistenceExceptionResolveris not specified, persistence exceptions are not explicitly resolved.- Overrides:
persistenceExceptionResolverin classBatchingEventStorageEngine.Builder- Parameters:
persistenceExceptionResolver- thePersistenceExceptionResolverused to detect concurrency exceptions from the backing database- Returns:
- the current Builder instance, for fluent interfacing
-
eventSerializer
Description copied from class:AbstractEventStorageEngine.BuilderSets theSerializerused to serialize and deserialize the Event Message's payload andMetaDatawith.- Overrides:
eventSerializerin classBatchingEventStorageEngine.Builder- Parameters:
eventSerializer- The serializer to serialize the Event Message's payload andMetaDatawith- 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:
finalAggregateBatchPredicatein classBatchingEventStorageEngine.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.in favor ofsnapshotFilter(SnapshotFilter)Sets thesnapshotFilterdeciding whether to take a snapshot into account. Can be set to filter out specific snapshot revisions which should not be applied. Defaults to aPredicatewhich returnstrueregardless.- Overrides:
snapshotFilterin classBatchingEventStorageEngine.Builder- Parameters:
snapshotFilter- aPredicatewhich decides whether to take a snapshot into account- Returns:
- the current Builder instance, for fluent interfacing
-
snapshotFilter
Description copied from class:AbstractEventStorageEngine.BuilderSets thesnapshotFilterdeciding whether to take a snapshot into account. Can be set to filter out specific snapshot revisions which should not be applied. Defaults toSnapshotFilter.allowAll().Note that
SnapshotFilterinstances can be combined and should returntrueif they handle a snapshot they wish to ignore.- Overrides:
snapshotFilterin classBatchingEventStorageEngine.Builder- Parameters:
snapshotFilter- aSnapshotFilterwhich decides whether to take a snapshot into account- Returns:
- the current Builder instance, for fluent interfacing
-
batchSize
Description copied from class:BatchingEventStorageEngine.BuilderSets thebatchSizespecifying 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 of100.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:
batchSizein classBatchingEventStorageEngine.Builder- Parameters:
batchSize- anintspecifying the number of events that should be read at each database access- Returns:
- the current Builder instance, for fluent interfacing
-
dataSource
Sets thePersistenceExceptionResolveras aSQLErrorCodesResolver, using the providedDataSourceto resolve the error codes. Note that the provided DataSource sole purpose in thisEventStorageEngineimplementation is to be used for instantiating the PersistenceExceptionResolver.- Parameters:
dataSource- theDataSourceused to instantiate aSQLErrorCodesResolver(DataSource)as thePersistenceExceptionResolver- Returns:
- the current Builder instance, for fluent interfacing
- Throws:
SQLException- if creation of theSQLErrorCodesResolverfails
-
entityManagerProvider
public JpaEventStorageEngine.Builder entityManagerProvider(EntityManagerProvider entityManagerProvider) Sets theEntityManagerProviderwhich provides theEntityManagerused to access the underlying database for thisEventStorageEngineimplementation.- Parameters:
entityManagerProvider- aEntityManagerProviderwhich provides theEntityManagerused to access the underlying database- Returns:
- the current Builder instance, for fluent interfacing
-
transactionManager
Sets theTransactionManagerused to manage transaction around fetching event data. Required by certain databases for reading blob data.- Parameters:
transactionManager- aTransactionManagerused to manage transaction around fetching event data- Returns:
- the current Builder instance, for fluent interfacing
-
explicitFlush
Sets theexplicitFlushfield specifying whether to explicitly callEntityManager.flush()after inserting the Events published in this Unit of Work. Iffalse, this instance relies on the TransactionManager to flush data. Note that thepersistenceExceptionResolvermay not be able to translate exceptions anymore.falseshould only be used to optimize performance for batch operations. In other cases,trueis recommended, which is also the default.- Parameters:
explicitFlush- abooleanspecifying whether to explicitly callEntityManager.flush()after inserting the Events published in this Unit of Work- Returns:
- the current Builder instance, for fluent interfacing
-
maxGapOffset
Sets themaxGapOffsetspecifying 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 of10000(JpaEventStorageEngine.DEFAULT_MAX_GAP_OFFSET.- Parameters:
maxGapOffset- anintspecifying 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
Sets thelowestGlobalSequencespecifying the first expected auto generated sequence number. For most data stores this is 1 unless the table has contained entries before. Defaults to alongof1(JpaEventStorageEngine.DEFAULT_LOWEST_GLOBAL_SEQUENCE).- Parameters:
lowestGlobalSequence- alongspecifying the first expected auto generated sequence number- Returns:
- the current Builder instance, for fluent interfacing
-
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 of60000(JpaEventStorageEngine.DEFAULT_GAP_TIMEOUT), thus 1 minute.- Parameters:
gapTimeout- anintspecifying 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
Sets the threshold of number of gaps in a token before an attempt to clean gaps up is taken. Defaults to an integer of250(JpaEventStorageEngine.DEFAULT_GAP_CLEANING_THRESHOLD).- Parameters:
gapCleaningThreshold- anintspecifying 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
Initializes aJpaEventStorageEngineas specified through this Builder.- Returns:
- a
JpaEventStorageEngineas specified through this Builder
-
validate
Validates whether the fields contained in this Builder are set accordingly.- Overrides:
validatein classBatchingEventStorageEngine.Builder- Throws:
AxonConfigurationException- if one field is asserted to be incorrect according to the Builder's specifications
-
snapshotFilter(SnapshotFilter)