@Repository @Transactional public class UserRepositoryJDBC extends Object implements UserRepository
Connection and DB interactions are managed by
JdbcConnector helper class
All methods are executed within Transactions to rollback any changes in case of abnormal termination.
EMAIL_MIN, LONG_MAX, NOT_EMPTY, SHORT_MAX| Constructor and Description |
|---|
UserRepositoryJDBC(DataSource dataSource,
CredentialsService credentialsService) |
| Modifier and Type | Method and Description |
|---|---|
User |
create(User user)
Store new user on persistence layer.
|
void |
delete(User user)
Delete existing user (found by id) from persistence layer
|
void |
deleteById(Long id)
Delete existing user (found by id) from persistence layer
|
User |
findByEmail(String email)
Find user by e-mail address.
|
User |
findById(Long id)
Find user by its unique identifier.
|
User |
update(User user)
Update existing user (found by id) with given
user details (password and email fields are omitted,
these are different operations).
|
@Autowired public UserRepositoryJDBC(DataSource dataSource, CredentialsService credentialsService)
public User findById(Long id)
UserRepositoryfindById in interface UserRepositoryid - User's idpublic User findByEmail(String email)
UserRepositoryfindByEmail in interface UserRepositoryemail - email addresspublic User create(User user)
UserRepositoryUser constraints: fields 'email', 'first name' and 'last name' must be provided; 'email' must be unique. If password was not given it will be generated and returned with the created object, otherwise password field will be null (for safety reasons).
For user's roles the 'shortName' parameter is needed.
If it is absent or the role with given name does not exist
in database the IllegalArgumentException will be thrown.
create in interface UserRepositoryuser - A new user to persistpublic User update(User user)
UserRepository
For user's roles the 'shortName' parameter is needed.
If it is absent or the role with given name does not exist
in database the IllegalArgumentException will be thrown.
update in interface UserRepositoryuser - An existing user with new detailspublic void delete(User user)
UserRepositorydelete in interface UserRepositoryuser - A user to be removedpublic void deleteById(Long id)
UserRepositorydeleteById in interface UserRepositoryid - An id of user that needs to be removed