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

📄 usermanagementsessionfacadebean.java

📁 Oracle的J2EE Sample
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
   */
  public String setContactInfo(Integer accountNumber, ContactInfo contactInfo)
       throws RemoteException {

    // Initialize Status Message
    String retMessage = "NOSUCCESS";
    try {

      // Find the User Account Local Entity Bean by passing the account Number
      // Primary Key
      UserAccountLocal userAccountLocal = userAccountHomeLocal.findByPrimaryKey(accountNumber);

      // Set the Contact Information
      userAccountLocal.setFirstName(contactInfo.getFirstName());
      userAccountLocal.setLastName(contactInfo.getLastName());
      userAccountLocal.setOrganization(contactInfo.getOrganization());
      userAccountLocal.setAddress(contactInfo.getAddress());
      userAccountLocal.setCity(contactInfo.getCity());
      userAccountLocal.setState(contactInfo.getState());
      userAccountLocal.setCountry(contactInfo.getCountry());
      userAccountLocal.setPhone(contactInfo.getPhone());
      userAccountLocal.setEmail(contactInfo.getEmail());
      userAccountLocal.setMobileEmail(contactInfo.getMobileEmail());

      retMessage = "SUCCESS";
    } catch (FinderException ex) {  // Trap Finder Errors
      System.out.println("Finder Exception " + ex.toString());
      throw new RemoteException("Finder Exception While Setting Contact Info : " +
           ex.toString());
    }

    return retMessage;  // Return Status Message
  }

  /**
   * Method to get Account Information for a particular User. Note that the
   * parameter returned by this method is AccountInfo Value Object.
   *
   * @param accountNumber Account Number of the User Account.
   * @return  The Account Information Value Object for the given user.
   *          For more information @see AccountInfo.java
   * @exception RemoteException If error occurs during getting Account Info
   * @since 1.0
   */
  public AccountInfo getAccountInfo(Integer accountNumber) throws RemoteException {

    AccountInfo accountInfo = null;
    try {

      // Find the User Account Local Entity Bean by passing the account Number
      // Primary Key
      UserAccountLocal userAccountLocal = userAccountHomeLocal.findByPrimaryKey(accountNumber);

      // Construct the Value Object which will be returned back.
      accountInfo = new AccountInfo(userAccountLocal.getPassword(),
                                    userAccountLocal.getUserType(),
                                    userAccountLocal.getAlertMode(),
                                    userAccountLocal.getAccountBalance(),
                                    userAccountLocal.getLinesPerPage());
    } catch (FinderException ex) {  // Trap Finder Errors
      System.err.println("Finder Exception " + ex.toString());
      throw new RemoteException("Finder Exception While Getting Account Info : " +
           ex.toString());
    }

    return accountInfo;
  }

  /**
   * Method to set the New Value of Account Information for a particular User.
   * Note that the one of the parameter passed to this method is AccountInfo
   * Value Object.
   *
   * @param accountNumber Account Number of the User Account.
   * @param accountInfo   The Account Information Value Object for the given user.
   *                      For more information @see AccountInfo.java
   * @return Status of this operation
   * @exception RemoteException If error occurs during setting Contact Info
   * @since 1.0

   */
  public String setAccountInfo(Integer accountNumber, AccountInfo accountInfo)
    throws RemoteException {

    // Initialize the Status Message
    String retMessage = "NOSUCCESS";
    try {

      // Find the User Account Local Entity Bean by passing the
      // Account Number Primary Key
      UserAccountLocal userAccountLocal = 
          userAccountHomeLocal.findByPrimaryKey(accountNumber);

      // Update the Account Information
      userAccountLocal.setAlertMode(accountInfo.getAlertMode());
      userAccountLocal.setLinesPerPage(accountInfo.getLinesPerPage());

      retMessage = "SUCCESS";
    } catch (FinderException ex) {  // Trap Errors While Finding EJB Object
      System.err.println("Finder Exception " + ex.toString());
      throw new RemoteException("Finder Exception While Setting Contact Info : " +
           ex.toString());
    }

    return retMessage;
  }

  /**
   * Method to get Timer Information for admin User. Note that the
   * parameter returned by this method is TimerInfo Value Object.
   *
   * @return  The Timer Information Value Object for the admin user.
   *          For more information @see TimerInfo.java
   * @exception RemoteException If error occurs during getting Timer Info
   * @since 1.0
   */
  public TimerInfo getAdminTimerInfo() throws RemoteException {

    TimerInfo timerInfo = null;

    if (timerHandle != null) {
      // If timer is already set, get the Timer Values 

      // When Timer is set for SLSB, the TimerHandle which is serializable 
      // is set in the bean. This timerhandle can be used at any point of time 
      // to get all the required information about the timer.
      Timer timer = timerHandle.getTimer();

      // The timeout value for the timer is set in the Info field of the timer.
      // Get the timeout value from the info field and convert the timeout in 
      // milliseconds to corresponding hour and minute values to be displayed 
      // to the user. 
      String totalinfo   = (String)timer.getInfo();
      String timeoutinfo = totalinfo.substring(totalinfo.indexOf(" : ") + 3);
      int    timeout     = Integer.parseInt(timeoutinfo);
      int    totalmins   = timeout / (60 * 1000);
      int    hour        = totalmins / 60;
      int    mins        = totalmins - (hour * 60);

      // Create TimerInfo value object with the hour and minute values
      // and return this to the user
      timerInfo = new TimerInfo(new Integer(hour), new Integer(mins));

    } else {
      // If timer is not already set, return the default values

      timerInfo = new TimerInfo(new Integer(0), new Integer(15));

    }

    return timerInfo;

  }

  /**
   * Method to retrieve Preferences for a given User Account. As a single user
   * account can have multiple preferences, this method returns a collection
   * of PreferencesInfo Value Object.
   *
   * @param accountNumber Account Number of the User Account.
   * @return A Collection of PreferencesInfo Value Object. This represents
   *         all the preferences for the User Account.
   * @exception RemoteException If error occurs during getting preferences
   * @since 1.0
   */
  public Collection getPreferences(Integer accountNumber) throws RemoteException {
    Collection allPreferences = new ArrayList();
    try {
      // Find the User Account Local Entity Bean by passing the
      // Account Number Primary Key
      UserAccountLocal userAccountLocal = userAccountHomeLocal.findByPrimaryKey(accountNumber);

      // Get all the preferences and Loop through them
      Iterator prefLocalIter = (userAccountLocal.getPreferences()).iterator();

      while (prefLocalIter.hasNext()) {
        // Get the next handle to PreferencesBean Local EJB Object
        PreferencesLocal preferencesLocal =
          (PreferencesLocal) prefLocalIter.next();

        // Add a new instance of PreferencesInfo Value Object to final list
        allPreferences.add(new PreferencesInfo(preferencesLocal.getSymbol(),
                                               preferencesLocal.getPrefType()));
      }
    } catch (FinderException ex) {  // Trap Errors While Finding EJB Objects
      System.err.println("Get Preferences Method : Finder Exception "
                         + ex.toString());
      throw new RemoteException("Finder Exception While Getting Preferences = " +
           ex.toString());

    }

    return allPreferences;  // Return All Preferences
  }

  /**
   * Method to add a Preference for a given User Account.
   *
   * @param accountNumber Account Number of the User Account.
   * @param preferencesInfo Value Object for Preferences Information
   * @return Status of this Operation
   * @exception RemoteException If error occurs during adding Preferences
   * @since 1.0

   */
  public String addPreferences(Integer accountNumber,
         PreferencesInfo preferencesInfo) throws RemoteException {
    // Flag indicating whether the Symbol Already Exists.
    boolean    symbolPresent  = false;
    boolean    validSymbol = false;
    ArrayList allPrefIter = null;
    String message = null;

    try {
      // Find the User Account Local Entity Bean by passing the account Number
      // Primary Key
      UserAccountLocal userAccountLocal = 
        userAccountHomeLocal.findByPrimaryKey(accountNumber);

      // Check Whether a Valid Symbol
      validSymbol = helper.checkSymbolExists(preferencesInfo.getSymbol());

      // Get All the Preferences for the User Account and loop through them
      allPrefIter = new ArrayList(userAccountLocal.getPreferences());
      int size = allPrefIter.size();
      int i    = 0;
      while (i < size ) {

        // Get the next handle to PreferencesBean Local EJB Object
        PreferencesLocal prefLocal = (PreferencesLocal) allPrefIter.get(i);

        // Check whether the Symbol already exists in the given set of
        // preferences
        if (prefLocal.getSymbol().equals(preferencesInfo.getSymbol())) {
          symbolPresent = true;
          //break;
        }

        allPrefIter.set(i,prefLocal);
        i++;
      }

      // If Symbol was not already present then add this preference to the
      // existing list of Preferences
      if (!symbolPresent && validSymbol) {
        PreferencesLocal preferencesLocal =
          preferencesHomeLocal.create(helper.getNextID("PREFERENCES_SEQ"),
                                      accountNumber,
                                      preferencesInfo.getSymbol(),
                                      preferencesInfo.getPreferenceType());

        allPrefIter.add(preferencesLocal);
      }

      userAccountLocal.setPreferences(allPrefIter);
    } catch (FinderException ex) {  // Trap the errors while finding the EJB
      System.err.println("Finder Exception : Add Preferences Method : "
                         + ex.toString());
      throw new RemoteException("Finder Exception While Adding Preferences = " +
           ex.toString());

    } catch (CreateException ex) {  // Trap Errors While Creating EJB
      System.err.println("Create Exception : Add Preferences Method : "
                         + ex.toString());
      throw new RemoteException("Create Exception While Adding Preferences = " +
           ex.toString());

    } catch (DatabaseException ex) { // Trap SQL Errors
      throw new RemoteException("SQL Exception While Creating New Account : " +
          ex.toString());
    }

    // If Symbol Already Exists then return a proper message
    if (!symbolPresent && validSymbol) {
      message = "SUCCESS";
    } else if (symbolPresent && validSymbol) {
      message = "Symbol Already Present. Can not add. Change it";
    } else if (!validSymbol) {
      message = "Improper Symbol Value. Please Enter proper Symbol Value";
    }
    return message;
  }


  /**
   * Method to Update a Single Preference Record for a given User Account.
   *
   * @param accountNumber Account Number of the User Account.
   * @param prefInfo      Value Object Encapsulating Updated preferences
   *                      Information
   * @return  Status of this Operation
   * @exception RemoteException If error occurs during Changing Preferences Info
   * @since 1.0

   */
  public String changePreferencesInfo(Integer accountNumber,
                PreferencesInfo prefInfo) throws RemoteException {
    String     message        = "SUCCESS";
    try {
      // Find the User Account Local Entity Bean by passing the account Number
      // Primary Key
      UserAccountLocal userAccountLocal = 
        userAccountHomeLocal.findByPrimaryKey(accountNumber);

      // Loop through all the preferences
      ArrayList prefIter = new ArrayList(userAccountLocal.getPreferences());
      int size = prefIter.size();
      int i = 0;
      while ( i < size) {

        // Get the next handle to PreferencesBean Local EJB Object
        PreferencesLocal pl = (PreferencesLocal) prefIter.get(i);

        //  Check whether the passed Symbol is same as Preferences Symbol
        if (pl.getSymbol().equals(prefInfo.getSymbol())) {

          // Update the Preference Type
          pl.setPrefType(prefInfo.getPreferenceType());
        }

        // Add to the final list of preferences
        prefIter.set(i,pl);
        i++;
      }

      // Set the preferences as a final list
      userAccountLocal.setPreferences(prefIter);
    } catch (FinderException ex) {  // Trap errors while finding EJB Object
      System.err.println("Change Preferences Info Method : Finder Exception "
                         + ex.toString());

      message = "NOSUCCESS";
      throw new RemoteException("Finder Exception While Changing Pref Info = " +
           ex.toString());

    }

    return message;
  }


  /**
   * Method to Delete a Preference from a given User Account.
   *
   * @param accountNumber Account Number of the User Account.
   * @return Status of this Operation
   * @exception RemoteException If error occurs during deleting Preferences Info

   * @since 1.0
   */
  public String deletePreference(Integer accountNumber, String symbol)
    throws RemoteException {
    String     message        = "SUCCESS";
    Collection allPreferences = new ArrayList();

⌨️ 快捷键说明

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