Class JdbcEventStorageEngine.Builder
- Enclosing class:
JdbcEventStorageEngine
JdbcEventStorageEngine.
The following configurable fields have defaults:
- The
EventUpcasterdefaults to anNoOpEventUpcaster. - The
PersistenceExceptionResolveris defaulted to aJdbcSQLErrorCodesResolver - The
snapshotFilterdefaults to aSnapshotFilter.allowAll()instance. - The
batchSizedefaults to an integer of size100. - The
dataTypeis defaulted to thebyte[]type. - The
EventSchemadefaults to anEventSchema()call. - 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
extendedGapCheckEnableddefaults totrue. - The
createTokenAtdefaults toJdbcEventStorageEngineStatements.createTokenAt(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, java.time.Instant). - The
appendEventsdefaults toJdbcEventStorageEngineStatements.appendEvents(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, java.lang.Class<?>, java.util.List<? extends org.axonframework.eventhandling.EventMessage<?>>, org.axonframework.serialization.Serializer, org.axonframework.eventsourcing.eventstore.jdbc.statements.TimestampWriter). - The
lastSequenceNumberFordefaults toJdbcEventStorageEngineStatements.lastSequenceNumberFor(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, java.lang.String). - The
createTailTokendefaults toJdbcEventStorageEngineStatements.createTailToken(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema). - The
createHeadTokendefaults toJdbcEventStorageEngineStatements.createHeadToken(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema). - The
appendSnapshotdefaults toJdbcEventStorageEngineStatements.appendSnapshot(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, java.lang.Class<?>, org.axonframework.eventhandling.DomainEventMessage<?>, org.axonframework.serialization.Serializer, org.axonframework.eventsourcing.eventstore.jdbc.statements.TimestampWriter). - The
deleteSnapshotsdefaults toJdbcEventStorageEngineStatements.deleteSnapshots(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, java.lang.String, long). - The
fetchTrackedEventsdefaults toJdbcEventStorageEngineStatements.fetchTrackedEvents(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, long). - The
cleanGapsdefaults toJdbcEventStorageEngineStatements.cleanGaps(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, java.util.SortedSet<java.lang.Long>). - The
readEventDataForAggregatedefaults toJdbcEventStorageEngineStatements.readEventDataForAggregate(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, java.lang.String, long, int). - The
readSnapshotDatadefaults toJdbcEventStorageEngineStatements.readSnapshotData(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, java.lang.String). - The
readEventDataWithoutGapsdefaults toJdbcEventStorageEngineStatements.readEventDataWithoutGaps(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, long, int). - The
readEventDataWithGapsdefaults toJdbcEventStorageEngineStatements.readEventDataWithGaps(java.sql.Connection, org.axonframework.eventsourcing.eventstore.jdbc.EventSchema, long, int, java.util.List<java.lang.Long>).
The event and snapshot Serializer, ConnectionProvider and TransactionManager are hard
requirements and as such should be provided.
-
Field Summary
Fields inherited from class org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine.Builder
upcasterChain -
Method Summary
Modifier and TypeMethodDescriptionappendEvents(AppendEventsStatementBuilder appendEvents) Set the PreparedStatement to be used onJdbcEventStorageEngine.appendEvents(Connection, List, Serializer)en}.appendSnapshot(AppendSnapshotStatementBuilder appendSnapshot) Set the PreparedStatement to be used onJdbcEventStorageEngine.appendSnapshot(Connection, DomainEventMessage, Serializer).batchSize(int batchSize) Sets thebatchSizespecifying the number of events that should be read at each database access.build()Initializes aJdbcEventStorageEngineas specified through this Builder.cleanGaps(CleanGapsStatementBuilder cleanGaps) Set the PreparedStatement to be used onJdbcEventStorageEngine.cleanGaps(Connection, SortedSet).connectionProvider(ConnectionProvider connectionProvider) Sets theConnectionProviderwhich provides access to a JDBC connection.createHeadToken(CreateHeadTokenStatementBuilder createHeadToken) Set the PreparedStatement to be used onJdbcEventStorageEngine.createHeadToken(Connection).createTailToken(CreateTailTokenStatementBuilder createTailToken) Set the PreparedStatement to be used onJdbcEventStorageEngine.createTailToken(Connection).createTokenAt(CreateTokenAtStatementBuilder createTokenAt) Set the PreparedStatement to be used onJdbcEventStorageEngine.createTokenAt.Sets thedataTypespecifying the serialized type of the Event Message's payload and Meta Data.deleteSnapshots(DeleteSnapshotsStatementBuilder deleteSnapshots) Set the PreparedStatement to be used onJdbcEventStorageEngine.deleteSnapshots(Connection, String, long).eventSerializer(Serializer eventSerializer) Sets theSerializerused to serialize and deserialize the Event Message's payload andMetaDatawith.extendedGapCheckEnabled(boolean extendedGapCheckEnabled) Indicates whether an extra query should be performed to verify for gaps in theglobalSequencelarger than the configured batch size.fetchTrackedEvents(FetchTrackedEventsStatementBuilder fetchTrackedEvents) Set the PreparedStatement to be used onJdbcEventStorageEngine.fetchTrackedEvents(Connection, long).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.lastSequenceNumberFor(LastSequenceNumberForStatementBuilder lastSequenceNumberFor) Set the PreparedStatement to be used onJdbcEventStorageEngine.lastSequenceNumberFor(Connection, String).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.readEventDataForAggregate(ReadEventDataForAggregateStatementBuilder readEventDataForAggregate) Set the PreparedStatement to be used onJdbcEventStorageEngine.readEventData(Connection, String, long, int).readEventDataWithGaps(ReadEventDataWithGapsStatementBuilder readEventDataWithGaps) Set the PreparedStatement to be used onJdbcEventStorageEngine.readEventDataWithGaps(Connection, long, int, List).readEventDataWithoutGaps(ReadEventDataWithoutGapsStatementBuilder readEventDataWithoutGaps) Set the PreparedStatement to be used onJdbcEventStorageEngine.readEventDataWithoutGaps(Connection, long, int).readSnapshotData(ReadSnapshotDataStatementBuilder readSnapshotData) Set the PreparedStatement to be used onJdbcEventStorageEngine.readSnapshotData(Connection, String).schema(EventSchema schema) Sets theEventSchemadescribing the database schema of event entries.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 transactions 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.
-
Method Details
-
createTokenAt
Set the PreparedStatement to be used onJdbcEventStorageEngine.createTokenAt. Defaults toJdbcEventStorageEngineStatements.createTokenAt(Connection, EventSchema, Instant).- Returns:
- the current Builder instance, for fluent interfacing
-
appendEvents
Set the PreparedStatement to be used onJdbcEventStorageEngine.appendEvents(Connection, List, Serializer)en}. Defaults toJdbcEventStorageEngineStatements.appendEvents(Connection, EventSchema, Class, List, Serializer, TimestampWriter).- Returns:
- the current Builder instance, for fluent interfacing
-
lastSequenceNumberFor
public JdbcEventStorageEngine.Builder lastSequenceNumberFor(LastSequenceNumberForStatementBuilder lastSequenceNumberFor) Set the PreparedStatement to be used onJdbcEventStorageEngine.lastSequenceNumberFor(Connection, String). Defaults toJdbcEventStorageEngineStatements.lastSequenceNumberFor(Connection, EventSchema, String)- Returns:
- the current Builder instance, for fluent interfacing
-
createTailToken
public JdbcEventStorageEngine.Builder createTailToken(CreateTailTokenStatementBuilder createTailToken) Set the PreparedStatement to be used onJdbcEventStorageEngine.createTailToken(Connection). Defaults toJdbcEventStorageEngineStatements.createTailToken(Connection, EventSchema)- Returns:
- the current Builder instance, for fluent interfacing
-
createHeadToken
public JdbcEventStorageEngine.Builder createHeadToken(CreateHeadTokenStatementBuilder createHeadToken) Set the PreparedStatement to be used onJdbcEventStorageEngine.createHeadToken(Connection). Defaults toJdbcEventStorageEngineStatements.createHeadToken(Connection, EventSchema)- Returns:
- the current Builder instance, for fluent interfacing
-
appendSnapshot
Set the PreparedStatement to be used onJdbcEventStorageEngine.appendSnapshot(Connection, DomainEventMessage, Serializer). Defaults toJdbcEventStorageEngineStatements.appendEvents(Connection, EventSchema, Class, List, Serializer, TimestampWriter)- Returns:
- the current Builder instance, for fluent interfacing
-
deleteSnapshots
public JdbcEventStorageEngine.Builder deleteSnapshots(DeleteSnapshotsStatementBuilder deleteSnapshots) Set the PreparedStatement to be used onJdbcEventStorageEngine.deleteSnapshots(Connection, String, long). Defaults toJdbcEventStorageEngineStatements.deleteSnapshots(Connection, EventSchema, String, long)- Returns:
- the current Builder instance, for fluent interfacing
-
fetchTrackedEvents
public JdbcEventStorageEngine.Builder fetchTrackedEvents(FetchTrackedEventsStatementBuilder fetchTrackedEvents) Set the PreparedStatement to be used onJdbcEventStorageEngine.fetchTrackedEvents(Connection, long). Defaults toJdbcEventStorageEngineStatements.fetchTrackedEvents(Connection, EventSchema, long)- Returns:
- the current Builder instance, for fluent interfacing
-
cleanGaps
Set the PreparedStatement to be used onJdbcEventStorageEngine.cleanGaps(Connection, SortedSet). Defaults toJdbcEventStorageEngineStatements.cleanGaps(Connection, EventSchema, SortedSet)- Returns:
- the current Builder instance, for fluent interfacing
-
readEventDataForAggregate
public JdbcEventStorageEngine.Builder readEventDataForAggregate(ReadEventDataForAggregateStatementBuilder readEventDataForAggregate) Set the PreparedStatement to be used onJdbcEventStorageEngine.readEventData(Connection, String, long, int). Defaults toJdbcEventStorageEngineStatements.readEventDataForAggregate(Connection, EventSchema, String, long, int)- Returns:
- the current Builder instance, for fluent interfacing
-
readSnapshotData
public JdbcEventStorageEngine.Builder readSnapshotData(ReadSnapshotDataStatementBuilder readSnapshotData) Set the PreparedStatement to be used onJdbcEventStorageEngine.readSnapshotData(Connection, String). Defaults toJdbcEventStorageEngineStatements.readSnapshotData(Connection, EventSchema, String)- Returns:
- the current Builder instance, for fluent interfacing
-
readEventDataWithoutGaps
public JdbcEventStorageEngine.Builder readEventDataWithoutGaps(ReadEventDataWithoutGapsStatementBuilder readEventDataWithoutGaps) Set the PreparedStatement to be used onJdbcEventStorageEngine.readEventDataWithoutGaps(Connection, long, int). Defaults toJdbcEventStorageEngineStatements.readEventDataWithoutGaps(Connection, EventSchema, long, int)- Returns:
- the current Builder instance, for fluent interfacing
-
readEventDataWithGaps
public JdbcEventStorageEngine.Builder readEventDataWithGaps(ReadEventDataWithGapsStatementBuilder readEventDataWithGaps) Set the PreparedStatement to be used onJdbcEventStorageEngine.readEventDataWithGaps(Connection, long, int, List). Defaults toJdbcEventStorageEngineStatements.readEventDataWithGaps(Connection, EventSchema, long, int, List)- Returns:
- the current Builder instance, for fluent interfacing
-
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 JdbcEventStorageEngine.Builder persistenceExceptionResolver(PersistenceExceptionResolver persistenceExceptionResolver) Sets thePersistenceExceptionResolverused to detect concurrency exceptions from the backing database. If thepersistenceExceptionResolveris not specified, persistence exceptions are not explicitly resolved. Defaults to aJdbcSQLErrorCodesResolver.- 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 JdbcEventStorageEngine.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 JdbcEventStorageEngine defaults to using an empty batch as the final batch. While this is safe, it is also relatively inefficient. When one can guarantee that no events for an aggregate are every removed from the event store, any batch smaller than the maximum batch size can be seen 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 JdbcEventStorageEngine.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
-
connectionProvider
public JdbcEventStorageEngine.Builder connectionProvider(@Nonnull ConnectionProvider connectionProvider) Sets theConnectionProviderwhich provides access to a JDBC connection.- Parameters:
connectionProvider- aConnectionProviderwhich provides access to a JDBC connection- Returns:
- the current Builder instance, for fluent interfacing
-
transactionManager
Sets theTransactionManagerused to manage transactions around fetching event data. Required by certain databases for reading blob data.- Parameters:
transactionManager- aTransactionManagerused to manage transactions around fetching event data- Returns:
- the current Builder instance, for fluent interfacing
-
dataType
Sets thedataTypespecifying the serialized type of the Event Message's payload and Meta Data. Defaults to thebyte[]Class.- Parameters:
dataType- aClassspecifying the serialized type of the Event Message's payload and Meta Data- Returns:
- the current Builder instance, for fluent interfacing
-
schema
Sets theEventSchemadescribing the database schema of event entries. Defaults toEventSchema().- Parameters:
schema- theEventSchemadescribing the database schema of event entries- 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(JdbcEventStorageEngine.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(JdbcEventStorageEngine.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(JdbcEventStorageEngine.DEFAULT_GAP_TIMEOUT), thus 1 minute.- Parameters:
gapTimeout- anintspecifying the amount of time 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(JdbcEventStorageEngine.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
-
extendedGapCheckEnabled
Indicates whether an extra query should be performed to verify for gaps in theglobalSequencelarger than the configured batch size. These gaps could trick the storage engine into believing there are no more events to read, while there are still positions ahead.This check comes at a cost of an extra query when a batch retrieval yields an empty result. This may increase database pressure when processors are at the HEAD of a stream, as each batch retrieval will result in an extra query, if there are no results.
Note that the extra query checks for the smallest globalSequence, higher than the last one seen. This query can be executed using an index, which should be a relatively cheap query for most databases.
Defaults to
true- Parameters:
extendedGapCheckEnabled- whether to enable the "extended gap check". Defaults totrue.- Returns:
- the current Builder instance, for fluent interfacing
-
build
Initializes aJdbcEventStorageEngineas specified through this Builder.- Returns:
- a
JdbcEventStorageEngineas 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)