Interface DeadLetterStatementFactory<E extends EventMessage>

Type Parameters:
E - An implementation of EventMessage within the DeadLetter this factory constructs PreparedStatements for.
All Known Implementing Classes:
DefaultDeadLetterStatementFactory

public interface DeadLetterStatementFactory<E extends EventMessage>
A contract towards all PreparedStatements a JdbcSequencedDeadLetterQueue requires to function.
Since:
4.8.0
Author:
Steven van Beelen
  • Method Details

    • enqueueStatement

      PreparedStatement enqueueStatement(Connection connection, String processingGroup, String sequenceIdentifier, DeadLetter<? extends E> letter, long sequenceIndex) throws SQLException
      Constructs the PreparedStatement used for the JdbcSequencedDeadLetterQueue.enqueue(Object, DeadLetter, ProcessingContext) operation.

      Context resources (e.g., tracking token, aggregate data) are read from DeadLetter.context().

      Parameters:
      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.
      Returns:
      The PreparedStatement used to enqueue.
      Throws:
      SQLException - When the statement could not be created.
    • maxIndexStatement

      PreparedStatement maxIndexStatement(Connection connection, String processingGroup, String sequenceIdentifier) throws SQLException
      Constructs the PreparedStatement used to retrieve the maximum index of the sequence identified with the given sequenceIdentifier.

      Used by the

      invalid reference
      JdbcSequencedDeadLetterQueue#enqueue(Object, DeadLetter)
      to deduce the index of the DeadLetter in its sequence.
      Parameters:
      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.
      sequenceIdentifier - The identifier of the sequence for which to retrieve the maximum index for.
      Returns:
      The PreparedStatement used to retrieve the maximum index with.
      Throws:
      SQLException - When the statement could not be created.
    • evictStatement

      PreparedStatement evictStatement(Connection connection, String identifier) throws SQLException
      Constructs the PreparedStatement used for the
      invalid reference
      JdbcSequencedDeadLetterQueue#evict(DeadLetter)
      operation.
      Parameters:
      connection - The Connection used to create the PreparedStatement.
      identifier - The identifier of the DeadLetter to evict.
      Returns:
      The PreparedStatement used to
      invalid reference
      evict
      .
      Throws:
      SQLException - When the statement could not be created.
    • requeueStatement

      PreparedStatement requeueStatement(Connection connection, String identifier, Cause cause, Instant lastTouched, Metadata diagnostics) throws SQLException
      Constructs the PreparedStatement used for the
      invalid reference
      JdbcSequencedDeadLetterQueue#requeue(DeadLetter, UnaryOperator)
      operation.
      Parameters:
      connection - The Connection used to create the PreparedStatement.
      identifier - 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.
      Returns:
      The PreparedStatement used to
      invalid reference
      requeue
      .
      Throws:
      SQLException - When the statement could not be created.
    • containsStatement

      PreparedStatement containsStatement(Connection connection, String processingGroup, String sequenceIdentifier) throws SQLException
      Constructs the PreparedStatement used for the
      invalid reference
      JdbcSequencedDeadLetterQueue#contains(Object)
      operation.
      Parameters:
      connection - The Connection used to create the PreparedStatement.
      processingGroup - The processing group for which to check whether the sequence identified by the given sequenceIdentifier.
      sequenceIdentifier - The identifier of the sequence to validate whether it is contained in the queue.
      Returns:
      The PreparedStatement used to check whether the given sequenceIdentifier is
      invalid reference
      contained
      in the queue.
      Throws:
      SQLException - When the statement could not be created.
    • letterSequenceStatement

      PreparedStatement letterSequenceStatement(Connection connection, String processingGroup, String sequenceIdentifier, int offset, int maxSize) throws SQLException
      Constructs the PreparedStatement used for the
      invalid reference
      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.

      Parameters:
      connection - The Connection used to create the PreparedStatement.
      processingGroup - The processing group for which to retrieve a dead-letter sequence.
      sequenceIdentifier - 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.
      Returns:
      The PreparedStatement used to return the dead letter sequence for the given sequenceIdentifier with.
      Throws:
      SQLException - When the statement could not be created.
    • sequenceIdentifiersStatement

      PreparedStatement sequenceIdentifiersStatement(Connection connection, String processingGroup) throws SQLException
      Constructs the PreparedStatement used to iterate over all sequences contained in the queue for the
      invalid reference
      JdbcSequencedDeadLetterQueue#deadLetters()
      operation.
      Parameters:
      connection - The Connection used to create the PreparedStatement.
      processingGroup - The processing group for which to retrieve all sequence identifiers.
      Returns:
      The PreparedStatement used to return all sequence identifiers enqueued in the given processingGroup with.
      Throws:
      SQLException - When the statement could not be created.
    • sizeStatement

      PreparedStatement sizeStatement(Connection connection, String processingGroup) throws SQLException
      Constructs the PreparedStatement used for the
      invalid reference
      JdbcSequencedDeadLetterQueue#size()
      operation.
      Parameters:
      connection - The Connection used to create the PreparedStatement.
      processingGroup - The processing group for which to retrieve the size for.
      Returns:
      The PreparedStatement used to retrieve the size with.
      Throws:
      SQLException - When the statement could not be created.
    • sequenceSizeStatement

      PreparedStatement sequenceSizeStatement(Connection connection, String processingGroup, String sequenceIdentifier) throws SQLException
      Constructs the PreparedStatement used for the
      invalid reference
      JdbcSequencedDeadLetterQueue#sequenceSize(Object)
      operation.
      Parameters:
      connection - The Connection used to create the PreparedStatement.
      processingGroup - The processing group for which to retrieve the size of the identified sequence.
      sequenceIdentifier - The identifier of the sequence for which to retrieve the size.
      Returns:
      The PreparedStatement used to retrieve the size of the sequence identified by the given sequenceIdentifier with.
      Throws:
      SQLException - When the statement could not be created.
    • amountOfSequencesStatement

      PreparedStatement amountOfSequencesStatement(Connection connection, String processingGroup) throws SQLException
      Constructs the PreparedStatement used for the
      invalid reference
      JdbcSequencedDeadLetterQueue#amountOfSequences()
      operation.
      Parameters:
      connection - The Connection used to create the PreparedStatement.
      processingGroup - The processing group for which to retrieve the amount of sequences.
      Returns:
      The PreparedStatement used to retrieve the amount of sequences with.
      Throws:
      SQLException - When the statement could not be created.
    • claimableSequencesStatement

      PreparedStatement claimableSequencesStatement(Connection connection, String processingGroup, Instant processingStartedLimit, int offset, int maxSize) throws SQLException
      Constructs the PreparedStatement used to retrieve the identifiers of the first entries of each sequence with that can be claimed.

      Used by the

      invalid reference
      JdbcSequencedDeadLetterQueue#process(Function)
      and
      invalid reference
      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.

      Parameters:
      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.
      Returns:
      The PreparedStatement used to find the identifier of the first entries of each sequence that are claimable.
      Throws:
      SQLException - When the statement could not be created.
    • claimStatement

      PreparedStatement claimStatement(Connection connection, String identifier, Instant current, Instant processingStartedLimit) throws SQLException
      Constructs the PreparedStatement used to claim a DeadLetter entry.

      Claiming a DeadLetter ensures only a single thread

      invalid reference
      processes
      the DeadLetter. This operation typically update 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

      invalid reference
      JdbcSequencedDeadLetterQueue#process(Function)
      or
      invalid reference
      JdbcSequencedDeadLetterQueue#process(Predicate, Function)
      invocation.
      Parameters:
      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.
      Returns:
      The PreparedStatement used to claim a DeadLetter with for
      invalid reference
      processing
      , ensuring no two threads are processing the same letter.
      Throws:
      SQLException - When the statement could not be created.
    • nextLetterInSequenceStatement

      PreparedStatement nextLetterInSequenceStatement(Connection connection, String processingGroup, String sequenceIdentifier, long sequenceIndex) throws SQLException
      Constructs the 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

      invalid reference
      JdbcSequencedDeadLetterQueue#process(Function)
      or
      invalid reference
      JdbcSequencedDeadLetterQueue#process(Predicate, Function)
      invocation.
      Parameters:
      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.
      Returns:
      The PreparedStatement used to retrieve the DeadLetter in the sequence identified by the given sequenceIdentifier with.
      Throws:
      SQLException - When the statement could not be created.
    • clearStatement

      PreparedStatement clearStatement(Connection connection, String processingGroup) throws SQLException
      Constructs the PreparedStatement used for the
      invalid reference
      clear
      operation.

      Will only remove all entries for the given processingGroup.

      Parameters:
      connection - The Connection used to create the PreparedStatement.
      processingGroup - The processing group for which to clear all entries.
      Returns:
      The PreparedStatement used to
      invalid reference
      clear
      all entries for the given processingGroup with.
      Throws:
      SQLException - When the statement could not be created.