java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.sms.JdbcSmsCostLedgerRepository
All Implemented Interfaces:
SmsCostLedgerRepository

@Repository public class JdbcSmsCostLedgerRepository extends Object implements SmsCostLedgerRepository
SmsCostLedgerRepository over the sms_cost_ledger table. It opens no transaction: a reservation runs in the caller's, where it first takes a PostgreSQL transaction-level advisory lock, so that concurrent senders (of this or another instance) check and record their messages one after the other and a cap is never overshot. The check and the insert are one conditional statement, so a refused message leaves no row. A refusal is logged, without the number or the country, so that an exhausted budget can be seen.
  • Field Details

    • SPEND_LOCK_KEY

      static final long SPEND_LOCK_KEY
      Key of the advisory lock that serialises the reservations of SMS spend.
      See Also:
    • LOCK

      private static final String LOCK
      Statement taking the advisory lock, released when the caller's transaction ends.
      See Also:
    • INSERT_WITHIN_CAPS

      private static final String INSERT_WITHIN_CAPS
      Statement inserting a row only when the spend of each window, the new row included, stays within its cap. It runs after the lock is taken, so (in the default READ COMMITTED isolation) it sees every row a previous holder of the lock committed.
      See Also:
    • DELETE_OLDER_THAN

      private static final String DELETE_OLDER_THAN
      Statement deleting the rows older than an instant.
      See Also:
    • jdbcClient

      private final org.springframework.jdbc.core.simple.JdbcClient jdbcClient
      JDBC client used to run the statements.
  • Constructor Details

    • JdbcSmsCostLedgerRepository

      public JdbcSmsCostLedgerRepository()
  • Method Details