public static class JpaEventStorageEngine.Builder extends BatchingEventStorageEngine.Builder
JpaEventStorageEngine
.
The following configurable fields have defaults:
Serializer
defaults to XStreamSerializer
.EventUpcaster
defaults to an NoOpEventUpcaster
.PersistenceExceptionResolver
is defaulted to a SQLErrorCodesResolver
, if the
DataSource
is providedXStreamSerializer
.snapshotFilter
defaults to a SnapshotFilter.allowAll()
intance.batchSize
defaults to an integer of size 100
.explicitFlush
defaults to true
.maxGapOffset
defaults to an integer of size 10000
.lowestGlobalSequence
defaults to a long of size 1
.gapTimeout
defaults to an integer of size 60000
(1 minute).gapCleaningThreshold
defaults to an integer of size 250
.
The EntityManagerProvider
and TransactionManager
are hard requirements and as such
should be provided.
upcasterChain
Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
JpaEventStorageEngine.Builder |
batchSize(int batchSize)
Sets the
batchSize specifying the number of events that should be read at each database access. |
JpaEventStorageEngine |
build()
Initializes a
JpaEventStorageEngine as specified through this Builder. |
JpaEventStorageEngine.Builder |
dataSource(DataSource dataSource)
Sets the
PersistenceExceptionResolver as a SQLErrorCodesResolver , using the provided
DataSource to resolve the error codes. |
JpaEventStorageEngine.Builder |
entityManagerProvider(EntityManagerProvider entityManagerProvider)
Sets the
EntityManagerProvider which provides the EntityManager used to access the
underlying database for this EventStorageEngine
implementation. |
JpaEventStorageEngine.Builder |
eventSerializer(Serializer eventSerializer)
Sets the
Serializer used to serialize and deserialize the Event Message's payload and Meta Data with. |
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. |
JpaEventStorageEngine.Builder |
gapCleaningThreshold(int gapCleaningThreshold)
Sets the threshold of number of gaps in a token before an attempt to clean gaps up is taken.
|
JpaEventStorageEngine.Builder |
gapTimeout(int gapTimeout)
Sets the amount of time until a 'gap' in a TrackingToken may be considered timed out.
|
JpaEventStorageEngine.Builder |
lowestGlobalSequence(long lowestGlobalSequence)
Sets the
lowestGlobalSequence specifying the first expected auto generated sequence number. |
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. |
JpaEventStorageEngine.Builder |
persistenceExceptionResolver(PersistenceExceptionResolver persistenceExceptionResolver)
Sets the
PersistenceExceptionResolver used to detect concurrency exceptions from the backing
database. |
JpaEventStorageEngine.Builder |
snapshotFilter(Predicate<? super DomainEventData<?>> snapshotFilter)
Deprecated.
in favor of
snapshotFilter(SnapshotFilter) |
JpaEventStorageEngine.Builder |
snapshotFilter(SnapshotFilter snapshotFilter)
Sets the
snapshotFilter deciding whether to take a snapshot into account. |
JpaEventStorageEngine.Builder |
snapshotSerializer(Serializer snapshotSerializer)
Sets the
Serializer used to serialize and deserialize snapshots. |
JpaEventStorageEngine.Builder |
transactionManager(TransactionManager transactionManager)
Sets the
TransactionManager used to manage transaction around fetching event data. |
JpaEventStorageEngine.Builder |
upcasterChain(EventUpcaster upcasterChain)
Sets the
EventUpcaster used to deserialize events of older revisions. |
protected void |
validate()
Validates whether the fields contained in this Builder are set accordingly.
|
public JpaEventStorageEngine.Builder snapshotSerializer(Serializer snapshotSerializer)
AbstractEventStorageEngine.Builder
Serializer
used to serialize and deserialize snapshots. Defaults to a XStreamSerializer
.snapshotSerializer
in class BatchingEventStorageEngine.Builder
snapshotSerializer
- a Serializer
used to serialize and deserialize snapshotspublic JpaEventStorageEngine.Builder upcasterChain(EventUpcaster upcasterChain)
AbstractEventStorageEngine.Builder
EventUpcaster
used to deserialize events of older revisions. Defaults to a NoOpEventUpcaster
.upcasterChain
in class BatchingEventStorageEngine.Builder
upcasterChain
- an EventUpcaster
used to deserialize events of older revisionspublic JpaEventStorageEngine.Builder persistenceExceptionResolver(PersistenceExceptionResolver persistenceExceptionResolver)
AbstractEventStorageEngine.Builder
PersistenceExceptionResolver
used to detect concurrency exceptions from the backing
database. If the persistenceExceptionResolver
is not specified, persistence exceptions are not
explicitly resolved.persistenceExceptionResolver
in class BatchingEventStorageEngine.Builder
persistenceExceptionResolver
- the PersistenceExceptionResolver
used to detect concurrency
exceptions from the backing databasepublic JpaEventStorageEngine.Builder eventSerializer(Serializer eventSerializer)
AbstractEventStorageEngine.Builder
Serializer
used to serialize and deserialize the Event Message's payload and Meta Data with.
Defaults to a XStreamSerializer
.eventSerializer
in class BatchingEventStorageEngine.Builder
eventSerializer
- The serializer to serialize the Event Message's payload and Meta Data with@Deprecated public JpaEventStorageEngine.Builder snapshotFilter(Predicate<? super DomainEventData<?>> snapshotFilter)
snapshotFilter(SnapshotFilter)
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.snapshotFilter
in class BatchingEventStorageEngine.Builder
snapshotFilter
- a Predicate
which decides whether to take a snapshot into accountpublic JpaEventStorageEngine.Builder snapshotFilter(SnapshotFilter snapshotFilter)
AbstractEventStorageEngine.Builder
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.
snapshotFilter
in class BatchingEventStorageEngine.Builder
snapshotFilter
- a SnapshotFilter
which decides whether to take a snapshot into accountpublic JpaEventStorageEngine.Builder batchSize(int batchSize)
BatchingEventStorageEngine.Builder
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.
batchSize
in class BatchingEventStorageEngine.Builder
batchSize
- an int
specifying the number of events that should be read at each database accesspublic JpaEventStorageEngine.Builder dataSource(DataSource dataSource) throws SQLException
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.dataSource
- the DataSource
used to instantiate a
SQLErrorCodesResolver.SQLErrorCodesResolver(DataSource)
as the
PersistenceExceptionResolver
SQLException
- if creation of the SQLErrorCodesResolver
failspublic JpaEventStorageEngine.Builder entityManagerProvider(EntityManagerProvider entityManagerProvider)
EntityManagerProvider
which provides the EntityManager
used to access the
underlying database for this EventStorageEngine
implementation.entityManagerProvider
- a EntityManagerProvider
which provides the EntityManager
used to
access the underlying databasepublic JpaEventStorageEngine.Builder transactionManager(TransactionManager transactionManager)
TransactionManager
used to manage transaction around fetching event data. Required by
certain databases for reading blob data.transactionManager
- a TransactionManager
used to manage transaction around fetching event datapublic JpaEventStorageEngine.Builder explicitFlush(boolean explicitFlush)
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.explicitFlush
- a boolean
specifying whether to explicitly call EntityManager.flush()
after inserting the Events published in this Unit of Workpublic JpaEventStorageEngine.Builder maxGapOffset(int maxGapOffset)
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
.maxGapOffset
- an int
specifying the maximum distance in sequence numbers between a missing
event and the event with the highest known indexpublic JpaEventStorageEngine.Builder lowestGlobalSequence(long lowestGlobalSequence)
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
).lowestGlobalSequence
- a long
specifying the first expected auto generated sequence numberpublic JpaEventStorageEngine.Builder gapTimeout(int gapTimeout)
60000
(JpaEventStorageEngine.DEFAULT_GAP_TIMEOUT
), thus 1 minute.gapTimeout
- an int
specifying the amount of time in milliseconds until a 'gap' in a
TrackingToken may be considered timed outpublic JpaEventStorageEngine.Builder gapCleaningThreshold(int gapCleaningThreshold)
250
(JpaEventStorageEngine.DEFAULT_GAP_CLEANING_THRESHOLD
).gapCleaningThreshold
- an int
specifying the threshold of number of gaps in a token before an
attempt to clean gaps up is takenpublic JpaEventStorageEngine build()
JpaEventStorageEngine
as specified through this Builder.JpaEventStorageEngine
as specified through this Builderprotected void validate() throws AxonConfigurationException
validate
in class BatchingEventStorageEngine.Builder
AxonConfigurationException
- if one field is asserted to be incorrect according to the Builder's
specificationsCopyright © 2010–2020. All rights reserved.