@Transactional @Override public void delete(UserDto userDto) { if (userDto == null) { throw new NullPointerException(); } User user = userConverter.userDtoToEntity(userDto); UserRole userRole = userRoleDao.findByUser(user); userRoleDao.delete(userRole); userDao.delete(user); }
@Transactional @Override public UserDto update(UserDto userDto) { if (userDto == null) { throw new NullPointerException(); } User user = userConverter.userDtoToEntity(userDto); UserRole userRole = userRoleDao.findByUser(user); userRole.setRole(userDto.getRole()); userRoleDao.update(userRole); return userConverter.userEntityToDto(userDao.update(user)); }
@Transactional @Override public UserDto findByNick(String nick) { User user = userDao.findByNick(nick); UserRole userRole = userRoleDao.findByUser(user); UserDto userDto = userConverter.userEntityToDto(user); userDto.setRole(userRole.getRole()); return userDto; }
@Transactional @Override public List<UserDto> findAll() { List<User> userList = userDao.findAll(); List<UserDto> resultList = new ArrayList(); for (User user : userList) { UserDto userDto = userConverter.userEntityToDto(user); UserRole userRole = userRoleDao.findByUser(user); userDto.setRole(userRole.getRole()); resultList.add(userDto); } return resultList; }
@Transactional @Override public long save(UserDto userDto) { if (userDto == null) { throw new NullPointerException(); } UserRole userRole = new UserRole(); User user = userConverter.userDtoToEntity(userDto); userRole.setUser(user); userRole.setRole(userDto.getRole()); Long id = userDao.save(user); userRoleDao.save(userRole); return id; }