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

📄 accountaccessbean.java

📁 我在加拿大学习的一个比较复杂的在线银行程序.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    /**    * @Description:    Deposit the specified money to the specified Account    * @return:         The updated AccountValue bean    */    public AccountValue deposit(StatementValue sValue) throws           SystemException, BusinessException   {        AccountValue newValue = null;        AuditLogger audit = new AuditLogger(this.log,                                   this.ctx.getCallerPrincipal().getName(),                                   "DEPOSIT", "Money");        UserProfile profile = null;        String accountType = sValue.getAccountType();        try        {            profile = UserContainer.getUserProfile(ctx); //get user profile            if (profile.isUserRestrictedOnFunction(Functions.ACCOUNT_DEPOSIT)) //check access               throw new BusinessException(ErrorMessages.NO_DEPOSIT_AUTHORIZED);            if (Constants.CHEQUING_ACCOUNT.equals(accountType))            {                ChequingAccountLocal account = cheqHome.findByAccountNo(sValue.getAccountNo());//lock Chequing Account for update                account.deposit(sValue.getDeposit()); //deposit the payment to Chequing account                newValue = account.getValueObject();                sValue.setBalance(newValue.getBalance()); //set new balance to the StatementValue                stmtHome.create(sValue); //Insert a new record to statement table            }            else if (Constants.SAVING_ACCOUNT.equals(accountType))            {                SavingAccountLocal account = savingHome.findByAccountNo(sValue.getAccountNo());                account.deposit(sValue.getDeposit());                newValue = account.getValueObject();                sValue.setBalance(newValue.getBalance());                stmtHome.create(sValue);            }            else if (Constants.VISA_ACCOUNT.equals(accountType))            {               JMSDelegate.sendPayment(sValue); //send the payment to JMS server               newValue = WebServiceDelegate.viewVisaByAccountNo(sValue.getAccountNo()); //no guranttee the newValue is updated because JMS is asynchronous serivce            }        }        catch (FinderException fe)        {            audit.setStatus("FAILED");            audit.setFailedReason("BusinessException: " + fe.getMessage());            throw new BusinessException(ErrorMessages.NO_ACCOUNT_FOUND);        }        catch (BusinessException be)        {           audit.setStatus("FAILED");           audit.setFailedReason("BusinessException: " + be.getMessage());           throw be;        }        catch (Exception e) //any exceptions        {            audit.setStatus("FAILED");            audit.setFailedReason("SystemException: " + e.getMessage());            throw new SystemException(e);        }        finally        {            audit.log(sValue.toString());        }        return newValue;   }   /**     * @Description:    Withdrawal the specified money from the specified Account     * @return:         The updated AccountValue bean     */     public AccountValue withdrawal(StatementValue sValue) throws            SystemException, BusinessException    {         AccountValue newValue = null;         AuditLogger audit = new AuditLogger(this.log,                                    this.ctx.getCallerPrincipal().getName(),                                    "WITHDRAWAL", "Money");         UserProfile profile = null;         String accountType = sValue.getAccountType();         try         {             profile = UserContainer.getUserProfile(ctx); //get user profile             if (profile.isUserRestrictedOnFunction(Functions.ACCOUNT_WITHDRAWAL)) //check access                throw new BusinessException(ErrorMessages.NO_WITHDRAWAL_AUTHORIZED);             if (Constants.CHEQUING_ACCOUNT.equals(accountType))             {                 ChequingAccountLocal account = cheqHome.findByAccountNo(sValue.getAccountNo());//lock Chequing Account for update                 account.withdrawal(sValue.getWithdrawal()); //withdrawal the money from the Chequing account                 newValue = account.getValueObject();                 sValue.setBalance(newValue.getBalance()); //set new balance to the StatementValue                 stmtHome.create(sValue); //Insert a new record to statement table             }             else if (Constants.SAVING_ACCOUNT.equals(accountType))             {                 SavingAccountLocal account = savingHome.findByAccountNo(sValue.getAccountNo());                 account.withdrawal(sValue.getWithdrawal());                 newValue = account.getValueObject();                 sValue.setBalance(newValue.getBalance());                 stmtHome.create(sValue);             }             else if (Constants.VISA_ACCOUNT.equals(accountType))             {                JMSDelegate.sendPayment(sValue); //send the payment to JMS server                newValue = WebServiceDelegate.viewVisaByAccountNo(sValue.getAccountNo()); //no guranttee the newValue is updated because JMS is asynchronous serivce             }         }         catch (FinderException fe)         {             audit.setStatus("FAILED");             audit.setFailedReason("BusinessException: " + fe.getMessage());             throw new BusinessException(ErrorMessages.NO_ACCOUNT_FOUND);         }         catch (BusinessException be)         {            audit.setStatus("FAILED");            audit.setFailedReason("BusinessException: " + be.getMessage());            throw be;         }         catch (Exception e) //any exceptions         {             audit.setStatus("FAILED");             audit.setFailedReason("SystemException: " + e.getMessage());             throw new SystemException(e);         }         finally         {             audit.log(sValue.toString());         }         return newValue;    }   /**    * @Description:    Insert a new record for account table    * @param:          AccountValue    * @return:         AccountValue    */    public AccountValue createAccount(AccountValue value) throws           EJBException, SystemException, BusinessException    {        String accountType = value.getAccountType();        AuditLogger audit = new AuditLogger(this.log,                                   this.ctx.getCallerPrincipal().getName(),                                   "CREATE", value.getValueType());        UserProfile profile = null;        AccountValue aValue = null;        try        {            profile = UserContainer.getUserProfile(ctx); //get user profile            if (profile.isUserRestrictedOnFunction(Functions.ACCOUNT_SAVE)) //check access               throw new BusinessException(ErrorMessages.NO_SAVE_AUTHORIZED);            if (Constants.CHEQUING_ACCOUNT.equals(accountType))            {                ChequingAccountLocal account = cheqHome.create((ChequingAccountValue)value);                aValue = account.getValueObject();            }            else if (Constants.SAVING_ACCOUNT.equals(accountType))            {                SavingAccountLocal account = savingHome.create((SavingAccountValue)value);                aValue = account.getValueObject();            }        }        catch (BusinessException be)        {           audit.setStatus("FAILED");           audit.setFailedReason("BusinessException: " + be.getMessage());           throw be;        }        catch (Exception e) //any other exceptions        {            audit.setStatus("FAILED");            audit.setFailedReason("SystemException: " + e.getMessage());            throw new SystemException(e);        }        finally        {            audit.log(value.toString());        }        return aValue;    }   /**    * @Description:    Search a full list of the accounts the user has    * @return:         ValueList that contains a full list of accounts the user has    */    public ValueList searchAccount(String cardID) throws           SystemException, BusinessException    {        ValueList vList = new ValueList();        AccountValue aValue;        AuditLogger audit = new AuditLogger(this.log,                               this.ctx.getCallerPrincipal().getName(),                               "SEARCH", " Account");        UserProfile profile = null;        try        {            profile = UserContainer.getUserProfile(ctx); //get user profile            if (profile.isUserRestrictedOnFunction(Functions.ACCOUNT_VIEW)) //check access               throw new BusinessException(ErrorMessages.NO_SAVE_AUTHORIZED);            //search Chequing            try            {                ChequingAccountLocal account = cheqHome.findByClientCardID(cardID);                aValue = account.getValueObject();                vList.addValue(aValue);            }            catch (FinderException fe)            {                //do nothing;            }            //search Saving            try            {                SavingAccountLocal account = savingHome.findByClientCardID(cardID);                aValue = account.getValueObject();                vList.addValue(aValue);            }            catch (FinderException fe)            {                //do nothing;            }            //search Visa through WebServices            aValue = WebServiceDelegate.viewVisaByCardID(cardID);            if (aValue != null)               vList.addValue(aValue);        }        catch (BusinessException be)        {          audit.setStatus("FAILED");          audit.setFailedReason("BusinessException: " + be.getMessage());          throw be;        }        catch (Exception e) //any other exceptions        {            audit.setStatus("FAILED");            audit.setFailedReason("SystemException: " + e.getMessage());            throw new SystemException(e);        }        finally        {            audit.log(cardID);        }        return vList;    }    /**    * @Description:    Transfer the specified money from fromAccount to toAccount    * @return:         Fresh ValueList that contains a full list of accounts the user has    */    public ValueList transferMoney(AccountValue fromAccount, AccountValue toAccount, double amount)        throws SystemException, BusinessException    {        ValueList vList = null;        AuditLogger audit = new AuditLogger(this.log,                       this.ctx.getCallerPrincipal().getName(),                       "TRANSFER", " Money");        UserProfile profile = null;        try        {            profile = UserContainer.getUserProfile(ctx); //get user profile            if (profile.isUserRestrictedOnFunction(Functions.ACCOUNT_TRANSFER)) //check access               throw new BusinessException(ErrorMessages.NO_TRANSFER_AUTHORIZED);            if (fromAccount.equals(toAccount))               throw new BusinessException(ErrorMessages.CANNOT_TRANSFER_TO_ITSELF);            AccountValue aValue;            StatementValue sValue;            //withdrawal money from fromAccount            if (fromAccount instanceof ChequingAccountValue)            {                ChequingAccountLocal account = cheqHome.findByAccountNo(fromAccount.getAccountNo());//lock Chequing Account for update                account.withdrawal(amount); //withdrawal the money from the Chequing account                sValue = buildStatement(fromAccount);                sValue.setDescription("Transfer money from");                sValue.setWithdrawal(amount);                sValue.setBalance(account.getBalance()); //set new balance to the StatementValue                stmtHome.create(sValue); //Insert a new record to statement table            }

⌨️ 快捷键说明

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