コード例 #1
0
  public boolean saveNewUser(Customer user) {
    final int initialPoint = 0;
    final double initialBalance = 1000;
    user.setBalance(initialBalance);
    user.setPoint(initialPoint);
    Session s = HibernateSessionFactory.getSession();
    try {

      String hql = "from CustomerLevel ul where ul.stand_point = ?";

      Transaction t = s.beginTransaction();

      Query q = s.createQuery(hql);
      q.setInteger(0, 99);

      List<CustomerLevel> uls = q.list();
      CustomerLevel level = uls.get(0);
      user.setLevel(level);
      s.save(user);
      t.commit();
      s.close();
    } catch (Exception e) {
      return false;
    }
    return true;
  }
コード例 #2
0
 public boolean updateUserInfo(Customer user) {
   Session s = HibernateSessionFactory.getSession();
   try {
     Transaction t = s.beginTransaction();
     s.update(user);
     t.commit();
     s.close();
   } catch (Exception e) {
     return false;
   }
   return true;
 }
コード例 #3
0
  public Customer queryUserInfoByUserID(Long userID) {
    Session s = HibernateSessionFactory.getSession();
    // String hql="from Customer u where u.user_id = ?";
    Customer ur = (Customer) s.get(Customer.class, userID);
    // Query q = s.createQuery(hql);
    // q.setLong(0, userID);

    // List<Customer> users = q.list();

    s.close();
    return ur;
  }
コード例 #4
0
  public boolean checkUserexist(String userName) {
    Session s = HibernateSessionFactory.getSession();
    String hql = "from Customer u where u.user_name = ?";

    Query q = s.createQuery(hql);
    q.setString(0, userName);

    List<Customer> users = q.list();
    s.close();
    // System.out.println(users.get(0).getUser_name());
    if (users.isEmpty()) return true; // ���Ϊ�գ���û������û����˻����Ϊ����ע��
    else return false;
  }
コード例 #5
0
  public String findPwdByuserIDandPhone(String userName, String phone) {
    try {
      Session s = HibernateSessionFactory.getSession();
      String hql = "from Customer u where u.user_name = ? and u.phone = ?";

      Query q = s.createQuery(hql);
      q.setString(0, userName);
      q.setString(1, phone);

      List<Customer> users = q.list();
      s.close();
      return users.get(0).getPassword();
    } catch (Exception e) {
      return null;
    }
  }
コード例 #6
0
  public Customer checkUserByUserNameAndPassword(String userName, String userPassword) {
    try {
      Session s = HibernateSessionFactory.getSession();
      String hql = "from Customer u where user_name = ? and password = ?";

      Query q = s.createQuery(hql);
      q.setString(0, userName);
      q.setString(1, userPassword);

      List<Customer> users = q.list();

      s.close();
      return users.get(0);
    } catch (Exception e) {
      return null;
      // TODO: handle exception
    }
  }