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

📄 testclient.java~46~

📁 一个四层结构的j2ee项目实例。对于初学者相当合适。欢迎下载使用。
💻 JAVA~46~
📖 第 1 页 / 共 2 页
字号:
    return ejbAccounts;  }  //----------------------------------------------------------------------------  // Methods that use Remote interface methods to access data through the bean  //----------------------------------------------------------------------------  public void setId(String id) {    if (ejbAccounts == null) {      System.out.println("Error in setId(): " + ERROR_NULL_REMOTE);      return ;    }    long startTime = 0;    if (logging) {      log("Calling setId(" + id + ")");      startTime = System.currentTimeMillis();    }    try {      ejbAccounts.setId(id);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: setId(" + id + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: setId(" + id + ")");      }      e.printStackTrace();    }  }  public String getId() {    String returnValue = "";    if (ejbAccounts == null) {      System.out.println("Error in getId(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling getId()");      startTime = System.currentTimeMillis();    }    try {      returnValue = ejbAccounts.getId();      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: getId()");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: getId()");      }      e.printStackTrace();    }    if (logging) {      log("Return value from getId(): " + returnValue + ".");    }    return returnValue;  }  public void setBal(double bal) {    if (ejbAccounts == null) {      System.out.println("Error in setBal(): " + ERROR_NULL_REMOTE);      return ;    }    long startTime = 0;    if (logging) {      log("Calling setBal(" + bal + ")");      startTime = System.currentTimeMillis();    }    try {      ejbAccounts.setBal(bal);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: setBal(" + bal + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: setBal(" + bal + ")");      }      e.printStackTrace();    }  }  public double getBal() {    double returnValue = 0f;    if (ejbAccounts == null) {      System.out.println("Error in getBal(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling getBal()");      startTime = System.currentTimeMillis();    }    try {      returnValue = ejbAccounts.getBal();      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: getBal()");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: getBal()");      }      e.printStackTrace();    }    if (logging) {      log("Return value from getBal(): " + returnValue + ".");    }    return returnValue;  }  public void setType(String type) {    if (ejbAccounts == null) {      System.out.println("Error in setType(): " + ERROR_NULL_REMOTE);      return ;    }    long startTime = 0;    if (logging) {      log("Calling setType(" + type + ")");      startTime = System.currentTimeMillis();    }    try {      ejbAccounts.setType(type);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: setType(" + type + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: setType(" + type + ")");      }      e.printStackTrace();    }  }  public String getType() {    String returnValue = "";    if (ejbAccounts == null) {      System.out.println("Error in getType(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling getType()");      startTime = System.currentTimeMillis();    }    try {      returnValue = ejbAccounts.getType();      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: getType()");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: getType()");      }      e.printStackTrace();    }    if (logging) {      log("Return value from getType(): " + returnValue + ".");    }    return returnValue;  }  public double deposit(double bal) {    double returnValue = 0f;    if (ejbAccounts == null) {      System.out.println("Error in deposit(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling deposit(" + bal + ")");      startTime = System.currentTimeMillis();    }    try {      returnValue = ejbAccounts.deposit(bal);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: deposit(" + bal + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: deposit(" + bal + ")");      }      e.printStackTrace();    }    if (logging) {      log("Return value from deposit(" + bal + "): " + returnValue + ".");    }    return returnValue;  }  public void testRemoteCallsWithDefaultArguments() {    if (ejbAccounts == null) {      System.out.println("Error in testRemoteCallsWithDefaultArguments(): " + ERROR_NULL_REMOTE);      return ;    }    setId("");    getId();    setBal(0f);    getBal();    setType("");    getType();    deposit(0f);  }  //----------------------------------------------------------------------------  // Utility Methods  //----------------------------------------------------------------------------  private void log(String message) {    if (message == null) {      System.out.println("-- null");      return ;    }    if (message.length() > MAX_OUTPUT_LINE_LENGTH) {      System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");    }    else {      System.out.println("-- " + message);    }  }  private EjbAccounts findOrCreateAccount(String id,  String accountType,double balance)    throws CreateException, FinderException, RemoteException  {    EjbAccounts remote = null;    try {      remote = (EjbAccounts)        PortableRemoteObject.narrow(ejbAccountsHome.findByPrimaryKey(id), EjbAccounts.class);    } catch (ObjectNotFoundException onfe) {      // the account id does not yet exist so create it.      remote = create(id,  accountType,balance);    }    return remote;  }  //Main method  public static void main(String[] args) {    TestClient client = new TestClient();    // Use the client object to call one of the Home interface wrappers    // above, to create a Remote interface reference to the bean.    // If the return value is of the Remote interface type, you can use it    // to access the remote interface methods.  You can also just use the    // client object to call the Remote interface wrappers.  }}

⌨️ 快捷键说明

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