E
- An implementation of EventMessage
within the DeadLetter
this factory constructs
PreparedStatements
for.public class DefaultDeadLetterStatementFactory<E extends EventMessage<?>> extends Object implements 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 genericSerializer
to serialize
TrackingTokens
in TrackedEventMessage
instances. Lastly, this factory uses the
eventSerializer
to serialize the event payload
,
MetaData
, and diagnostics
of any
DeadLetter
.
This factory and the DeadLetterJdbcConverter
must use the same Serializers
and
DeadLetterSchema
for the applicable fields.
Modifier and Type | Class and Description |
---|---|
protected static class |
DefaultDeadLetterStatementFactory.Builder<E extends EventMessage<?>>
Builder class to instantiate a
DefaultDeadLetterStatementFactory . |
Modifier | Constructor and Description |
---|---|
protected |
DefaultDeadLetterStatementFactory(DefaultDeadLetterStatementFactory.Builder<E> builder)
Instantiate a default
DeadLetterStatementFactory based on the given builder . |
Modifier and Type | Method and Description |
---|---|
PreparedStatement |
amountOfSequencesStatement(Connection connection,
String processingGroup)
Constructs the
PreparedStatement used for the JdbcSequencedDeadLetterQueue.amountOfSequences()
operation. |
static <E extends EventMessage<?>> |
builder()
Instantiate a builder to construct a
DefaultDeadLetterStatementFactory . |
PreparedStatement |
claimableSequencesStatement(Connection connection,
String processingGroup,
Instant processingStartedLimit,
int offset,
int maxSize)
Constructs the
PreparedStatement used to retrieve the identifiers of the first entries of each sequence
with that can be claimed. |
PreparedStatement |
claimStatement(Connection connection,
String identifier,
Instant current,
Instant processingStartedLimit)
Constructs the
PreparedStatement used to claim a DeadLetter entry. |
PreparedStatement |
clearStatement(Connection connection,
String processingGroup)
Constructs the
PreparedStatement used for the clear
operation. |
PreparedStatement |
containsStatement(Connection connection,
String processingGroup,
String sequenceId)
Constructs the
PreparedStatement used for the JdbcSequencedDeadLetterQueue.contains(Object)
operation. |
PreparedStatement |
enqueueStatement(Connection connection,
String processingGroup,
String sequenceIdentifier,
DeadLetter<? extends E> letter,
long sequenceIndex)
Constructs the
PreparedStatement used for the
JdbcSequencedDeadLetterQueue.enqueue(Object, DeadLetter) operation. |
PreparedStatement |
evictStatement(Connection connection,
String identifier)
Constructs the
PreparedStatement used for the JdbcSequencedDeadLetterQueue.evict(DeadLetter)
operation. |
PreparedStatement |
letterSequenceStatement(Connection connection,
String processingGroup,
String sequenceId,
int offset,
int maxSize)
Constructs the
PreparedStatement used for the
JdbcSequencedDeadLetterQueue.deadLetterSequence(Object) operation. |
PreparedStatement |
maxIndexStatement(Connection connection,
String processingGroup,
String sequenceId)
Constructs the
PreparedStatement used to retrieve the maximum
index of the sequence identified with the given
sequenceIdentifier . |
PreparedStatement |
nextLetterInSequenceStatement(Connection connection,
String processingGroup,
String sequenceIdentifier,
long sequenceIndex)
Constructs the
PreparedStatement used to retrieve the following DeadLetter from the sequence
identified with the given sequenceIdentifier . |
PreparedStatement |
requeueStatement(Connection connection,
String letterIdentifier,
Cause cause,
Instant lastTouched,
MetaData diagnostics)
Constructs the
PreparedStatement used for the
JdbcSequencedDeadLetterQueue.requeue(DeadLetter, UnaryOperator) operation. |
PreparedStatement |
sequenceIdentifiersStatement(Connection connection,
String processingGroup)
Constructs the
PreparedStatement used to iterate over all sequences contained in the queue for the
JdbcSequencedDeadLetterQueue.deadLetters() operation. |
PreparedStatement |
sequenceSizeStatement(Connection connection,
String processingGroup,
String sequenceId)
Constructs the
PreparedStatement used for the JdbcSequencedDeadLetterQueue.sequenceSize(Object)
operation. |
PreparedStatement |
sizeStatement(Connection connection,
String processingGroup)
Constructs the
PreparedStatement used for the JdbcSequencedDeadLetterQueue.size() operation. |
protected DefaultDeadLetterStatementFactory(DefaultDeadLetterStatementFactory.Builder<E> builder)
DeadLetterStatementFactory
based on the given builder
.
Will validate whether the generic Serializer
and
event Serializer
are set. If for either this is not the case an
AxonConfigurationException
is thrown.
builder
- The DefaultDeadLetterStatementFactory.Builder
used to instantiate a DefaultDeadLetterStatementFactory
instance.public static <E extends EventMessage<?>> DefaultDeadLetterStatementFactory.Builder<E> builder()
DefaultDeadLetterStatementFactory
.
The schema
is defaulted to a DeadLetterSchema.defaultSchema()
.
The generic Serializer
and
event Serializer
are hard requirements and should be provided.
E
- An implementation of EventMessage
within the DeadLetter
this factory constructs
PreparedStatements
for.DefaultDeadLetterStatementFactory
.public PreparedStatement enqueueStatement(@Nonnull Connection connection, @Nonnull String processingGroup, @Nonnull String sequenceIdentifier, @Nonnull DeadLetter<? extends E> letter, long sequenceIndex) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used for the
JdbcSequencedDeadLetterQueue.enqueue(Object, DeadLetter)
operation.enqueueStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.processingGroup
- The processing group for which to enqueue the given letter
.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.PreparedStatement
used to
enqueue
.SQLException
- When the statement could not be created.public PreparedStatement maxIndexStatement(@Nonnull Connection connection, @Nonnull String processingGroup, @Nonnull String sequenceId) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used to retrieve the maximum
index
of the sequence identified with the given
sequenceIdentifier
.
Used by the JdbcSequencedDeadLetterQueue.enqueue(Object, DeadLetter)
to deduce the index of the
DeadLetter
in its sequence.
maxIndexStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.processingGroup
- The processing group for which to retrieve the maximum
index
of the sequence identified through
the given sequenceIdentifier
.sequenceId
- The identifier of the sequence for which to retrieve the maximum
index
for.PreparedStatement
used to retrieve the maximum
index
with.SQLException
- When the statement could not be created.public PreparedStatement evictStatement(@Nonnull Connection connection, @Nonnull String identifier) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used for the JdbcSequencedDeadLetterQueue.evict(DeadLetter)
operation.evictStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.identifier
- The identifier of the DeadLetter
to evict.PreparedStatement
used to evict
.SQLException
- When the statement could not be created.public PreparedStatement requeueStatement(@Nonnull Connection connection, @Nonnull String letterIdentifier, Cause cause, @Nonnull Instant lastTouched, MetaData diagnostics) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used for the
JdbcSequencedDeadLetterQueue.requeue(DeadLetter, UnaryOperator)
operation.requeueStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.letterIdentifier
- The identifier of the DeadLetter
to requeue.cause
- The cause of requeueing the DeadLetter
identified through the given
identifier
.lastTouched
- The Instant
the DeadLetter
to requeue was last processed.diagnostics
- The new diagnostics to attach to the DeadLetter
to requeue.PreparedStatement
used to
requeue
.SQLException
- When the statement could not be created.public PreparedStatement containsStatement(@Nonnull Connection connection, @Nonnull String processingGroup, @Nonnull String sequenceId) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used for the JdbcSequencedDeadLetterQueue.contains(Object)
operation.containsStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.processingGroup
- The processing group for which to check whether the sequence identified by the given
sequenceIdentifier
.sequenceId
- The identifier of the sequence to validate whether it is contained in the queue.PreparedStatement
used to check whether the given sequenceIdentifier
is
contained
in the queue.SQLException
- When the statement could not be created.public PreparedStatement letterSequenceStatement(@Nonnull Connection connection, @Nonnull String processingGroup, @Nonnull String sequenceId, int offset, int maxSize) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used for the
JdbcSequencedDeadLetterQueue.deadLetterSequence(Object)
operation.
As dead-letter sequences can be large, the JdbcSequencedDeadLetterQueue
assumes it needs to page through
the result set. To that end it is recommended to use the given offset
to define the starting point of the
query (for example by validate the DeadLetterSchema.sequenceIndexColumn()
). The given maxSize
can
be used to limit the result.
letterSequenceStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.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 the PreparedStatement
under construction.maxSize
- The maximum size to limit the PreparedStatement
under construction.PreparedStatement
used to return the dead letter sequence for the given
sequenceIdentifier
with.SQLException
- When the statement could not be created.public PreparedStatement sequenceIdentifiersStatement(@Nonnull Connection connection, @Nonnull String processingGroup) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used to iterate over all sequences contained in the queue for the
JdbcSequencedDeadLetterQueue.deadLetters()
operation.sequenceIdentifiersStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.processingGroup
- The processing group for which to retrieve all sequence identifiers.PreparedStatement
used to return all sequence identifiers enqueued in the given
processingGroup
with.SQLException
- When the statement could not be created.public PreparedStatement sizeStatement(@Nonnull Connection connection, @Nonnull String processingGroup) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used for the JdbcSequencedDeadLetterQueue.size()
operation.sizeStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.processingGroup
- The processing group for which to retrieve the size for.PreparedStatement
used to retrieve the size with.SQLException
- When the statement could not be created.public PreparedStatement sequenceSizeStatement(@Nonnull Connection connection, @Nonnull String processingGroup, @Nonnull String sequenceId) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used for the JdbcSequencedDeadLetterQueue.sequenceSize(Object)
operation.sequenceSizeStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.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.PreparedStatement
used to retrieve the size of the sequence identified by the given
sequenceIdentifier
with.SQLException
- When the statement could not be created.public PreparedStatement amountOfSequencesStatement(@Nonnull Connection connection, @Nonnull String processingGroup) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used for the JdbcSequencedDeadLetterQueue.amountOfSequences()
operation.amountOfSequencesStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.processingGroup
- The processing group for which to retrieve the amount of sequences.PreparedStatement
used to retrieve the amount of sequences with.SQLException
- When the statement could not be created.public PreparedStatement claimableSequencesStatement(@Nonnull Connection connection, @Nonnull String processingGroup, @Nonnull Instant processingStartedLimit, int offset, int maxSize) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used to retrieve the identifiers of the first entries of each sequence
with that can be claimed.
Used by the JdbcSequencedDeadLetterQueue.process(Function)
and
JdbcSequencedDeadLetterQueue.process(Predicate, Function)
operations. A row may be claimed if the
processing started
field is older than the given
processingStartedLimit
.
The amount of sequences in a queue can be vast, hence the JdbcSequencedDeadLetterQueue
assumes it needs
to page through the result set. To that end it is recommended to use the given offset
to define the
starting point of the query (for example by validate the DeadLetterSchema.sequenceIndexColumn()
). The
given maxSize
can be used to limit the result.
claimableSequencesStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.processingGroup
- The processing group to find claimable sequences for.processingStartedLimit
- The Instant
used to compare with the
processing started
field.offset
- The offset from where to start the PreparedStatement
under construction.maxSize
- The maximum size to limit the PreparedStatement
under construction.PreparedStatement
used to find the identifier of the first entries of each sequence that are
claimable.SQLException
- When the statement could not be created.public PreparedStatement claimStatement(@Nonnull Connection connection, @Nonnull String identifier, @Nonnull Instant current, @Nonnull Instant processingStartedLimit) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used to claim a DeadLetter
entry.
Claiming a DeadLetter
ensures only a single thread
processes
the DeadLetter
. This operation typically
updates the processing started
field with the given
current
Instant
, marking it as claimed for a certain timeframe.
The returned statement is used after the JdbcSequencedDeadLetterQueue
searched for
claimable sequences
during a
JdbcSequencedDeadLetterQueue.process(Function)
or
JdbcSequencedDeadLetterQueue.process(Predicate, Function)
invocation.
claimStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.identifier
- The identifier of the DeadLetter
to claim.current
- The Instant
used to update the
processing started
field with to
mark it as claimed.processingStartedLimit
- The Instant
used to compare with the
processing started
field, to
ensure it wasn't claimed by another process.PreparedStatement
used to claim a DeadLetter
with for
processing
, ensuring no two threads are processing the
same letter.SQLException
- When the statement could not be created.public PreparedStatement nextLetterInSequenceStatement(@Nonnull Connection connection, @Nonnull String processingGroup, @Nonnull String sequenceIdentifier, long sequenceIndex) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used to retrieve the following DeadLetter
from the sequence
identified with the given sequenceIdentifier
. The returned statement is used after the
The returned statement is used after the JdbcSequencedDeadLetterQueue
claimed
a letter and successfully processed
it during a JdbcSequencedDeadLetterQueue.process(Function)
or
JdbcSequencedDeadLetterQueue.process(Predicate, Function)
invocation.
nextLetterInSequenceStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.processingGroup
- The processing group for which to return the following DeadLetter
in the
sequence identified by the given sequenceIdentifier
.sequenceIdentifier
- The identifier of the sequence for which to retrieve the following DeadLetter
for.sequenceIndex
- The index of the letter preceding the following DeadLetter
to retrieve.PreparedStatement
used to retrieve the DeadLetter
in the sequence identified by the
given sequenceIdentifier
with.SQLException
- When the statement could not be created.public PreparedStatement clearStatement(@Nonnull Connection connection, @Nonnull String processingGroup) throws SQLException
DeadLetterStatementFactory
PreparedStatement
used for the clear
operation.
Will only remove all entries for the given processingGroup
.
clearStatement
in interface DeadLetterStatementFactory<E extends EventMessage<?>>
connection
- The Connection
used to create the PreparedStatement
.processingGroup
- The processing group for which to clear all entries.PreparedStatement
used to clear
all entries for
the given processingGroup
with.SQLException
- When the statement could not be created.Copyright © 2010–2024. All rights reserved.