예제 #1
0
 public List<User> getUser(User user) throws HibernateException {
   List<User> users;
   try {
     session = sessionFactory.openSession();
     tx = session.beginTransaction();
     criteria = session.createCriteria(User.class);
     if (user.getUserId() != null) {
       criteria.add(Restrictions.eq("userId", user.getUserId()));
     }
     if (user.getFirstName() != null) {
       criteria.add(Restrictions.eq("firstName", user.getFirstName()));
     }
     if (user.getLastName() != null) {
       criteria.add(Restrictions.eq("lastName", user.getLastName()));
     }
     if (user.getMi() != null) {
       criteria.add(Restrictions.eq("mi", user.getMi()));
     }
     if (user.getActivated() != '\u0000') {
       criteria.add(Restrictions.eq("activated", user.getActivated()));
     }
     if (user.getLoginCredential() != null && user.getLoginCredential().getUserName() != null) {
       criteria.createAlias("loginCredential", "lc");
       criteria.add(Restrictions.eq("lc.userName", user.getLoginCredential().getUserName()));
     }
     users = criteria.list();
     tx.commit();
     return users;
   } catch (HibernateException e) {
     if (tx != null) tx.rollback();
     throw e;
   } finally {
     session.close();
   }
 }
예제 #2
0
 private void copyData(User from, User to) {
   to.setFirstName(from.getFirstName());
   to.setLastName(from.getLastName());
   to.setMi(from.getMi());
   to.setUserId(from.getUserId());
   to.setActivated(from.getActivated());
 }
예제 #3
0
 public void deleteUser(User user) throws HibernateException {
   try {
     session = sessionFactory.openSession();
     tx = session.beginTransaction();
     User dbUser = (User) session.get(User.class, user.getUserId());
     session.delete(dbUser);
     tx.commit();
   } catch (HibernateException e) {
     if (tx != null) tx.rollback();
     throw e;
   } finally {
     session.close();
   }
 }