public void blockAccount(User user, String description) throws ServiceException { Session session = util.getSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); Operation operation = buildOperation(user, description, 0D); operationDao.save(operation); // TODO сделать множественность счетов Set<Account> accounts = user.getAccounts(); Long accountId = 0L; Iterator<Account> iterator = accounts.iterator(); while (iterator.hasNext()) { accountId = iterator.next().getId(); } Account account = accountDao.getById(accountId); account.setAccountStatus(AccountStatusType.BLOCKED); accountDao.update(account); transaction.commit(); logger.info(TRANSACTION_SUCCEEDED); } catch (DaoException e) { TransactionUtil.rollback(transaction, e); logger.error(TRANSACTION_FAILED, e); throw new ServiceException(TRANSACTION_FAILED + e); } }
public void updateAccountStatus(Long id, AccountStatusType status) throws ServiceException { Session session = util.getSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); Account account = accountDao.getById(id); account.setAccountStatus(status); accountDao.update(account); transaction.commit(); logger.info(TRANSACTION_SUCCEEDED); } catch (DaoException e) { TransactionUtil.rollback(transaction, e); logger.error(TRANSACTION_FAILED, e); throw new ServiceException(TRANSACTION_FAILED + e); } }