Beispiel #1
0
  public List findByRoleNameLike(String roleName) {

    Session session = HibernateTrain.getSession();
    Criteria criteria =
        session.createCriteria(StaffRole.class).add(Restrictions.like("roleName", roleName));
    return criteria.list();
  }
Beispiel #2
0
  public Integer getCountUserValidate(String staffPiority) {
    Criteria criteria = getSession().createCriteria(User.class);
    criteria.add(Restrictions.eq("validateStu", 0));
    criteria.add(Restrictions.like("piority", "%" + staffPiority + "%"));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.count("validateStu"));
    criteria.setProjection(projectionList);

    Integer count = (Integer) criteria.uniqueResult();
    closeSession();
    return count;
  }
Beispiel #3
0
 public List<User> getUserValidate(String piority, Integer page) {
   Criteria criteria = getSession().createCriteria(User.class);
   criteria.add(Restrictions.eq("validateStu", 0));
   criteria.add(Restrictions.like("piority", "%" + piority + "%"));
   criteria.addOrder(Order.asc("dateCreate"));
   page = (page - 1) * 10;
   criteria.setFirstResult(page);
   criteria.setMaxResults(10);
   List<User> list = (List<User>) criteria.list();
   closeSession();
   return list;
 }
Beispiel #4
0
  public List<User> getStaffData(
      String fName, String lName, String nickName, String company, String employeeId) {
    Criteria criteria = getSession().createCriteria(User.class);
    if (BeanUtils.isNotEmpty(fName) && BeanUtils.isNotEmpty(lName)) {
      if (BeanUtils.isNotEmpty(fName)) {
        criteria.add(Restrictions.like("thFname", "%" + fName + "%"));
      }
      if (BeanUtils.isNotEmpty(lName)) {
        criteria.add(Restrictions.like("thLname", "%" + lName + "%"));
      }
    } else if (BeanUtils.isEmpty(lName) && BeanUtils.isNotEmpty(fName)) {
      criteria.add(
          Restrictions.or(
              Restrictions.like("thFname", "%" + fName + "%"),
              Restrictions.like("thLname", "%" + fName + "%")));
    }
    if (BeanUtils.isNotEmpty(nickName)) {
      criteria.add(Restrictions.like("nickName", "%" + nickName + "%"));
    }
    if (BeanUtils.isNotEmpty(employeeId)) {
      criteria.add(Restrictions.like("empId", "%" + employeeId + "%"));
    }
    if (BeanUtils.isNotEmpty(company)) {
      criteria.add(Restrictions.eq("compId", Integer.parseInt(company)));
    }

    criteria.add(Restrictions.eq("status", 2));
    List<User> list = (List<User>) criteria.list();
    closeSession();
    return list;
  }
Beispiel #5
0
  public List<User> getStudentData(
      String fName,
      String lName,
      String nickName,
      String staff,
      String position,
      String piority,
      Integer status) {
    Criteria criteria = getSession().createCriteria(User.class);
    if (BeanUtils.isNotEmpty(fName) && BeanUtils.isNotEmpty(lName)) {
      if (BeanUtils.isNotEmpty(fName)) {
        criteria.add(Restrictions.like("thFname", "%" + fName + "%"));
      }
      if (BeanUtils.isNotEmpty(lName)) {
        criteria.add(Restrictions.like("thLname", "%" + lName + "%"));
      }
    } else if (BeanUtils.isEmpty(lName) && BeanUtils.isNotEmpty(fName)) {
      criteria.add(
          Restrictions.or(
              Restrictions.like("thFname", "%" + fName + "%"),
              Restrictions.like("thLname", "%" + fName + "%")));
    }

    if (BeanUtils.isNotEmpty(nickName)) {
      criteria.add(Restrictions.like("nickName", "%" + nickName + "%"));
    }

    if (BeanUtils.isNotEmpty(staff)) {
      criteria.add(Restrictions.eq("staffId", Integer.parseInt(staff))); // Edit by PEEM
    }

    if (BeanUtils.isNotEmpty(position)) {
      criteria.add(Restrictions.eq("posiId", Integer.parseInt(position)));
    }

    criteria.add(Restrictions.eq("status", 3));
    criteria.add(Restrictions.eq("validateStu", 1));
    if (status == 2) {
      criteria.add(Restrictions.like("piority", "%" + piority + "%"));
      criteria.add(Restrictions.ne("piority", piority));
    }
    //        page = (page-1)*10;
    //        criteria.setFirstResult(page);
    //        criteria.setMaxResults(10);
    List<User> list = (List<User>) criteria.list();
    closeSession();
    return list;
  }
Beispiel #6
0
  public static Integer findPiority(String pior, Integer status) {
    Integer sizePioruty = 0;
    StringBuffer piorityBuffer = new StringBuffer();
    Criteria criteria = getSession().createCriteria(User.class);
    criteria.add(Restrictions.like("piority", pior + "%"));
    criteria.add(Restrictions.eq("status", status));
    criteria.add(new LengthExpression("piority", pior.length() + 3));
    criteria.addOrder(Order.asc("piority"));
    List<User> list = (List<User>) criteria.list();
    sizePioruty = list.size();

    if ((list.size() > 0 && status == 3) || (status == 2 && list.size() > 0)) {
      piorityBuffer.append(
          list.get(list.size() - 1)
                  .getPiority()
                  .charAt(list.get(list.size() - 1).getPiority().length() - 3)
              + "");
      piorityBuffer.append(
          list.get(list.size() - 1)
                  .getPiority()
                  .charAt(list.get(list.size() - 1).getPiority().length() - 2)
              + "");
      piorityBuffer.append(
          list.get(list.size() - 1)
                  .getPiority()
                  .charAt(list.get(list.size() - 1).getPiority().length() - 1)
              + "");
      sizePioruty = Integer.parseInt(piorityBuffer.toString()) + 1;
    }
    if (list.size() <= 0 && status == 2) {
      sizePioruty++;
    }
    if (list.size() <= 0 && status == 3) {

      sizePioruty++;
    }
    return sizePioruty;
  }
Beispiel #7
0
 /**
  * Restricts the results by the given properties value
  *
  * @param property The name of the property
  * @param expr The expression to restrict by
  * @return This query instance
  */
 public Query like(String property, String expr) {
   criteria.add(Restrictions.like(property, expr));
   return this;
 }
Beispiel #8
0
  public List findByCountryNameLike(String countryName) {

    Criteria criteria =
        session.createCriteria(Countries.class).add(Restrictions.like("countryName", countryName));
    return criteria.list();
  }