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

📄 accountaccessdelegate.java

📁 我在加拿大学习的一个比较复杂的在线银行程序.
💻 JAVA
字号:
package com.ebusiness.ebank.servicedelegate;/** * <p>Title: </p> * <p>Description:  Delegate is a bridge class interacting between front-tier and middle tier. *                  With this class, the back-end business lodic is isolated from *                  front-end. Front-end developers can focus on the presentation layer. * *                  Since the Delegate can be used either within eBank application *                  or by other applications, please do not use struts and Log service *                  within the delegate classes. *                  </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: eBusiness Inc., All right reserved</p> * @author * @version 1.0 */import java.rmi.RemoteException;import javax.ejb.EJBException;import javax.ejb.CreateException;import com.ebusiness.ebank.bean.AccountValue;import com.ebusiness.ebank.bean.ValueList;import com.ebusiness.ebank.bean.StatementValue;import com.ebusiness.ebank.criteria.SearchCriteria;import com.ebusiness.ebank.ejb.sessionbean.AccountAccessLocalHome;import com.ebusiness.ebank.ejb.sessionbean.AccountAccessLocal;import com.ebusiness.ebank.ejb.sessionbean.AccountAccessHome;import com.ebusiness.ebank.ejb.sessionbean.AccountAccess;import com.ebusiness.ebank.exception.SystemException;import com.ebusiness.ebank.exception.BusinessException;import com.ebusiness.ebank.util.Constants;public class AccountAccessDelegate{    private static AccountAccessHome home;    private static AccountAccessLocalHome localHome;    private static boolean isLocal; //Indicate if the Delegate can use local call to ejb tier    //Instantiate it and initialize AccountAccess local Home or AccountAccess remote Home object    static    {        try        {            localHome = (AccountAccessLocalHome)ServiceLocator.getInstance().getLocalHome(Constants.ACCOUNT_ACCESS_LOCALHOME);        }        catch (ServiceLocatorException sle){}        if (localHome != null)            isLocal = true; //can use local call        else //must use remote call        {            try            {                home = (AccountAccessHome)ServiceLocator.getInstance().getRemoteHome(Constants.ACCOUNT_ACCESS_HOME, AccountAccessHome.class);            }            catch (ServiceLocatorException sle){}        }    }    //The following are the delegated business methods. It has an one-to-one    //relationship with AccountAccess Session Bean    /**     * @Description:    View Account data     * @return:         AccountValue     */     public static AccountValue viewAccountByOID(long oid, String accountType) throws SystemException, BusinessException     {         AccountValue newValue = null;         try          {              if(isLocal)              {                  AccountAccessLocal accountAccessLocal = localHome.create();                  newValue = accountAccessLocal.viewAccountByOID(oid, accountType);              }              else              {                  AccountAccess accountAccess = home.create();                  newValue = accountAccess.viewAccountByOID(oid, accountType);              }          }          catch(CreateException ce)          {              throw new SystemException(ce);          }          catch(EJBException ee)          {             throw new SystemException(ee);          }          catch(RemoteException re)          {             throw new SystemException(re);          }          return newValue;     }     /**         * @Description:    Update Account data         * @param:          AccountValue         * @return:         AccountValue         */       public static AccountValue updateAccount(AccountValue value) throws SystemException, BusinessException       {           AccountValue newValue = null;           try           {               if(isLocal)               {                   AccountAccessLocal accountAccessLocal = localHome.create();                   newValue = accountAccessLocal.updateAccount(value);               }               else               {                   AccountAccess accountAccess = home.create();                   newValue = accountAccess.updateAccount(value);               }           }           catch(CreateException ce)           {               throw new SystemException(ce);           }           catch(EJBException ee)           {              throw new SystemException(ee);           }           catch(RemoteException re)           {              throw new SystemException(re);           }           return newValue;       }       /**          * @Description:    Insert a new record for Account table          * @param:          AccountValue          * @return:         AccountValue          */       public static AccountValue createAccount(AccountValue value) throws SystemException, BusinessException       {           AccountValue newValue=null;           try           {               if(isLocal)               {                   AccountAccessLocal accountAccessLocal = localHome.create();                   newValue = accountAccessLocal.createAccount(value);               }               else               {                   AccountAccess accountAccess = home.create();                   newValue = accountAccess.createAccount(value);               }           }           catch(CreateException ce)           {               throw new SystemException(ce);           }           catch(EJBException ee)           {              throw new SystemException(ee);           }           catch(RemoteException re)           {              throw new SystemException(re);           }           return newValue;       }    /**     * @Description:    View Account data     * @return:         AccountValue     */     public static AccountValue viewAccountByCardID(String cardID, String accountType) throws SystemException, BusinessException     {         AccountValue newValue = null;         try          {              if(isLocal)              {                  AccountAccessLocal accountAccessLocal = localHome.create();                  newValue = accountAccessLocal.viewAccountByCardID(cardID, accountType);              }              else              {                  AccountAccess accountAccess = home.create();                  newValue = accountAccess.viewAccountByCardID(cardID, accountType);              }          }          catch(CreateException ce)          {              throw new SystemException(ce);          }          catch(EJBException ee)          {             throw new SystemException(ee);          }          catch(RemoteException re)          {             throw new SystemException(re);          }          return newValue;     }     /**      * @Description:    View Account data      * @return:         AccountValue      */      public static AccountValue viewAccountByAccountNo(String accountNo, String accountType) throws SystemException, BusinessException      {          AccountValue newValue = null;          try           {               if(isLocal)               {                   AccountAccessLocal accountAccessLocal = localHome.create();                   newValue = accountAccessLocal.viewAccountByAccountNo(accountNo, accountType);               }               else               {                   AccountAccess accountAccess = home.create();                   newValue = accountAccess.viewAccountByAccountNo(accountNo, accountType);               }           }           catch(CreateException ce)           {               throw new SystemException(ce);           }           catch(EJBException ee)           {              throw new SystemException(ee);           }           catch(RemoteException re)           {              throw new SystemException(re);           }           return newValue;      }    /**    * @Description:    Search a list of Accounts belonging to the Client with the specified clientCard ID.    * @return:         CardholderValue    */    public static ValueList searchAccount(String cardID) throws SystemException, BusinessException    {        ValueList results = null;        try        {            if(isLocal)            {                AccountAccessLocal accountAccessLocal = localHome.create();                results = accountAccessLocal.searchAccount(cardID);            }            else            {                AccountAccess accountAccess = home.create();                results = accountAccess.searchAccount(cardID);            }        }        catch(CreateException ce)        {            throw new SystemException(ce);        }        catch(EJBException ee)        {           throw new SystemException(ee);        }        catch(RemoteException re)        {           throw new SystemException(re);        }        return results;    }    /**      * @Description:    Search a list of value beans based on the specified criteria      * @return:         ValueList that contains value beans      */      public static ValueList search(SearchCriteria criteria) throws SystemException, BusinessException      {          ValueList results = null;          try          {              if(isLocal)              {                  AccountAccessLocal accountAccessLocal = localHome.create();                  results = accountAccessLocal.search(criteria);              }              else              {                  AccountAccess accountAccess = home.create();                  results = accountAccess.search(criteria);              }          }          catch(CreateException ce)          {              throw new SystemException(ce);          }          catch(EJBException ee)          {             throw new SystemException(ee);          }          catch(RemoteException re)          {             throw new SystemException(re);          }          return results;      }     /**       * @Description:    Delete Account data. Used by Admin User only       * @param:          AccountValue       * @return:       */      public static void deleteAccount(AccountValue value) throws SystemException, BusinessException      {           try           {               if(isLocal)               {                   AccountAccessLocal accountAccessLocal = localHome.create();                   accountAccessLocal.deleteAccount(value);               }               else               {                   AccountAccess accountAccess = home.create();                   accountAccess.deleteAccount(value);               }           }           catch(CreateException ce)           {               throw new SystemException(ce);           }           catch(EJBException ee)           {              throw new SystemException(ee);           }           catch(RemoteException re)           {              throw new SystemException(re);           }      }    /**     * @Description:    Deposit the specified money to the specified Account     * @return:         The updated AccountValue bean     */     public static AccountValue deposit(StatementValue sValue) throws           SystemException, BusinessException    {        AccountValue newValue = null;        try        {              if(isLocal)              {                  AccountAccessLocal accountAccessLocal = localHome.create();                  newValue = accountAccessLocal.deposit(sValue);              }              else              {                  AccountAccess accountAccess = home.create();                  newValue = accountAccess.deposit(sValue);              }          }          catch(CreateException ce)          {              throw new SystemException(ce);          }          catch(EJBException ee)          {             throw new SystemException(ee);          }          catch(RemoteException re)          {             throw new SystemException(re);          }          return newValue;      }    /**     * @Description:    Withdrawal the specified money from the specified Account     * @return:         The updated AccountValue bean     */     public static AccountValue withdrawal(StatementValue sValue) throws            SystemException, BusinessException     {          AccountValue newValue = null;          try          {                if(isLocal)                {                    AccountAccessLocal accountAccessLocal = localHome.create();                    newValue = accountAccessLocal.withdrawal(sValue);                }                else                {                    AccountAccess accountAccess = home.create();                    newValue = accountAccess.withdrawal(sValue);                }            }            catch(CreateException ce)            {                throw new SystemException(ce);            }            catch(EJBException ee)            {               throw new SystemException(ee);            }            catch(RemoteException re)            {               throw new SystemException(re);            }            return newValue;      }      /**      * @Description:    Transfer the specified money from fromAccount to toAccount      * @return:         Fresh ValueList that contains a full list of accounts the user has      */     public static ValueList transferMoney(AccountValue fromAccount, AccountValue toAccount, double amount)         throws SystemException, BusinessException     {         ValueList results = null;         try         {             if(isLocal)             {                 AccountAccessLocal accountAccessLocal = localHome.create();                 results = accountAccessLocal.transferMoney(fromAccount, toAccount, amount);             }             else             {                 AccountAccess accountAccess = home.create();                 results = accountAccess.transferMoney(fromAccount, toAccount, amount);             }         }         catch(CreateException ce)         {             throw new SystemException(ce);         }         catch(EJBException ee)         {            throw new SystemException(ee);         }         catch(RemoteException re)         {            throw new SystemException(re);         }         return results;     }}

⌨️ 快捷键说明

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