Exemple #1
0
  @SuppressWarnings("unchecked")
  public List<T> find(Class<T> clazz, String title, int firstRow, int maxRow, String server) {
    /** &&短路符号 title.length()不会抛出异常(可省掉的) */
    if (title != null && title.length() > 0) {
      /** 防止title=" "出现 */
      title = title.replace(" ", "");
      if (title.length() == 0) return null;

    } else {
      return null;
    }
    Criteria criteria = this.getSession().createCriteria(clazz);
    criteria.add(
        or(
            Restrictions.like("title", "%" + title + "%"),
            Restrictions.like("note", "%" + title + "%")));
    criteria.addOrder(Order.asc("title"));
    if (null != server) {
      criteria.add(eq("server", server));
    }

    /** 分页? 需要做一些优化 */
    criteria.setFirstResult(firstRow);
    criteria.setMaxResults(maxRow);
    List<T> list = criteria.list();
    return ((list == null) || list.isEmpty()) ? null : list;
  }
Exemple #2
0
  @SuppressWarnings("unchecked")
  public static java.util.List<Object> getListData(
      Class<?> classBean, String strKey1, Object value1, String strKey2, Object value2) {
    java.util.List<Object> result = new java.util.ArrayList<Object>();
    Session session = null;
    try {
      session = sessionFactory.openSession();
      Transaction tx = session.beginTransaction();

      Criteria criteria = session.createCriteria(classBean);
      if (strKey1 != null) {
        criteria.add(Restrictions.like(strKey1, value1));
      }
      if (strKey2 != null) {
        criteria.add(Restrictions.like(strKey2, value2));
      }

      result = criteria.list();

      tx.commit();

    } finally {
      if (session != null) {
        session.close();
      }
    }
    return result;
  }
  public static Vector<Person> searchPerson(String keyword) {
    Session session = sf.openSession();
    Criteria criteria = session.createCriteria(Person.class);
    keyword = keyword.trim();

    Disjunction or = Restrictions.disjunction();

    or.add(Restrictions.like("name", "%" + keyword + "%"));
    or.add(Restrictions.like("sex", "%" + keyword + "%"));
    or.add(Restrictions.like("born", "%" + keyword + "%"));
    or.add(Restrictions.like("year", "%" + keyword + "%"));
    or.add(Restrictions.like("day", "%" + keyword + "%"));
    criteria.add(or);
    Vector vt = new Vector();
    List result = new Vector<Person>();
    result = criteria.list();
    for (Object o : result) {
      Person person = (Person) o;
      Vector temp = new Vector();
      temp.add(person.getName());
      temp.add(person.getSex());
      temp.add(person.getBorn());
      temp.add(person.getYear());
      temp.add(person.getDay());
      temp.add(person.getId());
      temp.add(person.getIsdirector());
      temp.add(person.getIsstar());
      vt.add(temp);
    }
    return vt;
  }
  private DetachedCriteria createActivityCriteria(Activity activity, String matchType) {
    DetachedCriteria criteria = DetachedCriteria.forClass(Activity.class);
    if (activity.getActivityName() != null) {
      if (matchType.equalsIgnoreCase("exact")) {
        criteria.add(
            Restrictions.eq("activityName", "" + activity.getActivityName() + "").ignoreCase());
      } else {
        criteria.add(
            Restrictions.like("activityName", "%" + activity.getActivityName() + "%").ignoreCase());
      }
    }
    if (activity.getActivityDescription() != null) {
      criteria.add(
          Restrictions.like("activityDescription", "%" + activity.getActivityDescription() + "%")
              .ignoreCase());
    }
    if (activity.getIsActive() != null) {
      /*criteria.add(Restrictions.like("isActive",
      "%" + activity.getIsActive() + "%").ignoreCase());*/
      criteria.add(Restrictions.eq("isActive", "" + activity.getIsActive() + ""));
    }
    if (activity.getOrganization() != null) {
      criteria.add(Restrictions.eq("organization", activity.getOrganization()));
    }

    return criteria;
  }
Exemple #5
0
  public List getSearchResult(
      String category, String prodname, String pricestart, String priceend) {
    List<Prod> lst = null;

    if ("".equals(pricestart) && "".equals(priceend)) {
      List pMM = getProdMaxMinPraces();
      pricestart = ((BigDecimal) pMM.get(1)).toString();
      priceend = ((BigDecimal) pMM.get(0)).toString();
    }
    if ("".equals(pricestart)) pricestart = getProdMinPrice().toString();
    if ("".equals(priceend)) priceend = getProdMaxPrice().toString();

    try {
      // -------------------------------------------------------------------------------
      lst =
          session
              .createCriteria(Prod.class)
              .add(
                  Restrictions.between(
                      "price", new BigDecimal(pricestart), new BigDecimal(priceend)))
              .add(Restrictions.like("name", "%" + prodname + "%"))
              .createCriteria("cat")
              .add(Restrictions.like("name", "%" + category + "%"))
              .list();
      // -------------------------------------------------------------------------------
    } catch (HibernateException he) {
      he.printStackTrace();
    }
    return lst;
  }
Exemple #6
0
  public HashMap getAllUsers(
      Filter filterUserId,
      int userTypeId,
      String parentTypeId,
      String sortBy,
      boolean ascending,
      int startIndex,
      int displayCount) {
    Criteria objCriteria = null;
    Session objSession = null;
    Integer totRecordCount = null;
    List objList = null;
    HashMap hmResult = new HashMap();
    try {
      logger.info("GETING ALL USERS");
      objSession = HibernateUtil.getSession();
      objCriteria = objSession.createCriteria(UsersVO.class);

      if (filterUserId != null) {
        objCriteria.add(
            Restrictions.like(
                filterUserId.getFieldName(),
                filterUserId.getFieldValue(),
                (MatchMode) HibernateUtil.htMatchCase.get(filterUserId.getSpecialFunction())));
      }

      if (userTypeId != 0) {
        objCriteria.add(Restrictions.eq("userTypes.userTypeId", new Integer(userTypeId)));
      }

      if (parentTypeId.length() > 0) {
        objCriteria.add(Restrictions.like("parentUser.userId", parentTypeId, MatchMode.EXACT));
      }

      totRecordCount = new Integer(objCriteria.list().size());
      if (ascending) {
        objCriteria.addOrder(Order.asc(sortBy));
      } else {
        objCriteria.addOrder(Order.desc(sortBy));
      }
      objCriteria.setFirstResult(startIndex);
      objCriteria.setMaxResults(displayCount);
      objList = objCriteria.list();
      hmResult.put("TotalRecordCount", totRecordCount);
      hmResult.put("Records", objList);
      logger.info("GOT ALL USERS");
    } catch (HibernateException e) {
      logger.error("HIBERNATE EXCEPTION DURING GET ALL USERS", e);
      e.printStackTrace();
    } finally {
      if (objSession != null) {
        objSession.close();
      }
    }
    return hmResult;
  }
  private void deleteAlarms(final String foreignSource, final String foreignId) {
    final OnmsCriteria alarmCriteria =
        new OnmsCriteria(OnmsAlarm.class)
            .add(Restrictions.like("eventParms", "%componentForeignSource=" + foreignSource + "%"))
            .add(Restrictions.like("eventParms", "%componentForeignId=" + foreignId + "%"));

    for (final OnmsAlarm alarm : m_alarmDao.findMatching(alarmCriteria)) {
      m_alarmDao.delete(alarm);
    }
  }
  private void deleteEvents(final String foreignSource, final String foreignId) {
    final OnmsCriteria eventCriteria =
        new OnmsCriteria(OnmsEvent.class)
            .add(Restrictions.like("eventParms", "%componentForeignSource=" + foreignSource + "%"))
            .add(Restrictions.like("eventParms", "%componentForeignId=" + foreignId + "%"));

    for (final OnmsEvent event : m_eventDao.findMatching(eventCriteria)) {
      m_eventDao.delete(event);
    }
  }
 public Employer queryEmployerByNameAndPassword(String name, String password) throws Exception {
   try {
     Criteria cr = getSession().createCriteria(Employer.class);
     cr.add(Restrictions.like("emailId", name));
     cr.add(Restrictions.like("password", password));
     Employer employer = (Employer) cr.uniqueResult();
     return employer;
   } catch (HibernateException e) {
     close();
     throw new Exception("Could not get Employer " + name, e);
   }
 }
  private Criteria buildCondition(Retirement r, String ks, String js, String eq, String type) {
    Criteria c = getSession().createCriteria(Retirement.class);
    if (r != null) {
      if (r.getSfsc() != null && r.getSfsc().length() > 0)
        c.add(Restrictions.eq("sfsc", r.getSfsc()));
      else c.add(Restrictions.eq("sfsc", Constants.HASNO));
      if (r.getSfzh() != null && r.getSfzh().length() > 0)
        c.add(Restrictions.eq("sfzh", r.getSfzh()));
      if (r.getXm() != null && r.getXm().length() > 0)
        c.add(Restrictions.like("xm", r.getXm(), MatchMode.ANYWHERE));
      if (r.getGzzh() != null && r.getGzzh().length() > 0)
        c.add(Restrictions.eq("gzzh", r.getGzzh()));
      if (r.getXb() != null && r.getXb().length() > 0) c.add(Restrictions.eq("xb", r.getXb()));
      if (r.getDwb() != null && r.getDwb().getId() != null)
        c.add(Restrictions.eq("dwb", r.getDwb()));
      if (r.getLxb() != null && r.getLxb().getId() != null)
        c.add(Restrictions.eq("lxb", r.getLxb()));
      if (r.getZjb() != null && r.getZjb().getId() != null)
        c.add(Restrictions.eq("zjb", r.getZjb()));
      if (r.getZwb() != null && r.getZwb().getId() != null)
        c.add(Restrictions.eq("zwb", r.getZwb()));
      if (r.getMzb() != null && r.getMzb().getId() != null)
        c.add(Restrictions.eq("mzb", r.getMzb()));
      if (r.getZzmm() != null && r.getZzmm().getId() != null)
        c.add(Restrictions.eq("zzmm", r.getZzmm()));
      if (r.getJg() != null && r.getJg().length() > 0) c.add(Restrictions.eq("jg", r.getJg()));

      if (r.getCsrq() != null && r.getCsrq().length() > 0)
        c.add(Restrictions.eq("csrq", r.getCsrq())); // 类型为空表是查出生日期,不为空是查是否为党员

      if (StringUtils.isNotEmpty(ks) || StringUtils.isNotBlank(js)) {
        if (StringUtils.isNotEmpty(ks) && StringUtils.isNotBlank(js)) {
          c.add(Restrictions.and(Restrictions.gt("csrq", js), Restrictions.lt("csrq", ks)));
        }
        if (StringUtils.isNotEmpty(ks)) {
          c.add(Restrictions.lt("csrq", ks));
        }
        if (StringUtils.isNotEmpty(js)) {
          c.add(Restrictions.gt("csrq", js));
        }
      }
      if (StringUtils.isNotBlank(eq)) {
        c.add(Restrictions.like("csrq", "%" + eq + "%"));
      }

      if (r.getParty() != null && r.getParty().getId() != null)
        c.add(Restrictions.eq("party", r.getParty()));
    }
    c.addOrder(Order.asc("sfzh")).addOrder(Order.desc("csrq"));
    return c;
  }
  /*
   * (non-Javadoc)
   *
   * @see com.changpeng.common.action.AbstractAction#go()
   */
  @Override
  protected String go() throws Exception {

    DetachedCriteria detachedCriteria =
        DetachedCriteria.forClass(SysUser.class).add(Restrictions.eq("roleid", 1));

    // 这里要判断出登录帐号所属的group
    // 如果是admin,看所有的,如果不是admin,则根据登录人员的所属角色,判断角色对用户和对部门的可见性

    if (loginname != null && !"".equals(loginname))
      detachedCriteria.add(Restrictions.like("loginname", loginname, MatchMode.ANYWHERE));
    if (username != null && !"".equals(username))
      detachedCriteria.add(Restrictions.like("username", username, MatchMode.ANYWHERE));
    if (systemno != null && !"".equals(systemno))
      detachedCriteria.add(Restrictions.like("systemno", systemno, MatchMode.ANYWHERE));
    // 必须是没有删除的啊
    detachedCriteria.add(Restrictions.eq("delflag", false));
    // 取消掉自己的显示
    detachedCriteria.add(Restrictions.ne("userid", getLoginUser().getUserid()));
    SysUser sysUser = getLoginUser();
    SysGroup group = sysUser.getSysGroup();
    // 如果没有所属的group,则能查看所有的数据信息,否则只能看本部门和下级部门的数据
    if (group != null && group.getGroupid() != 1) { // 不是深圳律协的人上来的话
      int groupid = group.getGroupid();
      GroupTree tree = new GroupTree();
      List groupidlist = tree.getChildGroupIds(groupid);
      detachedCriteria
          .createAlias("sysGroup", "sysGroup")
          .add(Restrictions.in("sysGroup.groupid", groupidlist));
      if (groupname != null && !"".equals(groupname)) {
        detachedCriteria.add(
            Restrictions.like("sysGroup.groupname", groupname, MatchMode.ANYWHERE));
      }

      // detachedCriteria.add(Restrictions.in("groupid", groupidlist));
    } else if (groupname != null && !"".equals(groupname)) {
      detachedCriteria
          .createAlias("sysGroup", "sysGroup")
          .add(Restrictions.like("sysGroup.groupname", groupname, MatchMode.ANYWHERE));
    }
    detachedCriteria.setFetchMode("sysGroup", FetchMode.JOIN);

    // 按userid逆序排序
    detachedCriteria.addOrder(Order.desc("userid"));
    BasicService service = (BasicService) getBean("basicService");
    this.page = service.findPageByCriteria(detachedCriteria, pageSize, pageNo);
    // TODO Auto-generated method stub
    return SUCCESS;
  }
 public List findList(Privilege example) {
   DetachedCriteria dc = super.getDetachedCriteria();
   Criteria criteria = getSession().createCriteria(Privilege.class);
   if (StringUtils.isNotEmpty(example.getPrivilName())) {
     dc.add(Restrictions.like("privilName", example.getPrivilName(), MatchMode.ANYWHERE));
   }
   if (StringUtils.isNotEmpty(example.getPattern())) {
     dc.add(Restrictions.like("pattern", example.getPattern(), MatchMode.ANYWHERE));
   }
   if (StringUtils.isNotEmpty(example.getType())) {
     dc.add(Restrictions.eq("type", example.getType()));
   }
   dc.addOrder(Order.asc("privilName"));
   return super.findList(dc);
 }
  /**
   * The 'findConfigurations' function will return a list of configurations based on a search term
   * passed in. The function will search configurations on the following fields configName, orgName
   * and messageTypeName @Table configurations
   *
   * @param searchTerm Will hold the term used search configurations on
   * @return This function will return a list of configuration objects
   */
  @Override
  @SuppressWarnings("unchecked")
  public List<configuration> findConfigurations(String searchTerm) {

    if (searchTerm != "") {
      // get a list of organization id's that match the term passed in
      List<Integer> orgIdList = new ArrayList<Integer>();
      Criteria findOrgs = sessionFactory.getCurrentSession().createCriteria(Organization.class);
      findOrgs.add(Restrictions.like("orgName", "%" + searchTerm + "%"));
      List<Organization> orgs = findOrgs.list();

      for (Organization org : orgs) {
        orgIdList.add(org.getId());
      }

      // get a list of message type id's that match the term passed in
      List<Integer> msgTypeIdList = new ArrayList<Integer>();
      Criteria findMsgTypes = sessionFactory.getCurrentSession().createCriteria(messageType.class);
      findMsgTypes.add(Restrictions.like("name", "%" + searchTerm + "%"));
      List<messageType> msgTypes = findMsgTypes.list();

      for (messageType msgType : msgTypes) {
        msgTypeIdList.add(msgType.getId());
      }

      Criteria criteria = sessionFactory.getCurrentSession().createCriteria(configuration.class);

      if (orgIdList.size() == 0) {
        orgIdList.add(0);
      }
      if (msgTypeIdList.size() == 0) {
        msgTypeIdList.add(0);
      }

      criteria
          .add(
              Restrictions.or(
                  Restrictions.in("orgId", orgIdList),
                  Restrictions.in("messageTypeId", msgTypeIdList)))
          .addOrder(Order.desc("dateCreated"));

      return criteria.list();
    } else {
      Criteria criteria = sessionFactory.getCurrentSession().createCriteria(configuration.class);
      criteria.addOrder(Order.desc("dateCreated"));
      return criteria.list();
    }
  }
  public ListAndPagingInfo<Customer> searchCustomer(String name) {

    // use findByCriteria4Page method

    name = JSFTools.processNull(name);
    DetachedCriteria criteria = DetachedCriteria.forClass(Customer.class);

    if (!StringUtil.isEmptyString(name)) {
      criteria.add(Restrictions.like("name", name, MatchMode.ANYWHERE));
    }
    if (PaginationContext.getPaginationSortOrderData() != null
        && PaginationContext.getPaginationSortOrderData().getSortValue() == null) {
      PaginationContext.getPaginationSortOrderData().setSortValue("updatedDt");
      PaginationContext.getPaginationSortOrderData().setAscending(false);
    }
    return findByCriteria4Page(criteria);

    // use find4Page method
    /*
     * name = JSFTools.processNull(name); String hql =
     * "FROM Customer customer " + "WHERE  customer.name like ? " +
     * "ORDER BY customer.updatedDt DESC";
     *
     * String hqlCount = "SELECT COUNT(*) FROM Customer customer " +
     * "WHERE  customer.name like ? " + "ORDER BY customer.updatedDt DESC";
     *
     * return this.find4Page(hql, hqlCount, new String[]{"%" + name + "%"});
     */

  }
 public static synchronized void brisiNovostZaPredmet(int predmetID) {
   Session session = null;
   Transaction tx = null;
   try {
     session = dbHelper.getSessionFact().openSession();
     tx = session.beginTransaction();
     ArrayList<Novost> list =
         (ArrayList<Novost>)
             session
                 .createCriteria(Novost.class)
                 .add(Restrictions.like("urlInfo", predmetID + "-%-%"))
                 .list();
     for (Novost k : list) {
       session.delete(k);
     }
     tx.commit();
   } catch (Exception ex) {
     System.out.println("Error..." + ex.getMessage());
     if (tx != null) {
       tx.rollback();
     }
   } finally {
     if (session != null) {
       session.flush();
       session.close();
     }
   }
 }
 private Criteria createCriteriaByCriteres(CritereRechercheContratDto criteres) {
   final Criteria crit = createCriteria(Contrat.class);
   crit.createAlias("statut", "statut");
   if (criteres != null && criteres.getIdAssure() != null) {
     crit.add(Restrictions.eq("uidAssure", criteres.getIdAssure()));
   }
   if (criteres != null && criteres.getIdSouscripteur() != null) {
     crit.add(Restrictions.eq("uidSouscripteur", criteres.getIdSouscripteur()));
   }
   if (criteres != null && criteres.isIdAssureNull()) {
     crit.add(Restrictions.isNull("uidAssure"));
   }
   if (criteres != null && StringUtils.isNotBlank(criteres.getNumeroContrat())) {
     crit.add(Restrictions.ilike("numeroContrat", criteres.getNumeroContrat() + "%"));
   }
   if (criteres != null
       && criteres.getHasContratEnCours() != null
       && criteres.getHasContratEnCours()) {
     crit.add(Restrictions.eq("statut.id", adherentMappingService.getIdStatutContratEnCours()));
   }
   if (criteres != null
       && criteres.getContratEid() != null
       && StringUtils.isNotBlank(criteres.getContratEid())) {
     crit.add(Restrictions.like("identifiantExterieur", "%" + criteres.getContratEid() + "%"));
   }
   crit.add(Restrictions.eq("isVisible", true));
   return crit;
 }
  public Page<Log> find(Page<Log> page, Map<String, Object> paramMap) {
    DetachedCriteria dc = logDao.createDetachedCriteria();

    Long createById = StringUtils.toLong(paramMap.get("createById"));
    if (createById > 0) {
      dc.add(Restrictions.eq("createBy.id", createById));
    }

    String requestUri = ObjectUtils.toString(paramMap.get("requestUri"));
    if (StringUtils.isNotBlank(requestUri)) {
      dc.add(Restrictions.like("requestUri", "%" + requestUri + "%"));
    }

    String exception = ObjectUtils.toString(paramMap.get("exception"));
    if (StringUtils.isNotBlank(exception)) {
      dc.add(Restrictions.eq("type", Log.TYPE_EXCEPTION));
    }

    Date beginDate = DateUtils.parseDate(paramMap.get("beginDate"));
    if (beginDate == null) {
      beginDate = DateUtils.setDays(new Date(), 1);
      paramMap.put("beginDate", DateUtils.formatDate(beginDate, "yyyy-MM-dd"));
    }
    Date endDate = DateUtils.parseDate(paramMap.get("endDate"));
    if (endDate == null) {
      endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1);
      paramMap.put("endDate", DateUtils.formatDate(endDate, "yyyy-MM-dd"));
    }
    dc.add(Restrictions.between("createDate", beginDate, endDate));

    dc.addOrder(Order.desc("id"));
    return logDao.find(page, dc);
  }
Exemple #18
0
  private Criterion filterExactlyBy(final String filter) {
    Disjunction filterDisjunction = Restrictions.disjunction();

    filterDisjunction.add(Restrictions.like(Role.NAME_PROPERTY, filter));

    return filterDisjunction;
  }
  protected Criteria buildProcessInstanceExtensionSearchCriteria(
      long companyId, Long userId, String assetClassName, Long assetClassPK, Boolean completed) {

    Criteria criteria = _session.createCriteria(ProcessInstanceExtensionImpl.class);

    criteria.add(Restrictions.eq("companyId", companyId));

    if (userId != null) {
      criteria.add(Restrictions.eq("userId", userId));
    }

    if (Validator.isNotNull(assetClassName)) {
      criteria.add(Restrictions.like("className", assetClassName));
    }

    if (Validator.isNotNull(assetClassPK)) {
      criteria.add(Restrictions.eq("classPK", assetClassPK));
    }

    if (completed != null) {
      Criteria completionCriteria = criteria.createCriteria("processInstance");

      if (completed) {
        completionCriteria.add(Restrictions.isNotNull("end"));
      } else {
        completionCriteria.add(Restrictions.isNull("end"));
      }
    }

    return criteria;
  }
 /**
  * The 'getOrganizationByName' function will return a single organization based on the name passed
  * in. @Table organizations
  *
  * @param cleanURL Will hold the 'clean' organization name from the url
  * @return This function will return a single organization object
  */
 @Override
 @SuppressWarnings("unchecked")
 public List<configuration> getConfigurationByName(String configName) {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(configuration.class);
   criteria.add(Restrictions.like("configName", configName));
   return criteria.list();
 }
Exemple #21
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() > 1)) {
     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 == 3) {
     sizePioruty++;
   }
   return sizePioruty;
 }
  /**
   * Tìm kiếm nhanh
   *
   * @param c Tiêu chí tìm kiếm
   * @return Danh sách các điện thoại thỏa tiêu chí tìm kiếm
   */
  @SuppressWarnings("unchecked")
  public List<DienThoai> quickSearch(QuickSearchCriteria c) {

    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(DienThoai.class);

    if (c.getIdHangDienThoai() > 0) {
      Criterion manufacture = Restrictions.eq("hangDienThoai.id", c.getIdHangDienThoai());
      criteria.add(manufacture);
    }

    if (c.getTenDienThoai() != null) {
      Criterion name = Restrictions.like("ten", "%" + c.getTenDienThoai() + "%");
      criteria.add(name);
    }

    if (c.getGiaTu() >= 0.0) {
      Criterion minPrice = Restrictions.ge("giaHienHanh", c.getGiaTu());
      criteria.add(minPrice);
    }

    if (c.getGiaDen() >= 0.0) {
      Criterion maxPrice = Restrictions.le("giaHienHanh", c.getGiaDen());
      criteria.add(maxPrice);
    }
    criteria.add(Restrictions.eq("xoa", false));

    return criteria.list();
  }
 public List<Standard> selectAll() {
   List<Standard> get = null;
   DetachedCriteria criteria = DetachedCriteria.forClass(Standard.class);
   criteria.add(Restrictions.like("type", "%"));
   get = (List<Standard>) this.hibernateTemplate.findByCriteria(criteria);
   return get;
 }
  /**
   * Tìm kiếm nhanh
   *
   * @param idHangDienThoai id của HangDienThoai.
   * @param ten tên DienThoai.
   * @param giaTu giá chặn dưới.
   * @param giaDen giá chặn trên.
   * @return Danh sách DienThoai thỏa tiêu chí tìm kiếm.
   */
  @SuppressWarnings("unchecked")
  public List<DienThoai> quickSearch(int idHangDienThoai, String ten, double giaTu, double giaDen) {

    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(DienThoai.class);

    if (idHangDienThoai > 0) {
      Criterion manufacture = Restrictions.eq("hangDienThoai.id", idHangDienThoai);
      criteria.add(manufacture);
    }

    if (ten != null) {
      Criterion name = Restrictions.like("ten", "%" + ten + "%");
      criteria.add(name);
    }

    if (giaTu >= 0.0) {
      Criterion minPrice = Restrictions.ge("giaHienHanh", giaTu);
      criteria.add(minPrice);
    }

    if (giaDen >= 0.0) {
      Criterion maxPrice = Restrictions.le("giaHienHanh", giaDen);
      criteria.add(maxPrice);
    }
    criteria.add(Restrictions.eq("xoa", false));

    return criteria.list();
  }
Exemple #25
0
  @Override
  public List<Log> list(ListLogRequest logParam, int pageIndex, int pageSize) {

    DetachedCriteria criteria = DetachedCriteria.forClass(Log.class);

    // TODO 添加大小不敏感
    if (StringUtils.isNotBlank(logParam.getLoginName())) {
      criteria.add(Restrictions.like("loginName", "%" + logParam.getLoginName() + "%"));
    }

    if (logParam.getOperationUsers() != null && logParam.getOperationUsers().length > 0) {
      criteria.add(Restrictions.in("loginName", logParam.getOperationUsers()));
    }
    if (StringUtils.isNotBlank(logParam.getModule())) {
      criteria.add(Restrictions.eq("module", logParam.getModule()));
    }
    if (StringUtils.isNotBlank(logParam.getOperation())) {
      criteria.add(Restrictions.eq("operation", logParam.getOperation()));
    }

    if (logParam.getStartDate() != null) {
      criteria.add(Restrictions.ge("createdOn", logParam.getStartDate()));
    }
    if (logParam.getEndDate() != null) {
      criteria.add(Restrictions.le("createdOn", logParam.getEndDate()));
    }
    criteria.addOrder(Order.desc("createdOn"));

    List result = (List<Log>) findByCriteria(criteria, pageIndex, pageSize);

    return result;
  }
 @SuppressWarnings("unchecked")
 public List<DistributorVersion> findByNameSearch(String name) {
   return currentSession()
       .createCriteria(DistributorVersion.class)
       .add(Restrictions.like("name", "%" + name + "%"))
       .list();
 }
Exemple #27
0
  public List findByRoleNameLike(String roleName) {

    Session session = HibernateTrain.getSession();
    Criteria criteria =
        session.createCriteria(StaffRole.class).add(Restrictions.like("roleName", roleName));
    return criteria.list();
  }
  /** 按属性条件参数创建Criterion,辅助函数. */
  protected Criterion buildCriterion(
      final String propertyName, final Object propertyValue, final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName不能为空");
    Criterion criterion = null;
    // 根据MatchType构造criterion
    switch (matchType) {
      case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
      case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;

      case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
      case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
      case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
      case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
    }
    return criterion;
  }
  public BankaMemuru checkBankaMemuruLoginInfo(
      String par_sBankaMemuruName, String par_sBankaMemuruPass) {
    BankaMemuru currentBankaMemuru = null;

    System.out.println(
        "checkBankaMemuruLoginInfo " + par_sBankaMemuruName + " " + par_sBankaMemuruPass);

    par_sBankaMemuruPass = PasswordHash.hashPassword(par_sBankaMemuruPass);

    System.out.println(
        "hashten sonra checkUserLoginInfo " + par_sBankaMemuruPass + " " + par_sBankaMemuruName);

    baslat();
    HibernateSession.beginTransaction();
    session = getSession();

    Criteria crit = session.createCriteria(BankaMemuru.class);

    if (par_sBankaMemuruName != null && par_sBankaMemuruName != "") {
      System.out.println("girdim2");
      Criterion name = Restrictions.like("bankaMemuruUyeAdi", par_sBankaMemuruName);
      crit.add(name);
    }
    if (par_sBankaMemuruPass != null && par_sBankaMemuruPass != "") {
      System.out.println("girdim3");
      Criterion name = Restrictions.like("bankaMemuruSifre", par_sBankaMemuruPass);
      crit.add(name);
    }

    List results = crit.list();
    for (Object o : results) {
      currentBankaMemuru = (BankaMemuru) o;
      System.out.println(
          "\nsonuc müþteri: "
              + ((BankaMemuru) o).getBankaMemuruUyeAdi()
              + " "
              + ((BankaMemuru) o).getBankaMemuruId()
              + "\n");
    }

    HibernateSession.commitTransaction();
    sonlandir();

    System.out.println("\ncheckBankaMemuruLoginInfo bitti");

    return currentBankaMemuru;
  }
 public List<Comida> buscaPorNome(String nome) {
   session = HibernateConexao.getSession();
   session.beginTransaction().begin();
   List list =
       session.createCriteria(classe).add(Restrictions.like("nome", "%" + nome + "%")).list();
   session.close();
   return list;
 }