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

📄 cardholderaccessbean.java

📁 我在加拿大学习的一个比较复杂的在线银行程序.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            chValue.setClientCardID(value.getClientCardID());
            values.addValue(chValue);
       }
       else
       {
            if (!FieldHelper.isEmpty(value.getSIN()))
            {
                cardholder = cardholderHome.findBySIN(value.getSIN());
                chValue = cardholder.getValueObject();
                if (CardholderValue.APPROVED.equals(chValue.getStatus())) //Approved cardholder will have a clientCard number
                   chValue.setClientCardID(clientCardHome.findByCardholderOID(new Long(chValue.getObjectID())).getClientCardID());
                values.addValue(chValue);
            }
            else
            {
                Collection col;
                if (FieldHelper.isEmpty(value.getFirstName()))
                {
                    if (FieldHelper.isEmpty(value.getLastName()))
                        throw new BusinessException(ErrorMessages.NOT_ENOUGH_DATA);
                    col = cardholderHome.findByLastName(value.getLastName());
                }
                else
                {
                    if (FieldHelper.isEmpty(value.getLastName()))
                        col = cardholderHome.findByFirstName(value.getFirstName());
                    else
                        col = cardholderHome.findByFullName(value.getFirstName(),
                                                value.getLastName());
                }
                if (col.isEmpty())
                    throw new BusinessException(ErrorMessages.NO_CARDHOLDER_FOUND);
                Iterator i = col.iterator();
                while (i.hasNext())
                {
                    chValue = ( (CardholderLocal) i.next()).getValueObject();
                    values.addValue(chValue);
                }
            }
        }
    }
    catch (BusinessException be)
    {
        audit.setStatus("FAILED");
        audit.setFailedReason("BusinessException: " + be.getMessage());
        throw be;
    }
    catch (FinderException fe)
    {
        audit.setStatus("FAILED");
        audit.setFailedReason("BusinessException: " + fe.getMessage());
        throw new BusinessException(ErrorMessages.NO_CARDHOLDER_FOUND);
    }
    catch (Exception e) //any other exceptions
    {
        audit.setStatus("FAILED");
        audit.setFailedReason("SystemException: " + e.getMessage());
        throw new SystemException(e);
    }
    finally
    {
        audit.log(value.toString());
    }
    return values;
  }

  /**
   * @Description:    Update cardholder data
   * @param:          CardholderValue
   * @return:         CardholderValue
   */
  public CardholderValue updateCardholder(CardholderValue value) throws SystemException, BusinessException {
    AuditLogger audit = new AuditLogger(this.log,
                                        this.ctx.getCallerPrincipal().getName(),
                                        "UPDATE", "Cardholder");
    //UserProfile profile = null;
    CardholderValue newValue = null; ;
    try {
      CardholderLocal cardholder = cardholderHome.findByPrimaryKey(new Long(value.
          getObjectID()));
      newValue = cardholder.update(value);
    }
    catch (Exception e) { //any other exceptions
      audit.setStatus("FAILED");
      audit.setFailedReason("SystemException: " + e.getMessage());
      throw new SystemException(e);
    }
    finally {
      audit.log(value.toString());
    }
    return newValue;
  }

  /**
   * @Description:    Insert a new record for cardholder table
   * @param:          CardholderValue
   * @return:         CardholderValue
   */
  public CardholderValue createCardholder(CardholderValue value) throws SystemException, BusinessException {
    AuditLogger audit = new AuditLogger(this.log,
                                        this.ctx.getCallerPrincipal().getName(),
                                        "INSERT", "Cardholder");
    CardholderValue newValue = null;
    //UserProfile profile = null;
    try {
      newValue = cardholderHome.create(value).getValueObject();
    }
    catch (Exception e) { //any other exceptions
      audit.setStatus("FAILED");
      audit.setFailedReason("SystemException: " + e.getMessage());
      throw new SystemException(e);
    }
    finally {
      audit.log(value.toString());
    }
    return newValue;
  }

  /**
   * @Description:    Approve the cardholder registered online. Used by Bank Clerk only
   * @param:          CardholderValue
   * @return:         CardholderValue
   */
  public CardholderValue approveCardholder(CardholderValue value) throws SystemException, BusinessException {
    //will implement later
    return value;
  }

  /**
   * @Description:    Delete cardholder data. Used by Admin User only
   * @param:          CardholderValue
   * @return:
   */
  public void deleteCardholder(CardholderValue value) throws SystemException, BusinessException {
    AuditLogger audit = new AuditLogger(this.log,
                                        this.ctx.getCallerPrincipal().getName(),
                                        "DELETE", "Cardholder");
    //UserProfile profile = null;
    try {
      CardholderLocal cardholder = cardholderHome.findByPrimaryKey(new Long(value.
          getObjectID()));
      cardholder.remove();
    }
    catch (FinderException fe) {
      audit.setStatus("FAILED");
      audit.setFailedReason("FinderException: " + fe.getMessage());
      this.ctx.setRollbackOnly(); //
      throw new BusinessException(ErrorMessages.RECORD_DELETED);
    }
    catch (Exception e) { //any other exceptions
      audit.setStatus("FAILED");
      audit.setFailedReason("SystemException: " + e.getMessage());
      throw new SystemException(e);
    }
    finally {
      audit.log(value.toString());
    }
  }

  /**
   * @Description:    View address data for the specified Object ID
   * @return:         AddressValue
   */
  public AddressValue viewAddressByOID(long oid) throws SystemException, BusinessException {
    AuditLogger audit = new AuditLogger(this.log,
                                        this.ctx.getCallerPrincipal().getName(),
                                        "VIEW", "Address");
    //UserProfile profile = null;
    AddressValue aValue = null;
    try {
      AddressLocal address = addressHome.findByPrimaryKey(new Long(oid));
      aValue = address.getValueObject();
    }
    catch (Exception e) { //any exceptions
      audit.setStatus("FAILED");
      audit.setFailedReason("SystemException: " + e.getMessage());
      throw new SystemException(e);
    }
    finally {
      audit.log("Object ID = " + oid);
    }
    return aValue;
  }

  /**
   * @Description:    Update Address data
   * @param:          AddressValue
   * @return:         AddressValue
   */
  public AddressValue updateAddress(AddressValue value) throws SystemException, BusinessException {
    AuditLogger audit = new AuditLogger(this.log,
                                        this.ctx.getCallerPrincipal().getName(),
                                        "UPDATE", "Addess");
    //UserProfile profile = null;
    AddressValue newValue = null; ;
    try {
      AddressLocal address = addressHome.findByPrimaryKey(new Long(value.
          getObjectID()));
      newValue = address.update(value);
    }
    catch (Exception e) { //any other exceptions
      audit.setStatus("FAILED");
      audit.setFailedReason("SystemException: " + e.getMessage());
      throw new SystemException(e);
    }
    finally {
      audit.log(value.toString());
    }
    return newValue;

  }

  /**
   * @Description:    Insert a new record for Address table
   * @param:          AddressValue
   * @return:         AddressValue
   */
  public AddressValue createAddress(AddressValue value) throws SystemException, BusinessException {
    AuditLogger audit = new AuditLogger(this.log,
                                        this.ctx.getCallerPrincipal().getName(),
                                        "INSERT", "Address");
    AddressValue newValue = null;
    //UserProfile profile = null;
    try {
      CardholderLocal cardholder = cardholderHome.findByPrimaryKey(new Long(value.getCardholderOID()));
      newValue = addressHome.create(value).getValueObject();
    }
    catch (Exception e) { //any other exceptions
      audit.setStatus("FAILED");
      audit.setFailedReason("SystemException: " + e.getMessage());
      throw new SystemException(e);
    }
    finally {
      audit.log(value.toString());
    }
    return newValue;

  }

  /**
   * @Description:    Delete Address data. Used by Bank Clerk only
   * @param:          AddressValue
   * @return:
   */
  public void deleteAddress(AddressValue value) throws SystemException, BusinessException {
    AuditLogger audit = new AuditLogger(this.log,
                                        this.ctx.getCallerPrincipal().getName(),
                                        "DELETE", "Address");
    //UserProfile profile = null;
    try {
      AddressLocal address = addressHome.findByPrimaryKey(new Long(value.
          getObjectID()));
      address.remove();
    }
    catch (FinderException fe) {
      audit.setStatus("FAILED");
      audit.setFailedReason("FinderException: " + fe.getMessage());
      this.ctx.setRollbackOnly(); //
      throw new BusinessException(ErrorMessages.RECORD_DELETED);
    }
    catch (Exception e) { //any other exceptions
      audit.setStatus("FAILED");
      audit.setFailedReason("SystemException: " + e.getMessage());
      throw new SystemException(e);
    }
    finally {
      audit.log(value.toString());
    }
  }

  private boolean isCardholderExist(long oid) throws SystemException, BusinessException
  {
      try
      {
          if (cardholderHome.findByPrimaryKey(new Long(oid)) != null);
             return true;
      }
      catch (FinderException fe)
      {
          throw new BusinessException(ErrorMessages.NO_CARDHOLDER_FOUND);
      }
  }

  // The following public methods are EJB container callback methods.

  /***
   * Stateless session bean is pooled and this method will be called
   * only when a new instance is created and is added to the pool.
   * So it can be empty or used to initialize some common variables
   */
  public void ejbCreate() {
    try {
      clientCardHome = (ClientCardLocalHome) ServiceLocator.getInstance().
          getLocalHome(Constants.CLIENT_CARD_LOCALHOME);
      cardholderHome = (CardholderLocalHome) ServiceLocator.getInstance().
          getLocalHome(Constants.CARDHOLDER_LOCALHOME);
      addressHome = (AddressLocalHome) ServiceLocator.getInstance().
          getLocalHome(Constants.ADDRESS_LOCALHOME);
    }
    catch (ServiceLocatorException sle) {
      log.fatal(sle.getMessage(), sle);
    }
    log.info("ejbCreate called");
  }

  public void ejbActivate() {} //This method will never be called for stateless bean

  public void ejbRemove() { //Will be called only when the instance is removed from the pool
    log.info("ejbRemove called");
  }

  public void ejbPassivate() {} //This method will never be called for stateless bean

  /**
   *  This method will be called each time before a business method is called. So in business method,
   *  We can use SessionContext object to get information like Caller Principal.
   *
   *  To use it in business method, we must have an instance variable to hold the reference
   *
   *  Please note, ctx.getCallerPrincipal() is not allowed in this method. It must be called
   *  through business methods
   */
  public void setSessionContext(SessionContext ctx) {
    log.debug("setSessionContext called");
    this.ctx = ctx;
  }
}

⌨️ 快捷键说明

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