示例#1
0
文件: UserDAO.java 项目: sks40gb/zunk
 public List<User> findUser(String searchValue, String status) throws HibernateException {
   String[] properties = {ID, COMPANY_NAME, CITY, STATE, ZIP, FIRST_NAME, LAST_NAME, EMAIL};
   StringBuilder queryBuilder = new StringBuilder(" from User where");
   if (!status.trim().equals(CommonConstant.ALL)) {
     queryBuilder.append(" " + STATUS + " = '" + status + "'");
   } else {
     queryBuilder.append(
         " ("
             + STATUS
             + " = '"
             + Status.PENDING.toString()
             + "' or "
             + STATUS
             + " = '"
             + Status.APPROVED.toString()
             + "')");
   }
   queryBuilder.append(" and (");
   boolean isFirst = true;
   for (String property : properties) {
     if (isFirst) {
       queryBuilder.append(property + " like '%" + searchValue + "%'");
       isFirst = false;
     } else {
       queryBuilder.append(" or " + property + " like '%" + searchValue + "%'");
     }
   }
   queryBuilder.append(")");
   Query queryObject = getSession().createQuery(queryBuilder.toString());
   return queryObject.list();
 }
示例#2
0
文件: UserDAO.java 项目: sks40gb/zunk
 public List<User> findByStatusAndRole(Status status, Roles role) throws Exception {
   List<User> searchList = new ArrayList<User>();
   StringBuilder queryBuilder = new StringBuilder(" from User where");
   if (!status.toString().equals(Status.ALL.toString())) {
     queryBuilder.append(" " + STATUS + " = '" + status + "'");
   } else {
     queryBuilder.append(
         " ("
             + STATUS
             + " = '"
             + Status.PENDING.toString()
             + "' or "
             + STATUS
             + " = '"
             + Status.APPROVED.toString()
             + "')");
   }
   Query queryObject = getSession().createQuery(queryBuilder.toString());
   List<User> list = queryObject.list();
   for (User user : list) {
     if (user.hasRole(role)) {
       searchList.add(user);
     }
   }
   return searchList;
 }