示例#1
0
  /** Add user details to the DB for a newly signed up user. Updates User and Session tables. */
  public User addUserDetails(
      String profilePic,
      String userName,
      String passWord,
      String email,
      String address,
      String phone,
      String bio,
      String fbId,
      String fbData,
      String fbToken,
      String fbPermissions) {
    User user;
    Session session = null;
    try {
      session = DBUtil.getSessionFactory().openSession();

      Transaction transaction = session.beginTransaction();
      user = new User();
      user.setUserName(userName);
      user.setPassWord(passWord);
      user.setEmail(email);
      user.setPhone(phone);
      user.setAddress(address);
      user.setProfilePic(profilePic);
      user.setBio(bio);
      user.setFacebookId(fbId);
      user.setFacebookData(fbData);
      user.setFacebookToken(fbToken);
      user.setFbPermission(fbPermissions);
      user.setTimestamp(System.currentTimeMillis());
      user.setModified(0);
      session.save(user);

      transaction.commit();
      session.close();

    } catch (HibernateException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
      user = null;
      System.out.println("error");
    } finally {
      if (session != null && session.isOpen()) session.close();
    }

    return user;
  }
示例#2
0
  public boolean editUserDetails(
      int userId,
      String userName,
      String passWord,
      String email,
      String address,
      String phone,
      String bio) {

    Session session = null;
    try {
      session = DBUtil.getSessionFactory().openSession();

      Transaction transaction = session.beginTransaction();
      User user = getUserDetails(userId);

      user.setUserName(userName);
      user.setPassWord(passWord);
      user.setEmail(email);
      user.setPhone(phone);
      user.setAddress(address);
      user.setBio(bio);
      user.setModified(System.currentTimeMillis());

      session.save(user);
      transaction.commit();
      session.close();

    } catch (HibernateException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();

      System.out.println("error");
      return false;
    } finally {
      if (session != null && session.isOpen()) session.close();
    }

    return true;
  }