customerfacadebean.java

来自「A J2EE & Jsp Example」· Java 代码 · 共 118 行

JAVA
118
字号
/* * * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. *  * This software is the proprietary information of Sun Microsystems, Inc.   * Use is subject to license terms. * The code in this example is offered under the license at:  * http://wireless.java.sun.com/berkeley_license.html * */package customerejb;import java.util.*;import javax.ejb.*;public class CustomerFacadeBean implements javax.ejb.SessionBean {    private javax.ejb.SessionContext context;    private Customer customer = null;    CustomerHome home = null;    String jndiCustomerName  = "java:comp/env/ejb/Customer";        /**     * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)     */    public void setSessionContext(javax.ejb.SessionContext aContext) {        context=aContext;    }            /**     * @see javax.ejb.SessionBean#ejbActivate()     */    public void ejbActivate() {            }            /**     * @see javax.ejb.SessionBean#ejbPassivate()     */    public void ejbPassivate() {            }            /**     * @see javax.ejb.SessionBean#ejbRemove()     */    public void ejbRemove() {            }            /**     * See section 7.10.3 of the EJB 2.0 specification     */    public void ejbCreate() {           }        public CustomerTO getCustomer(java.lang.String customerId)throws CustomerException {        try {            return getEntity(customerId).getCustomer();        } catch (Exception e) {                    throw new CustomerException("Cannot get customer", e);        }    }        public CustomerTO createCustomer(CustomerTO customerTO) throws CustomerException {          try {            LocalCustomerHome home =  getEntityHome();            LocalCustomer localCustomer = home.create(customerTO);            return customerTO;        } catch (Exception e) {              throw new CustomerException("Cannot create customer", e);        }    }        public void removeCustomer(java.lang.String customerId)throws CustomerException {         try {            getEntity(customerId).remove();        } catch (Exception e) {            throw new CustomerException("Cannot remove customer", e);        }    }        public void updateCustomer(CustomerTO customerTO) throws CustomerException {        try {            LocalCustomer localCustomer =getEntity(customerTO.getCustomerId());            localCustomer.updateCustomer(customerTO);        } catch (Exception e) {            throw new CustomerException("Cannot update customer", e);        }    }    /** Retrieves the local interface of the Customer entity bean. */    private LocalCustomer getEntity(String customerId)            throws CustomerException {        try {            LocalCustomerHome home = getEntityHome();            return home.findByPrimaryKey(customerId);        } catch (Exception e) {            throw new CustomerException("Cannot locate CustomerHome", e);        }    }         /** Retrieves the local home interface of the Customer intity bean. */    private final LocalCustomerHome getEntityHome()            throws ServiceLocatorException {        ServiceLocator locator = ServiceLocator.getInstance();        LocalCustomerHome home = (LocalCustomerHome) locator.getLocalHome(jndiCustomerName);        System.out.println( "CustomerFacade: locator.getLocalHome");        return home;    }    }

⌨️ 快捷键说明

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