Package net.octal.supinbank.service

Source Code of net.octal.supinbank.service.AccountService

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.octal.supinbank.service;

import com.google.common.base.Preconditions;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import net.octal.supinbank.dao.AccountDao;
import net.octal.supinbank.entity.Account;
import net.octal.supinbank.entity.Person;

/**
*
* @author octal
*/

@Stateless
public class AccountService {
   
   
    @EJB
    private AccountDao accountDao;
   
    public Account findAccountById(Long id) {
        return accountDao.findAccountById(id);
    }
   
    public List<Account> getAccountsByCustomer(Person customer) {
        return accountDao.getAccountsByCustomer(customer);
    }
   
    public Account withDrawAccount(Long accountId, Double amount) {
        Account account = accountDao.findAccountById(accountId);
        if (account != null) {
            Preconditions.checkArgument(account.getTotalAmount() >= amount);
            account.setTotalAmount(account.getTotalAmount() - amount);
        }
       
        return account;
    }
    public Account creditAccount(Long accountId, Double amount) {
        Account account = accountDao.findAccountById(accountId);
        if (account != null) {
            account.setTotalAmount(account.getTotalAmount() + amount);
        }
       
        return account;
    }

    public void withDrawAndCredit(Long fromAccountId, Long toAccountId, Double amount) {
        withDrawAccount(fromAccountId, amount);
        creditAccount(toAccountId, amount);
    }
   
}
TOP

Related Classes of net.octal.supinbank.service.AccountService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.