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

📄 ucmaintainrltnshp.java

📁 《Developing Applications with Java and UML》一书的源代码。
💻 JAVA
字号:
package com.jacksonreed;import java.util.Enumeration;import java.util.Random;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.naming.NamingException;/** * UCMaintainRltnshp is a controller class that maps to the * Maintain Relationships Use Case in Remulak. There is one controller * class for each use case. There is also (at a minimum) one method per * pathway found in the use case. * * In the current Tomcat implementation, only the Customer Add, Update, Delete, * and inquiry functionality exists. For address Add, Update, Delete in  * conjuction with customer add, update, delete...see the EJB implementation * * This is implemented in the spirit of the GOF Facade pattern * * @author Paul Reed, Jackson-Reed, Inc. <prreed@jacksonreed.com> * @version 1.0 */public class UCMaintainRltnshp implements java.io.Serializable {  private static Random generator;  private static TransactionContext transactionContext;  public UCMaintainRltnshp() {      transactionContext = new TransactionContext();      log("created transaction context");  }  public CustomerValue rltnCustomerInquiry(String customerNumber){      CustomerValue customerValue = new CustomerValue();      CustomerBean customerHome = new CustomerBean();      log("UCController: Getting Customer with Customer Number " + customerNumber);      try {      log("UCController: in try block ");          transactionContext.beginTran(false);          log("UCController: after beginTran ");          customerValue = customerHome.findByCustomerNumber(transactionContext, customerNumber);          log("UCController: after customerValue ");          transactionContext.commitTran();      } catch (RemulakFinderException fe) {      } catch (TranCommitException ce) {      } catch (TranSysException se) {      } catch (TranBeginException be) {      } catch (TranRollBackException re) {      } catch (Exception e) {      } finally {        customerHome = null;      }      log("UCController: Returning CustomerValue");      return customerValue;  }  /**   * Inquires on a address   *   * @param addressId Integer   * @return AddressValue object   *   * @business-method   */  public AddressValue rltnAddressInquiry(Integer addressId)     {     /**   Implemented only in EJB Implementation       AddressHome addressHome;      addressHome = lookupAddressHome();      log("Getting Address with Address Id " + addressId);      Address address = addressHome.findByAddressId(addressId);      return address.getAddressValue();      */      return new AddressValue();  }    public RoleValue rltnRoleInquiry(Integer roleId)       {      /** Implemented only in EJB Implementation      RoleHome roleHome;      roleHome = lookupRoleHome();      log("Getting Role with Role Id " + roleId);      Role role = roleHome.findByRoleId(roleId);      return role.getRoleValue();      */      return new RoleValue();  }  /**   * Adds a customer   *   * @param customerValue Object   * @return                  CustomerValue object   *   * @business-method   */  public void rltnAddCustomer(CustomerValue custVal) {      // seed random generator      seedRandomGenerator();      // generate a random integer as the key field      custVal.setCustomerId(generateRandomKey());      CustomerBean customerHome = new CustomerBean();      log("UCController: Inserting Customer with Customer Number " + custVal.getCustomerNumber());      try {          transactionContext.beginTran(true);          customerHome.customerInsert(transactionContext, custVal);          transactionContext.commitTran();      } catch (RemulakFinderException fe) {      } catch (TranCommitException ce) {        try {          transactionContext.rollBackTran();        }        catch (TranRollBackException ree) {        }      } catch (TranSysException se) {          try {          transactionContext.rollBackTran();        }        catch (TranRollBackException ree) {        }      } catch (TranBeginException be) {      } catch (TranRollBackException re) {      } catch (Exception e) {          try {          transactionContext.rollBackTran();        }        catch (TranRollBackException ree) {        }      } finally {        customerHome = null;      }      log("After create ");  }  /**   * Updates a customer   *   * @param customerValue Object   * @return                  void   *   * @business-method   */  public void rltnUpdateCustomer(CustomerValue custVal) {      CustomerBean customerHome = new CustomerBean();      log("UCController: Getting Customer with Customer Number " + custVal.getCustomerNumber());      try {          transactionContext.beginTran(true);          customerHome.customerUpdate(transactionContext, custVal);          transactionContext.commitTran();      } catch (RemulakFinderException fe) {      } catch (TranCommitException ce) {        try {          transactionContext.rollBackTran();        }        catch (TranRollBackException ree) {        }      } catch (TranSysException se) {          try {          transactionContext.rollBackTran();        }        catch (TranRollBackException ree) {        }      } catch (TranBeginException be) {      } catch (TranRollBackException re) {      } catch (Exception e) {          try {          transactionContext.rollBackTran();        }        catch (TranRollBackException ree) {        }      } finally {        customerHome = null;      }      log("UCController: Returning CustomerValue");  }  /**   * Deletes a customer   *   * @param customerId Integer   * @return                  void   *   * @business-method   */  public void rltnDeleteCustomer(Integer customerId) {      CustomerBean customerHome = new CustomerBean();      log("UCController: Deleting Customer with Customer Number " + customerId);      try {          transactionContext.beginTran(true);          customerHome.customerDelete(transactionContext, customerId);          transactionContext.commitTran();      } catch (RemulakFinderException fe) {      } catch (TranCommitException ce) {        try {          transactionContext.rollBackTran();        }        catch (TranRollBackException ree) {        }      } catch (TranSysException se) {          try {          transactionContext.rollBackTran();        }        catch (TranRollBackException ree) {        }      } catch (TranBeginException be) {      } catch (TranRollBackException re) {      } catch (Exception e) {          try {          transactionContext.rollBackTran();        }        catch (TranRollBackException ree) {        }      } finally {        customerHome = null;      }      log("UCController: Returning CustomerValue");  }  public void rltnAddAddress(AddressValue addrVal, CustomerValue custVal,            RoleValue roleVal)       {      /** Implemented only in EJB Implementation      // seed random generator      seedRandomGenerator();      RoleHome roleHome;      roleHome = lookupRoleHome();      AddressHome addressHome;      addressHome = lookupAddressHome();      CustomerHome customerHome;      customerHome = lookupCustomerHome();      // generate a random integer as the pk key field or Role      roleVal.setRoleId(generateRandomKey());      log("roleId Key " + roleVal.getRoleId());      // generate a random integer as the pk key field or Address      addrVal.setAddressId(generateRandomKey());      log("addrId Key " + addrVal.getAddressId());      // find the customer bean using the customerId      Customer customer = customerHome.findByCustomerId(custVal.getCustomerId());      Address myAddress = addressHome.create(addrVal);      log("addrId Key " + addrVal.getAddressId());      Address address = addressHome.findByAddressId(addrVal.getAddressId());      Role myRole = roleHome.create(roleVal, address, customer);      log("After create ");      */  }    public void rltnUpdateAddress(AddressValue addrVal, CustomerValue custVal,            RoleValue roleVal)       {      /** Implemented only in EJB Implementation      RoleHome roleHome;      roleHome = lookupRoleHome();      AddressHome addressHome;      addressHome = lookupAddressHome();      CustomerHome customerHome;      customerHome = lookupCustomerHome();      // find the address bean using the addressId      Address address = addressHome.findByAddressId(addrVal.getAddressId());      address.setAddressValue(addrVal);      // find the role bean using the roleId      Role role = roleHome.findByRoleId(roleVal.getRoleId());      role.setRoleValue(roleVal);      log("After update ");      */  }    public void rltnDeleteAddress(Integer addressId, Integer roleId)      {      /** Implemented only in EJB Implementation      RoleHome roleHome;      roleHome = lookupRoleHome();      AddressHome addressHome;      addressHome = lookupAddressHome();      // remove the bean using the primary key      addressHome.remove(addressId);      roleHome.remove(roleId);      log("After delete ");      */  }  private static void seedRandomGenerator() {    generator = new Random(System.currentTimeMillis());  }  private Integer generateRandomKey() {    Integer myInt = new Integer(generator.nextInt());    return myInt;  }  private static void log(String s) {    System.out.println(s);  }}

⌨️ 快捷键说明

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