Class JdbcUserPhoneRepository
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.sms.JdbcUserPhoneRepository
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringStatement clearing the verified columns of a user.private static final StringStatement deleting the row of a user that holds neither a verified phone nor a pending verification.private static final StringQuery returning the verified phone with a number.private static final StringQuery returning the verified phone of a user.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements.private static final StringStatement taking the advisory lock of a number, released when the caller's transaction ends.(package private) static final intFirst key of the advisory locks of the numbers, which keeps them apart from every other advisory lock.private static final StringStatement 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.private final UserPhoneRowMapperMaps a row to a verified phone. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteByUserId(UUID userId) Removes the verified phone of a user.findByPhone(PhoneNumber phone) Finds the verified phone that holds a number.findByUserId(UUID userId) Finds the verified phone of a user.booleanStores the verified phone of a user, replacing the one it had.
-
Field Details
-
PHONE_LOCK_NAMESPACE
static final int PHONE_LOCK_NAMESPACEFirst key of the advisory locks of the numbers, which keeps them apart from every other advisory lock.- See Also:
-
FIND_BY_USER
Query returning the verified phone of a user.- See Also:
-
FIND_BY_PHONE
Query returning the verified phone with a number.- See Also:
-
LOCK_NUMBER
Statement taking the advisory lock of a number, released when the caller's transaction ends.- See Also:
-
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 defaultREAD COMMITTEDisolation) it sees the row of any user who confirmed the same number before, and the unique constraint cannot be hit.- See Also:
-
CLEAR_VERIFIED
Statement clearing the verified columns of a user.- See Also:
-
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 jdbcClientJDBC client used to run the statements. -
userPhoneRowMapper
Maps a row to a verified phone.
-
-
Constructor Details
-
JdbcUserPhoneRepository
public JdbcUserPhoneRepository()
-
-
Method Details
-
findByUserId
Description copied from interface:UserPhoneRepositoryFinds the verified phone of a user.- Specified by:
findByUserIdin interfaceUserPhoneRepository- Parameters:
userId- identifier of the user.- Returns:
- the phone, or empty when the user has none.
-
findByPhone
Description copied from interface:UserPhoneRepositoryFinds the verified phone that holds a number.- Specified by:
findByPhonein interfaceUserPhoneRepository- Parameters:
phone- the number.- Returns:
- the phone, or empty when no user verified it.
-
save
Description copied from interface:UserPhoneRepositoryStores the verified phone of a user, replacing the one it had.- Specified by:
savein interfaceUserPhoneRepository- Parameters:
phone- the verified phone.- Returns:
falsewhen another user already holds the number and nothing was stored.
-
deleteByUserId
Description copied from interface:UserPhoneRepositoryRemoves the verified phone of a user.- Specified by:
deleteByUserIdin interfaceUserPhoneRepository- Parameters:
userId- identifier of the user.
-