Operation transactOperation(Operation src, boolean updated) throws OperationServiceException {
        Account account = src.getAccount();
        BigDecimal repositoryBalance;
        if (updated) {
            repositoryBalance = getRollbackBalance(src);
        } else {
            repositoryBalance = account.getBalance();
        }
        BigDecimal cost = src.getCost();
        OperationType type = src.getOperationType();
        BigDecimal updatedBalance = null;
        if (type == OperationType.expense || type == OperationType.transferFrom) {
            updatedBalance = repositoryBalance.subtract(cost);
            AmountValidator.notNegative(updatedBalance, IS_TOO_MUCH_TRANSACTION_AMOUNT);
        }
        if (type == OperationType.income || type == OperationType.transferTo) {
            updatedBalance = repositoryBalance.add(cost);
        }
        if (updatedBalance == null) {
            throw new OperationServiceException(INVALID_OPERATION_TYPE);
        }
        account.setBalance(updatedBalance);
        accountService.update(account);
        if (updated) {
            manager.merge(src);
        } else {
            manager.persist(src);
        }
        manager.flush();
        return src;
    }