Example #1
0
  /**
   * Gets a user's information and creates the User instance base on its ID<br>
   * If there this user has been logged in, and still stored in the user pool, just return the exact
   * same user
   *
   * @param UID The user's ID
   * @param load Whether being allowed to load from database
   * @return The created instance, or <tt>Null</tt> if
   *     <ul>
   *       <li>load is <tt>false</tt> and this user isn't cached
   *       <li>the user isn't found
   *     </ul>
   *
   * @throws SQLException If there are some thing wrong with the database
   */
  public static User getUser(int UID, boolean load) throws SQLException {
    synchronized (userPool) {
      if (userPool.containsKey(UID)) return userPool.get(UID);
      else if (!load) return null;

      ResultSet resultSet;
      synchronized (userByID) {
        userByID.setInt(1, UID);
        resultSet = userByID.executeQuery();
      }
      if (!resultSet.first()) return null;

      User newUser =
          new User(
              UID,
              resultSet.getString(2),
              AccessLevel.valueOf(resultSet.getInt(4)),
              resultSet.getInt(5));
      userPool.put(UID, newUser);
      return newUser;
    }
  }
Example #2
0
 /**
  * Get the AccessLevel object based on its value
  *
  * @param level The value of this level
  * @return The AccessLevel object, or <em>null</em> if their are no level matches this value
  */
 public static AccessLevel valueOf(int level) {
   for (AccessLevel al : AccessLevel.values()) if (al.value == level) return al;
   return null;
 }