Class DefaultDeadLetterStatementFactory<E extends EventMessage>
- Type Parameters:
E- An implementation ofEventMessagewithin theDeadLetterthis factory constructsPreparedStatementsfor.
- All Implemented Interfaces:
DeadLetterStatementFactory<E>
DeadLetterStatementFactory used by the JdbcSequencedDeadLetterQueue.
Constructs PreparedStatements that are compatible with most databases.
This factory expects a DeadLetterSchema to base the table and columns names used for all
PreparedStatements. Furthermore, it uses the configurable genericConverter to convert
TrackingTokens and diagnostics. Lastly, this factory uses the eventConverter to convert
the event payload and Metadata of any
DeadLetter.
This factory and the DeadLetterJdbcConverter must use the same Converter and
EventConverter and DeadLetterSchema for the applicable fields.
- Since:
- 4.8.0
- Author:
- Steven van Beelen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classBuilder class to instantiate aDefaultDeadLetterStatementFactory. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate a defaultDeadLetterStatementFactorybased on the givenbuilder. -
Method Summary
Modifier and TypeMethodDescriptionamountOfSequencesStatement(Connection connection, String processingGroup) Constructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#amountOfSequences()static <E extends EventMessage>
DefaultDeadLetterStatementFactory.Builder<E> builder()Instantiate a builder to construct aDefaultDeadLetterStatementFactory.claimableSequencesStatement(Connection connection, String processingGroup, Instant processingStartedLimit, int offset, int maxSize) Constructs thePreparedStatementused to retrieve the identifiers of the first entries of each sequence with that can be claimed.claimStatement(Connection connection, String identifier, Instant current, Instant processingStartedLimit) Constructs thePreparedStatementused to claim aDeadLetterentry.clearStatement(Connection connection, String processingGroup) Constructs thePreparedStatementused for theoperation.invalid reference
clearcontainsStatement(Connection connection, String processingGroup, String sequenceId) Constructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#contains(Object)enqueueStatement(Connection connection, String processingGroup, String sequenceIdentifier, DeadLetter<? extends E> letter, long sequenceIndex) Constructs thePreparedStatementused for theJdbcSequencedDeadLetterQueue.enqueue(Object, DeadLetter, ProcessingContext)operation.evictStatement(Connection connection, String identifier) Constructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#evict(DeadLetter)letterSequenceStatement(Connection connection, String processingGroup, String sequenceId, int offset, int maxSize) Constructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#deadLetterSequence(Object)maxIndexStatement(Connection connection, String processingGroup, String sequenceId) Constructs thePreparedStatementused to retrieve the maximumindexof the sequence identified with the givensequenceIdentifier.nextLetterInSequenceStatement(Connection connection, String processingGroup, String sequenceIdentifier, long sequenceIndex) Constructs thePreparedStatementused to retrieve the followingDeadLetterfrom the sequence identified with the givensequenceIdentifier.requeueStatement(Connection connection, String letterIdentifier, Cause cause, Instant lastTouched, Metadata diagnostics) Constructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#requeue(DeadLetter, UnaryOperator)sequenceIdentifiersStatement(Connection connection, String processingGroup) Constructs thePreparedStatementused to iterate over all sequences contained in the queue for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#deadLetters()sequenceSizeStatement(Connection connection, String processingGroup, String sequenceId) Constructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#sequenceSize(Object)sizeStatement(Connection connection, String processingGroup) Constructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#size()
-
Constructor Details
-
DefaultDeadLetterStatementFactory
Instantiate a defaultDeadLetterStatementFactorybased on the givenbuilder.Will validate whether the
generic ConverterandEventConverterare set. If for either this is not the case anAxonConfigurationExceptionis thrown.- Parameters:
builder- TheDefaultDeadLetterStatementFactory.Builderused to instantiate aDefaultDeadLetterStatementFactoryinstance.
-
-
Method Details
-
builder
Instantiate a builder to construct aDefaultDeadLetterStatementFactory.The
schemais defaulted to aDeadLetterSchema.defaultSchema(). Thegeneric ConverterandEventConverterare hard requirements and should be provided.- Type Parameters:
E- An implementation ofEventMessagewithin theDeadLetterthis factory constructsPreparedStatementsfor.- Returns:
- A builder that can construct a
DefaultDeadLetterStatementFactory.
-
enqueueStatement
public PreparedStatement enqueueStatement(Connection connection, String processingGroup, String sequenceIdentifier, DeadLetter<? extends E> letter, long sequenceIndex) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused for theJdbcSequencedDeadLetterQueue.enqueue(Object, DeadLetter, ProcessingContext)operation.Context resources (e.g., tracking token, aggregate data) are read from
DeadLetter.context().- Specified by:
enqueueStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to enqueue the givenletter.sequenceIdentifier- The identifier of the sequence the letter belongs to.letter- The letter to enqueue.sequenceIndex- The index of the letter within the sequence, to ensure the processing order is maintained.- Returns:
- The
PreparedStatementused toenqueue. - Throws:
SQLException- When the statement could not be created.
-
maxIndexStatement
public PreparedStatement maxIndexStatement(Connection connection, String processingGroup, String sequenceId) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused to retrieve the maximumindexof the sequence identified with the givensequenceIdentifier.Used by the
to deduce the index of theinvalid reference
JdbcSequencedDeadLetterQueue#enqueue(Object, DeadLetter)DeadLetterin its sequence.- Specified by:
maxIndexStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to retrieve the maximumindexof the sequence identified through the givensequenceIdentifier.sequenceId- The identifier of the sequence for which to retrieve the maximumindexfor.- Returns:
- The
PreparedStatementused to retrieve the maximumindexwith. - Throws:
SQLException- When the statement could not be created.
-
evictStatement
public PreparedStatement evictStatement(Connection connection, String identifier) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#evict(DeadLetter)- Specified by:
evictStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.identifier- The identifier of theDeadLetterto evict.- Returns:
- The
PreparedStatementused to.invalid reference
evict - Throws:
SQLException- When the statement could not be created.
-
requeueStatement
public PreparedStatement requeueStatement(Connection connection, String letterIdentifier, Cause cause, Instant lastTouched, Metadata diagnostics) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#requeue(DeadLetter, UnaryOperator)- Specified by:
requeueStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.letterIdentifier- The identifier of theDeadLetterto requeue.cause- The cause of requeueing theDeadLetteridentified through the givenidentifier.lastTouched- TheInstanttheDeadLetterto requeue was last processed.diagnostics- The new diagnostics to attach to theDeadLetterto requeue.- Returns:
- The
PreparedStatementused to.invalid reference
requeue - Throws:
SQLException- When the statement could not be created.
-
containsStatement
public PreparedStatement containsStatement(Connection connection, String processingGroup, String sequenceId) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#contains(Object)- Specified by:
containsStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to check whether the sequence identified by the givensequenceIdentifier.sequenceId- The identifier of the sequence to validate whether it is contained in the queue.- Returns:
- The
PreparedStatementused to check whether the givensequenceIdentifierisin the queue.invalid reference
contained - Throws:
SQLException- When the statement could not be created.
-
letterSequenceStatement
public PreparedStatement letterSequenceStatement(Connection connection, String processingGroup, String sequenceId, int offset, int maxSize) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#deadLetterSequence(Object)As dead-letter sequences can be large, the
JdbcSequencedDeadLetterQueueassumes it needs to page through the result set. To that end it is recommended to use the givenoffsetto define the starting point of the query (for example by validate theDeadLetterSchema.sequenceIndexColumn()). The givenmaxSizecan be used to limit the result.- Specified by:
letterSequenceStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to retrieve a dead-letter sequence.sequenceId- The identifier of the sequence to retrieve.offset- The offset from where to start thePreparedStatementunder construction.maxSize- The maximum size to limit thePreparedStatementunder construction.- Returns:
- The
PreparedStatementused to return the dead letter sequence for the givensequenceIdentifierwith. - Throws:
SQLException- When the statement could not be created.
-
sequenceIdentifiersStatement
public PreparedStatement sequenceIdentifiersStatement(Connection connection, String processingGroup) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused to iterate over all sequences contained in the queue for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#deadLetters()- Specified by:
sequenceIdentifiersStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to retrieve all sequence identifiers.- Returns:
- The
PreparedStatementused to return all sequence identifiers enqueued in the givenprocessingGroupwith. - Throws:
SQLException- When the statement could not be created.
-
sizeStatement
public PreparedStatement sizeStatement(Connection connection, String processingGroup) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#size()- Specified by:
sizeStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to retrieve the size for.- Returns:
- The
PreparedStatementused to retrieve the size with. - Throws:
SQLException- When the statement could not be created.
-
sequenceSizeStatement
public PreparedStatement sequenceSizeStatement(Connection connection, String processingGroup, String sequenceId) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#sequenceSize(Object)- Specified by:
sequenceSizeStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to retrieve the size of the identified sequence.sequenceId- The identifier of the sequence for which to retrieve the size.- Returns:
- The
PreparedStatementused to retrieve the size of the sequence identified by the givensequenceIdentifierwith. - Throws:
SQLException- When the statement could not be created.
-
amountOfSequencesStatement
public PreparedStatement amountOfSequencesStatement(Connection connection, String processingGroup) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused for theoperation.invalid reference
JdbcSequencedDeadLetterQueue#amountOfSequences()- Specified by:
amountOfSequencesStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to retrieve the amount of sequences.- Returns:
- The
PreparedStatementused to retrieve the amount of sequences with. - Throws:
SQLException- When the statement could not be created.
-
claimableSequencesStatement
public PreparedStatement claimableSequencesStatement(Connection connection, String processingGroup, Instant processingStartedLimit, int offset, int maxSize) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused to retrieve the identifiers of the first entries of each sequence with that can be claimed.Used by the
andinvalid reference
JdbcSequencedDeadLetterQueue#process(Function)operations. A row may be claimed if theinvalid reference
JdbcSequencedDeadLetterQueue#process(Predicate, Function)processing startedfield is older than the givenprocessingStartedLimit.The amount of sequences in a queue can be vast, hence the
JdbcSequencedDeadLetterQueueassumes it needs to page through the result set. To that end it is recommended to use the givenoffsetto define the starting point of the query (for example by validate theDeadLetterSchema.sequenceIndexColumn()). The givenmaxSizecan be used to limit the result.- Specified by:
claimableSequencesStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group to find claimable sequences for.processingStartedLimit- TheInstantused to compare with theprocessing startedfield.offset- The offset from where to start thePreparedStatementunder construction.maxSize- The maximum size to limit thePreparedStatementunder construction.- Returns:
- The
PreparedStatementused to find the identifier of the first entries of each sequence that are claimable. - Throws:
SQLException- When the statement could not be created.
-
claimStatement
public PreparedStatement claimStatement(Connection connection, String identifier, Instant current, Instant processingStartedLimit) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused to claim aDeadLetterentry.Claiming a
DeadLetterensures only a single threadtheinvalid reference
processesDeadLetter. This operation typically update theprocessing startedfield with the givencurrentInstant, marking it as claimed for a certain timeframe.The returned statement is used after the
JdbcSequencedDeadLetterQueuesearched forclaimable sequencesduring aorinvalid reference
JdbcSequencedDeadLetterQueue#process(Function)invocation.invalid reference
JdbcSequencedDeadLetterQueue#process(Predicate, Function)- Specified by:
claimStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.identifier- The identifier of theDeadLetterto claim.current- TheInstantused to update theprocessing startedfield with to mark it as claimed.processingStartedLimit- TheInstantused to compare with theprocessing startedfield, to ensure it wasn't claimed by another process.- Returns:
- The
PreparedStatementused to claim aDeadLetterwith for, ensuring no two threads are processing the same letter.invalid reference
processing - Throws:
SQLException- When the statement could not be created.
-
nextLetterInSequenceStatement
public PreparedStatement nextLetterInSequenceStatement(Connection connection, String processingGroup, String sequenceIdentifier, long sequenceIndex) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused to retrieve the followingDeadLetterfrom the sequence identified with the givensequenceIdentifier. The returned statement is used after theThe returned statement is used after the
JdbcSequencedDeadLetterQueueclaimeda letter and successfully processed it during aorinvalid reference
JdbcSequencedDeadLetterQueue#process(Function)invocation.invalid reference
JdbcSequencedDeadLetterQueue#process(Predicate, Function)- Specified by:
nextLetterInSequenceStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to return the followingDeadLetterin the sequence identified by the givensequenceIdentifier.sequenceIdentifier- The identifier of the sequence for which to retrieve the followingDeadLetterfor.sequenceIndex- The index of the letter preceding the followingDeadLetterto retrieve.- Returns:
- The
PreparedStatementused to retrieve theDeadLetterin the sequence identified by the givensequenceIdentifierwith. - Throws:
SQLException- When the statement could not be created.
-
clearStatement
public PreparedStatement clearStatement(Connection connection, String processingGroup) throws SQLException Description copied from interface:DeadLetterStatementFactoryConstructs thePreparedStatementused for theoperation.invalid reference
clearWill only remove all entries for the given
processingGroup.- Specified by:
clearStatementin interfaceDeadLetterStatementFactory<E extends EventMessage>- Parameters:
connection- TheConnectionused to create thePreparedStatement.processingGroup- The processing group for which to clear all entries.- Returns:
- The
PreparedStatementused toall entries for the giveninvalid reference
clearprocessingGroupwith. - Throws:
SQLException- When the statement could not be created.
-