⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fundaccountsessionfacadebean.java

📁 EJB+Struts+Webservice实现的开放式基金管理系统
💻 JAVA
字号:
package com.fund.client;

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import com.fund.ServiceLocator;
import com.fund.ServiceLocatorException;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collection;
import javax.ejb.EJBException;

/**
 *
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class FundAccountSessionFacadeBean implements SessionBean {
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /**
     * sessionContext
     */
    SessionContext sessionContext;

    /**
     * fundAccountHome
     */
    private FundAccountHome fundAccountHome;

    /**
     * ejbCreate
     * @throws CreateException e
     */
    public void ejbCreate() throws CreateException {
    }

    /**
     * ejbRemove
     */
    public void ejbRemove() {
    }

    /**
     * ejbActivate
     */
    public void ejbActivate() {
    }

    /**
     * ejbPassivate
     */
    public void ejbPassivate() {
    }

    /**
     * setSessionContext
     * @param sessionContext SessionContext
     */
    public void setSessionContext(SessionContext sessionContext) {
        this.sessionContext = sessionContext;
        try {
            findFundAccountHome();
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }

    /**
     * createFundAccount
     * @param fundAccountDto FundAccountDto
     * @return Integer
     * @throws EJBException e
     */
    public Integer createFundAccount(FundAccountDto fundAccountDto) throws
            EJBException {
        Integer fundAccountNo = new Integer(0);

        try {
            FundAccount fundAccount = fundAccountHome.create(fundAccountDto
                    .getFundAccNo());
            setFundAccountFromFundAccountDto(fundAccount, fundAccountDto);
            fundAccountNo = fundAccount.getFundAccNo();
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
        return fundAccountNo;
    }

    /**
     * removeFundAccount
     * @param fundAccNo Integer
     * @throws EJBException e
     */
    public void removeFundAccount(Integer fundAccNo) throws EJBException {
        try {
            fundAccountHome.remove(fundAccNo);
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }

    /**
     * removeFundAccount
     * @param fundAccountDto FundAccountDto
     * @throws EJBException e
     */
    public void removeFundAccount(FundAccountDto fundAccountDto) throws
            EJBException {
        if (fundAccountDto != null) {
            Integer fundAccNo = fundAccountDto.getFundAccNo();
            removeFundAccount(fundAccNo);
        }
    }

    /**
     * updateFundAccount
     * @param fundAccountDto FundAccountDto
     * @throws EJBException e
     */
    public void updateFundAccount(FundAccountDto fundAccountDto) throws
            EJBException {
        if (fundAccountDto != null) {
            Integer fundAccNo = fundAccountDto.getFundAccNo();
            try {
                FundAccount fundAccount = fundAccountHome
                                          .findByPrimaryKey(fundAccNo);
                setFundAccountFromFundAccountDto(fundAccount, fundAccountDto);
            } catch (Exception e) {
                throw new EJBException(e.getMessage());
            }
        }
    }

    /**
     * updateFundAccounts
     * @param fundAccountDtos FundAccountDto[]
     * @throws EJBException e
     */
    public void updateFundAccounts(FundAccountDto[] fundAccountDtos) throws
            EJBException {
        if (fundAccountDtos != null) {
            for (int i = 0; i < fundAccountDtos.length; i++) {
                updateFundAccount(fundAccountDtos[i]);
            }
        }
    }

    /**
     *
     * @param fundAccNo Integer
     * @return FundAccountDto
     * @throws EJBException e
     */
    public FundAccountDto fundAccountFindByPrimaryKey(Integer fundAccNo) throws
            EJBException {
        try {
            return assembleFundAccountDto(fundAccountHome
                                          .findByPrimaryKey(fundAccNo));
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }

    /**
     *
     * @param financialAccNo Integer
     * @return FundAccountDto[]
     * @throws EJBException e
     */
    public FundAccountDto[] fundAccountFindByFinancialAccNo(
            Integer financialAccNo) throws EJBException {
        try {
            return assembleFundAccountDtos(fundAccountHome
             .findByFinancialAccNo(financialAccNo));
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }

    /**
     *
     * @param fundAccount FundAccount
     * @param fundAccountDto FundAccountDto
     */
    private void setFundAccountFromFundAccountDto(FundAccount fundAccount,
                                                  FundAccountDto fundAccountDto)
    {
        fundAccount.setFinancialAccNo(fundAccountDto.getFinancialAccNo());
        fundAccount.setFundNo(fundAccountDto.getFundNo());
        fundAccount.setQuantity(fundAccountDto.getQuantity());
        fundAccount.setPrice(fundAccountDto.getPrice());
    }

    /**
     * findFundAccountHome
     * @throws EJBException e
     */
    private void findFundAccountHome() throws EJBException {
        final String entityName = "java:comp/env/ejb/fundAccount";
        if (fundAccountHome == null) {
            try {
                ServiceLocator locator = ServiceLocator.getInstance();
                fundAccountHome = (FundAccountHome) locator
                                  .getEjbLocalHome(entityName);
            } catch (ServiceLocatorException e) {
                throw new EJBException(e.getMessage());
            }
        }
    }

    /**
     *
     * @param fundAccount FundAccount
     * @return FundAccountDto
     */
    private FundAccountDto assembleFundAccountDto(FundAccount fundAccount) {
        return FundAccountDtoAssembler.createDto(fundAccount);
    }

    /**
     *
     * @param fundAccounts Collection
     * @return FundAccountDto[]
     */
    private FundAccountDto[] assembleFundAccountDtos(Collection fundAccounts) {
        List list = new ArrayList();
        if (fundAccounts != null) {
            Iterator iterator = fundAccounts.iterator();
            while (iterator.hasNext()) {
                FundAccount fundAccount = (FundAccount) iterator.next();
                list.add(assembleFundAccountDto(fundAccount));
            }
        }
        FundAccountDto[] returnArray = new FundAccountDto[list.size()];
        return (FundAccountDto[]) list.toArray(returnArray);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -