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

📄 customerbean.java

📁 《Developing Applications with Java and UML》一书的源代码。
💻 JAVA
字号:
package com.jacksonreed;import java.io.Serializable;import java.util.Enumeration;import java.util.Vector;import java.util.Collection;import javax.naming.InitialContext;import javax.naming.NamingException;import java.util.List;import java.util.Iterator;import java.util.ArrayList;/** * This is the Customer bean * * @author Paul Reed, Jackson-Reed, Inc. <prreed@jacksonreed.com> * @version 1.0 */public class CustomerBean implements java.io.Serializable {   private Integer customerId;   private String customerNumber;   private String firstName;   private String middleInitial;   private String prefix;   private String suffix;   private String lastName;   private String phone1;   private String phone2;   private String EMail;   private ArrayList roleValue;   private ArrayList orderValue;   public void CustomerBean() {      roleValue = new ArrayList();      orderValue = new ArrayList();   }   public Integer getCustomerId() {      return customerId;   }   public void setCustomerId(Integer val) {       customerId = val;   }   public String getCustomerNumber() {       return customerNumber;   }   public void setCustomerNumber(String val) {       customerNumber = val;   }   public String getFirstName(){       return firstName;   }   public void setFirstName(String val){       firstName = val;   }   public String getMiddleInitial(){       return middleInitial;   }   public void setMiddleInitial(String val){       middleInitial = val;   }   public String getPrefix(){       return prefix;   }   public void setPrefix(String val){       prefix = val;   }   public String getSuffix(){       return suffix;   }   public void setSuffix(String val){       suffix = val;   }   public String getLastName(){       return lastName;   }   public void setLastName(String val){       lastName = val;   }   public String getPhone1(){       return phone1;   }   public void setPhone1(String val){       phone1 = val;   }   public String getPhone2(){       return phone2;   }   public void setPhone2(String val){       phone2 = val;   }   public String getEMail(){       return EMail;   }   public void setEMail(String val){      EMail = val;   }  /**   public ArrayList getRoleValue(){       return roleValue;   }   public void setRoleValue(ArrayList val){       roleValue = val;   }   public ArrayList getOrderValue(){       return orderValue;   }   public void setOrderValue(ArrayList val){       orderValue = val;   }   public Collection getRoles(){        return new ArrayList();        }   public void setRoles(Collection Role) {   }   public Collection getOrders(){        return new ArrayList();        }   public void setOrders(Collection Role){   }   */  /**     * Returns an CustomerBean initialized with the information     * found in the database for the specified employee, or null if     * not found.     */   public CustomerValue findByCustomerNumber(TransactionContext transactionContext, String customerNumber)        throws RemulakFinderException, Exception {        try {          // Get the information from the DAO object          log("CustomerBean: Before DAO");          DataAccess custDAO = new CustomerDAO(transactionContext);          CustomerValue custVal = (CustomerValue) custDAO.findByName(customerNumber);          log("CustomerBean: After DAO");          // Sets the values of this object with the DAO results          setCustomerValue(custVal);          custDAO = null;          return custVal;        }        catch (DAOSysException se) {          log("CustomerBean: Fatal Error Occurred");          throw new Exception (se.getMessage());        }        catch (DAOFinderException fe) {          log("CustomerBean: Couldnt find key");          throw new RemulakFinderException (fe.getMessage());        }  }  /**     * Updates a customer     *   */   public void customerUpdate(TransactionContext transactionContext, CustomerValue custVal)        throws RemulakFinderException, Exception {        try {          // Get the information from the DAO object          log("CustomerBean: Before DAO");          setCustomerValue(custVal);          DataAccess custDAO = new CustomerDAO(transactionContext);          custDAO.updateObject(custVal);          log("CustomerBean: After DAO");          custDAO = null;        }        catch (DAOSysException se) {          log("CustomerBean: message = " + se.getMessage());          log("CustomerBean: Fatal Error Occurred");          throw new Exception (se.getMessage());        }        catch (DAODBUpdateException ue) {          log("CustomerBean: Couldnt find row to update/delete ");          throw new Exception (ue.getMessage());        }  }  /**     * Inserts a new customer     *     *  */   public void customerInsert(TransactionContext transactionContext, CustomerValue custVal)        throws RemulakFinderException, Exception {        try {          // Get the information from the DAO object          log("CustomerBean: Before DAO");          setCustomerValue(custVal);          DataAccess custDAO = new CustomerDAO(transactionContext);          custDAO.insertObject(custVal);          log("CustomerBean: After DAO");          custDAO = null;        }        catch (DAOSysException se) {          log("CustomerBean: message = " + se.getMessage());          log("CustomerBean: Fatal Error Occurred");          throw new Exception (se.getMessage());        }        catch (DAODBUpdateException ue) {          log("CustomerBean: Couldnt find row to update/delete ");          throw new Exception (ue.getMessage());        }  }  /**     * Inserts a new customer     *     *  */   public void customerDelete(TransactionContext transactionContext, Integer customerId)        throws RemulakFinderException, Exception {        try {          // Get the information from the DAO object          log("CustomerBean: Before DAO");          DataAccess custDAO = new CustomerDAO(transactionContext);          custDAO.deleteObject(customerId);          log("CustomerBean: After DAO");          custDAO = null;        }        catch (DAOSysException se) {          log("CustomerBean: message = " + se.getMessage());          log("CustomerBean: Fatal Error Occurred");          throw new Exception (se.getMessage());        }        catch (DAODBUpdateException ue) {          log("CustomerBean: Couldnt find row to update/delete ");          throw new Exception (ue.getMessage());        }  }  /**  public void addRole(Role Role)  {    log("CustomerBean.addRoles");    Collection Roles = getRoles();    Roles.add(Role);  }  public Collection getAllRoles()  {    log("CustomerBean.getAllRoles");    List returnList = new ArrayList();    Collection Roles = getRoles();    Iterator iter = Roles.iterator();    log("roles--------****------------------");    while (iter.hasNext()) {      Object ob = iter.next();      log(ob.getClass().getName());      returnList.add(ob);    }    return returnList;  }  public void addOrder(Order Order)  {    log("CustomerBean.addOrders");    Collection Orders = getOrders();    Orders.add(Order);  }  public Collection getAllOrders()  {    log("CustomerBean.getAllOrders");    List returnList = new ArrayList();    Collection Orders = getOrders();    Iterator iter = Orders.iterator();    log("Orders----------***-----------------");    while (iter.hasNext()) {      Object ob = iter.next();      log(ob.getClass().getName());      returnList.add(ob);    }    return returnList;  }  */  public CustomerValue getCustomerValue() {    CustomerValue myCustVal = new CustomerValue();    myCustVal.setCustomerId(getCustomerId());    myCustVal.setCustomerNumber(getCustomerNumber());    myCustVal.setFirstName(getFirstName());    myCustVal.setMiddleInitial(getMiddleInitial());    myCustVal.setPrefix(getPrefix());    myCustVal.setSuffix(getSuffix());    myCustVal.setLastName(getLastName());    myCustVal.setPhone1(getPhone1());    myCustVal.setPhone2(getPhone2());    myCustVal.setEMail(getEMail());    /**    // Get the RoleValue objects by iterating over the Roles collection    ArrayList returnList = new ArrayList();    Iterator roleIter = getRoles().iterator();    if(! roleIter.hasNext()) {      log("  No roles for this customer");    }    else {        while (roleIter.hasNext()) {          Role role = (Role) roleIter.next();          RoleValue roleValue = role.getRoleValue();          roleValue.setCustomerValue(myCustVal);          //      List returnList = new ArrayList();          returnList.add(roleValue);         }    }    myCustVal.setRoleValue(returnList);    */    return myCustVal;  }  public void setCustomerValue(CustomerValue val)  {    log("Setting Customer Value");    setCustomerId(val.getCustomerId());    setCustomerNumber(val.getCustomerNumber());    setFirstName(val.getFirstName());    setMiddleInitial(val.getMiddleInitial());    setPrefix(val.getPrefix());    setSuffix(val.getSuffix());    setLastName(val.getLastName());    setPhone1(val.getPhone1());    setPhone2(val.getPhone2());    setEMail(val.getEMail());  }  public String toString() {    return "[CustomerBean (" + getCustomerId() + ", " + getFirstName() + ", " + getLastName() + "]";  }  private void log(String s) {    System.out.println(s);  }}

⌨️ 快捷键说明

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