java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.sms.JdbcUserPhoneRepository
All Implemented Interfaces:
UserPhoneRepository

@Repository public class JdbcUserPhoneRepository extends Object implements UserPhoneRepository
UserPhoneRepository over the verified columns of the user_phones table. It opens no transaction: a save runs in the caller's, where it first takes a PostgreSQL transaction-level advisory lock on the number, so two users confirming the same number are serialised and the unique constraint is never violated (a violation would abort the caller's transaction).
  • Field Details

    • PHONE_LOCK_NAMESPACE

      static final int PHONE_LOCK_NAMESPACE
      First key of the advisory locks of the numbers, which keeps them apart from every other advisory lock.
      See Also:
    • FIND_BY_USER

      private static final String FIND_BY_USER
      Query returning the verified phone of a user.
      See Also:
    • FIND_BY_PHONE

      private static final String FIND_BY_PHONE
      Query returning the verified phone with a number.
      See Also:
    • LOCK_NUMBER

      private static final String LOCK_NUMBER
      Statement taking the advisory lock of a number, released when the caller's transaction ends.
      See Also:
    • UPSERT

      private static final String UPSERT
      Statement that stores the verified phone of a user, creating the row or updating its verified columns only (the pending ones are untouched), unless another user already owns the number. It runs after the lock of the number is taken, so (in the default READ COMMITTED isolation) it sees the row of any user who confirmed the same number before, and the unique constraint cannot be hit.
      See Also:
    • CLEAR_VERIFIED

      private static final String CLEAR_VERIFIED
      Statement clearing the verified columns of a user.
      See Also:
    • DELETE_IF_EMPTY

      private static final String DELETE_IF_EMPTY
      Statement deleting the row of a user that holds neither a verified phone nor a pending verification.
      See Also:
    • jdbcClient

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

      private final UserPhoneRowMapper userPhoneRowMapper
      Maps a row to a verified phone.
  • Constructor Details

    • JdbcUserPhoneRepository

      public JdbcUserPhoneRepository()
  • Method Details