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

📄 customermanagesessionbeantestclient1.java

📁 客户管理系统,很强大的功能,能完成日常生活中的大部分事务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package custom_management;

import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.lang.Long;
import java.util.Collection;
import java.util.Properties;
import java.util.Iterator;
import java.rmi.RemoteException;

public class CustomerManageSessionBeanTestClient1 {
  private static final String ERROR_NULL_REMOTE = "Remote interface reference is null.  It must be created by calling one of the Home interface methods first.";
  private static final int MAX_OUTPUT_LINE_LENGTH = 100;
  private boolean logging = true;
  private CustomerManageSession customerManageSession = null;
  private CustomerManageSessionHome customerManageSessionHome = null;

  //Construct the EJB test client
  public CustomerManageSessionBeanTestClient1() {
    initialize();
  }

  public void initialize() {
    long startTime = 0;
    if (logging) {
      log("Initializing bean access.");
      startTime = System.currentTimeMillis();
    }

    try {

      //get naming context
      Context context = getInitialContext();
      //look up jndi name
      Object ref = context.lookup("CustomerManageSessionBean");
      //look up jndi name and cast to Home interface
      customerManageSessionHome = (CustomerManageSessionHome)
          PortableRemoteObject.narrow(ref, CustomerManageSessionHome.class);
      if (logging) {
        log("Succeeded initializing bean access through Home interface.");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }

    }
    catch (Exception e) {
      if (logging) {
        log("Failed initializing bean access.");
      }
      e.printStackTrace();
    }

  }

  public Context getInitialContext() throws Exception {
    String url = "t3://localhost:7001";
    String user = null;
    String password = null;
    Properties properties;
    try {
      properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY,
                     "weblogic.jndi.WLInitialContextFactory");
      properties.put(Context.PROVIDER_URL, url);
      if (user != null) {
        properties.put(Context.SECURITY_PRINCIPAL, user);
        properties.put(Context.SECURITY_CREDENTIALS,
                       password == null ? "" : password);
      }
      return new javax.naming.InitialContext(properties);
    }
    catch (Exception e) {
      log("Unable to connect to WebLogic server at " + url);
      log("Please make sure that the server is running.");
      throw e;
    }
  }

  //----------------------------------------------------------------------------
  // Methods that use Home interface methods to generate a Remote interface reference
  //----------------------------------------------------------------------------

  public CustomerManageSession create() {
    long startTime = 0;
    if (logging) {
      log("Calling create()");
      startTime = System.currentTimeMillis();
    }

    try {
      customerManageSession = customerManageSessionHome.create();
      if (logging) {
        log("Succeeded: create()");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : create()");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from create(): " + customerManageSession + ".");
    }
    return customerManageSession;
  }

  //----------------------------------------------------------------------------
  // Methods that use Remote interface methods to access data through the bean
  //----------------------------------------------------------------------------

  public EmployeeObject getWbEployeeBySn(Long sn) {
    EmployeeObject returnValue = null;
    if (customerManageSession == null) {
      System.out.println("Error in getWbEployeeBySn(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getWbEployeeBySn(" + sn + ")");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = customerManageSession.getWbEployeeBySn(sn);
      if (logging) {
        log("Succeeded: getWbEployeeBySn(" + sn + ")");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getWbEployeeBySn(" + sn + ")");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getWbEployeeBySn(" + sn + "): " + returnValue +
          ".");
    }
    return returnValue;
  }

  public RoleObject getWbRoleById(Long id) {
    RoleObject returnValue = null;
    if (customerManageSession == null) {
      System.out.println("Error in getWbRoleById(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getWbRoleById(" + id + ")");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = customerManageSession.getWbRoleById(id);
      if (logging) {
        log("Succeeded: getWbRoleById(" + id + ")");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getWbRoleById(" + id + ")");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getWbRoleById(" + id + "): " + returnValue + ".");
    }
    return returnValue;
  }

  public Collection getWbEmployeeBeans() {
    Collection returnValue = null;
    if (customerManageSession == null) {
      System.out.println("Error in getWbEmployeeBeans(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getWbEmployeeBeans()");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = customerManageSession.getWbEmployeeBeans();
      if (logging) {
        log("Succeeded: getWbEmployeeBeans()");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getWbEmployeeBeans()");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getWbEmployeeBeans(): " + returnValue + ".");
    }
    return returnValue;
  }

  public Collection getWbRoleBeans() {
    Collection returnValue = null;
    if (customerManageSession == null) {
      System.out.println("Error in getWbRoleBeans(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getWbRoleBeans()");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = customerManageSession.getWbRoleBeans();
      if (logging) {
        log("Succeeded: getWbRoleBeans()");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getWbRoleBeans()");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getWbRoleBeans(): " + returnValue + ".");
    }
    return returnValue;
  }

  public String saveNewEmployee(EmployeeObject newEmployee,
                                Collection roleMapped) {
    String returnValue = "";
    if (customerManageSession == null) {
      System.out.println("Error in saveNewEmployee(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling saveNewEmployee(" + newEmployee + ", " + roleMapped + ")");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = customerManageSession.saveNewEmployee(newEmployee,
          roleMapped);
      if (logging) {
        log("Succeeded: saveNewEmployee(" + newEmployee + ", " + roleMapped +
            ")");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : saveNewEmployee(" + newEmployee + ", " + roleMapped + ")");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from saveNewEmployee(" + newEmployee + ", " +
          roleMapped + "): " + returnValue + ".");
    }
    return returnValue;
  }

  public String saveNewRole(RoleObject newRole, Collection employeeMapped) {
    String returnValue = "";
    if (customerManageSession == null) {
      System.out.println("Error in saveNewRole(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling saveNewRole(" + newRole + ", " + employeeMapped + ")");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = customerManageSession.saveNewRole(newRole, employeeMapped);
      if (logging) {
        log("Succeeded: saveNewRole(" + newRole + ", " + employeeMapped + ")");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : saveNewRole(" + newRole + ", " + employeeMapped + ")");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from saveNewRole(" + newRole + ", " + employeeMapped +
          "): " + returnValue + ".");
    }
    return returnValue;
  }

  public String deleteEmployeeBySns(Long[] sns) {
    String returnValue = "";
    if (customerManageSession == null) {
      System.out.println("Error in deleteEmployeeBySns(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;

⌨️ 快捷键说明

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