public interface UserRepository
User entity.
For all methods where receiving the User object as a parameter
user id field is mandatory, otherwise that user can't be serviced.| Modifier and Type | Field and Description |
|---|---|
static int |
EMAIL_MIN
Logically, correct email address can't contain less
than 5 characters.
|
static int |
LONG_MAX
Maximal long field (like
last name) length - 70 characters |
static int |
NOT_EMPTY
Minimal string length is just not empty - 1 character
|
static int |
SHORT_MAX
Maximal short field (like
middle name) length - 45 characters |
| 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).
|
static final int EMAIL_MIN
static final int NOT_EMPTY
static final int LONG_MAX
last name) length - 70 charactersstatic final int SHORT_MAX
middle name) length - 45 charactersUser findById(Long id)
id - User's idIllegalArgumentException - if argument is nullEntityDoesNotExistException - if user with the id can't be foundAccessDataBaseException - if operation was unsuccessful
due to internal errorUser findByEmail(String email)
email - email addressIllegalArgumentException - if argument is null or emptyEntityDoesNotExistException - if user with the email can't be foundAccessDataBaseException - if operation was unsuccessful
due to internal errorUser create(User user)
User 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.
user - A new user to persistIllegalArgumentException - if user or its id is null or user has
incomplete or wrong informationEntityAlreadyExistsException - if user with the same
email already existsAccessDataBaseException - if operation was unsuccessful
due to internal errorUser update(User user)
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.
user - An existing user with new detailsIllegalArgumentException - if user or its id is null or user has
incomplete or wrong informationEntityDoesNotExistException - if user can't be foundAccessDataBaseException - if operation was unsuccessful
due to internal errorvoid delete(User user)
user - A user to be removedIllegalArgumentException - if user or its id is nullEntityDoesNotExistException - if user can't be foundAccessDataBaseException - if operation was unsuccessful
due to internal errorvoid deleteById(Long id)
id - An id of user that needs to be removedIllegalArgumentException - if id is nullEntityDoesNotExistException - if user can't be foundAccessDataBaseException - if operation was unsuccessful
due to internal error