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

📄 clientsessionfacadebean.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 ClientSessionFacadeBean implements SessionBean {
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;
    /**
     * sessionContext
     */
    SessionContext sessionContext;
    /**
     * clientHome
     */
    private ClientHome clientHome;
    /**
     * ejbCreate
     * @throws CreateException e
     */
    public void ejbCreate() throws CreateException {
    }

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

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

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

    /**
     *
     * @param sessionContext SessionContext
     */
    public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
        try {
            findClientHome();
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }
    /**
     *
     * @param clientDto ClientDto
     * @throws EJBException e
     */
    public void createClient(ClientDto clientDto) throws EJBException {
        if (clientDto == null) {
            return;
        }
        try {
            Client client = clientHome.create(clientDto.getClientNo());
            setClientFromClientDto(client, clientDto);
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }

    /**
     *
     * @param clientNo Integer
     * @throws EJBException e
     */
    public void removeClient(Integer clientNo) throws EJBException {
    try {
            clientHome.remove(clientNo);
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }

    /**
     *
     * @param clientDto ClientDto
     * @throws EJBException e
     */
    public void removeClient(ClientDto clientDto) throws EJBException {
    if (clientDto != null) {
            Integer clientNo = clientDto.getClientNo();
            removeClient(clientNo);
        }
    }
    /**
     *
     * @param clientDto ClientDto
     * @throws EJBException e
     */
    public void updateClient(ClientDto clientDto) throws EJBException {
        if (clientDto != null) {
            Integer clientNo = clientDto.getClientNo();
            try {
                Client client = clientHome.findByPrimaryKey(clientNo);
                setClientFromClientDto(client, clientDto);
            } catch (Exception e) {
                throw new EJBException(e.getMessage());
            }
        }
    }
    /**
     *
     * @param clientDtos ClientDto[]
     * @throws EJBException e
     */
    public void updateClients(ClientDto[] clientDtos) throws EJBException {
        if (clientDtos != null) {
            for (int i = 0; i < clientDtos.length; i++) {
                updateClient(clientDtos[i]);
            }
        }
    }

    /**
     *
     * @param clientNo Integer
     * @return ClientDto
     * @throws EJBException e
     */
    public ClientDto clientFindByPrimaryKey(Integer clientNo) throws
    EJBException {
        try {
            return assembleClientDto(clientHome.findByPrimaryKey(clientNo));
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }
    /**
     *
     * @param idCardNo String
     * @return ClientDto
     * @throws EJBException e
     */
    public ClientDto clientFindByIdCardNo(String idCardNo) throws EJBException {
        try {
            return assembleClientDto(clientHome.findByIdCardNo(idCardNo));
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }
    /**
     *
     * @param client Client
     * @param clientDto ClientDto
     */
    private void setClientFromClientDto(Client client, ClientDto clientDto) {
        client.setClientName(clientDto.getClientName());
        client.setIdCardNo(clientDto.getIdCardNo());
        client.setSex(clientDto.getSex());
        client.setPhone(clientDto.getPhone());
        client.setAddress(clientDto.getAddress());
        client.setEmail(clientDto.getEmail());
        client.setHobby(clientDto.getHobby());
        client.setCreatedDate(clientDto.getCreatedDate());
    }
    /**
     *
     * @throws EJBException e
     */
    private void findClientHome() throws EJBException {
         String entityName = "java:comp/env/ejb/client";
        if (clientHome == null) {
            try {
                ServiceLocator locator = ServiceLocator.getInstance();
                clientHome = (ClientHome) locator.getEjbLocalHome(entityName);
            } catch (ServiceLocatorException e) {
                throw new EJBException(e.getMessage());
            }
        }
    }
    /**
     *
     * @param client Client
     * @return ClientDto
     */
    private ClientDto assembleClientDto(Client client) {
        return ClientDtoAssembler.createDto(client);
    }

    /**
     *
     * @param clients Collection
     * @return ClientDto[]
     */
    private ClientDto[] assembleClientDtos(Collection clients) {
    List list = new ArrayList();
        if (clients != null) {
            Iterator iterator = clients.iterator();
            while (iterator.hasNext()) {
                Client client = (Client) iterator.next();
                list.add(assembleClientDto(client));
            }
        }
        ClientDto[] returnArray = new ClientDto[list.size()];
        return (ClientDto[]) list.toArray(returnArray);
    }
}

⌨️ 快捷键说明

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