Example usage for org.hibernate.criterion Restrictions ge

List of usage examples for org.hibernate.criterion Restrictions ge

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions ge.

Prototype

public static SimpleExpression ge(String propertyName, Object value) 

Source Link

Document

Apply a "greater than or equal" constraint to the named property

Usage

From source file:com.wwinsoft.modules.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,./* w ww. j  a v  a2s  .c  om*/
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final PropertyFilter.MatchType matchType) {
    Assert.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    //?MatchTypecriterion
    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;
}

From source file:com.xbwl.common.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * Criterion,./*  w w w .  j a  v a2 s . co m*/
 */
protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName");
    Criterion criterion = null;
    try {

        //MatchTypecriterion
        if (MatchType.EQ.equals(matchType)) {
            criterion = Restrictions.eq(propertyName, propertyValue);
        } else if (MatchType.LIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        } else if (MatchType.LE.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue);
        } else if (MatchType.LT.equals(matchType)) {
            criterion = Restrictions.lt(propertyName, propertyValue);
        } else if (MatchType.GE.equals(matchType)) {
            criterion = Restrictions.ge(propertyName, propertyValue);
        } else if (MatchType.GT.equals(matchType)) {
            criterion = Restrictions.gt(propertyName, propertyValue);
        } else if (MatchType.NE.equals(matchType)) {
            criterion = Restrictions.ne(propertyName, propertyValue);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
    return criterion;
}

From source file:com.xin.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,.//from   ww w  .j a  v  a 2 s  .c  om
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    AssertUtils.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    // ?MatchTypecriterion
    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;
}

From source file:com.xuanhai.repositories.OrderedTableRepository.java

public List<DatBan> getByTableId(int id) {
    Session s = HibernateUtil.getSessionFactory().openSession();
    s.beginTransaction();//from   w  w  w  .  ja va 2  s.  com

    Ban ban = tableRepo.get(id);

    if (ban != null) {
        List<DatBan> datBans = s.createCriteria(DatBan.class).add(Restrictions.eq("ban", ban))
                .add(Restrictions.ge("createDate", ban.getUpdateDate())).list();

        s.getTransaction().commit();

        if (datBans.isEmpty()) {
            return null;
        } else {
            return datBans;
        }
    }

    return null;

}

From source file:com.yahoo.elide.datastores.hibernate3.filter.CriterionFilterOperation.java

License:Apache License

@Override
public Criterion apply(FilterPredicate filterPredicate) {
    List<FilterPredicate.PathElement> path = filterPredicate.getPath();

    /* If the predicate refers to a nested association, the restriction should be 'alias.fieldName' */
    String alias;//from w  w w  .  j  a va2  s . c om
    if (path.size() > 1) {
        alias = getAlias(path);
        alias = alias + "." + path.get(path.size() - 1).getFieldName();
        /* If the predicate refers to the root entity, the restriction should be 'fieldName' */
    } else {
        alias = path.get(0).getFieldName();
    }

    switch (filterPredicate.getOperator()) {
    case IN:
        if (filterPredicate.getValues().isEmpty()) {
            return Restrictions.sqlRestriction("(false)");
        }
        return Restrictions.in(alias, filterPredicate.getValues());
    case NOT:
        if (filterPredicate.getValues().isEmpty()) {
            return Restrictions.sqlRestriction("(true)");
        }
        return Restrictions.not(Restrictions.in(alias, filterPredicate.getValues()));
    case PREFIX:
        return Restrictions.like(alias,
                filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)
                        + MATCHALL_CHARACTER);
    case PREFIX_CASE_INSENSITIVE:
        return Restrictions.ilike(alias,
                filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)
                        + MATCHALL_CHARACTER);
    case POSTFIX:
        return Restrictions.like(alias, MATCHALL_CHARACTER
                + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER));
    case POSTFIX_CASE_INSENSITIVE:
        return Restrictions.ilike(alias, MATCHALL_CHARACTER
                + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER));
    case INFIX:
        return Restrictions.like(alias,
                MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)
                        + MATCHALL_CHARACTER);
    case INFIX_CASE_INSENSITIVE:
        return Restrictions.ilike(alias,
                MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)
                        + MATCHALL_CHARACTER);
    case ISNULL:
        return Restrictions.isNull(alias);
    case NOTNULL:
        return Restrictions.isNotNull(alias);
    case LT:
        return Restrictions.lt(alias, filterPredicate.getValues().get(0));
    case LE:
        return Restrictions.le(alias, filterPredicate.getValues().get(0));
    case GT:
        return Restrictions.gt(alias, filterPredicate.getValues().get(0));
    case GE:
        return Restrictions.ge(alias, filterPredicate.getValues().get(0));
    case TRUE:
        return Restrictions.sqlRestriction("(true)");
    case FALSE:
        return Restrictions.sqlRestriction("(false)");
    default:
        throw new InvalidPredicateException("Operator not implemented: " + filterPredicate.getOperator());
    }
}

From source file:com.zdtx.ifms.specific.service.analy.SpeInstructionManager.java

public Page<SpeInstruction> getBatch(Page<SpeInstruction> page, CounsellVo deVo) {
    Criteria criteria = baseDao.getSession().createCriteria(SpeInstruction.class);

    if (!Utils.isEmpty(deVo.getUname())) {
        criteria.add(Restrictions.like("licenseplate", "%" + deVo.getUname().trim() + "%").ignoreCase());
    }/*www  .  ja v  a 2s.c  o m*/
    if (!Utils.isEmpty(deVo.getCode())) {
        criteria.add(Restrictions.eq("code", deVo.getCode()));
    }
    if (!Utils.isEmpty(deVo.getUsername())) {
        criteria.add(Restrictions.like("creater", "%" + deVo.getUsername().trim() + "%").ignoreCase());
    }
    if (!Utils.isEmpty(deVo.getTimeMin())) {
        criteria.add(Restrictions.ge("creatime", deVo.getTimeMin()));
    }
    if (!Utils.isEmpty(deVo.getTimeMax())) {
        criteria.add(Restrictions.le("creatime", deVo.getTimeMax()));
    }
    List<Order> orders = new ArrayList<Order>();
    orders.add(Order.desc("creatime"));
    orders.add(Order.asc("licenseplate"));
    orders.add(Order.asc("code"));
    return baseDao.getBatch(page, criteria, orders);
}

From source file:com.zdtx.ifms.specific.service.task.FuelMileageManager.java

public Page<Mileageoil> getBetch(Page<Mileageoil> page, FuelMileageVo fmvo) {
    DetachedCriteria criteria = DetachedCriteria.forClass(Mileageoil.class);
    if (fmvo.getVehicleid() != null && fmvo.getVehicleid() != -1) {
        criteria.add(Restrictions.eq("vehicleid", fmvo.getVehicleid()));
    }/* w  w w . j  a v a2s . c o m*/
    if (fmvo.getTypeid() != null && fmvo.getTypeid() != -1l) {
        criteria.add(Restrictions.eq("typeid", fmvo.getTypeid()));
    }

    if (fmvo.getStartdate() != null && !"".equals(fmvo.getStartdate())) {
        criteria.add(Restrictions.ge("riqi", fmvo.getStartdate()));
    }
    if (fmvo.getEnddate() != null && !"".equals(fmvo.getEnddate())) {
        criteria.add(Restrictions.le("riqi", fmvo.getEnddate()));
    }

    List<Order> orderList = new ArrayList<Order>();
    orderList.add(Order.asc("riqi"));
    Page<Mileageoil> pageResult = baseDao.getBatch(page, criteria.getExecutableCriteria(baseDao.getSession()),
            orderList);
    if (1 == pageResult.getCurrentPage()) {
        Struts2Util.getSession().setAttribute("criteria_export", criteria);
        Struts2Util.getSession().setAttribute("page_export", page);
        Struts2Util.getSession().setAttribute("order_export", orderList);
    }
    return pageResult;
}

From source file:com.zhima.base.dao.BaseDao.java

License:Open Source License

/**
 * ?criteriaeq,gt,ge,lt,le?// w ww.j av  a  2 s  .  c  o  m
 * 
 * @param criteria
 * @param list
 *            ??
 */
@SuppressWarnings("rawtypes")
private void setExpression(Criteria criteria, String[] list, String expression, Object dto) {
    Class dtoClass = dto.getClass();
    try {
        for (String str : list) {
            if (str != null && !"".equals(str.trim())) {
                Field dtoField = dtoClass.getDeclaredField(str);
                dtoField.setAccessible(true);
                if (dtoField != null) {
                    if (HibernateConstrant.HIBERNATE_CRITERIA_EQ.equals(expression)) {
                        criteria.add(Restrictions.eq(str, dtoField.get(dto)));
                    } else if (HibernateConstrant.HIBERNATE_CRITERIA_GE.equals(expression)) {
                        criteria.add(Restrictions.gt(str, dtoField.get(dto)));
                    } else if (HibernateConstrant.HIBERNATE_CRITERIA_GT.equals(expression)) {
                        criteria.add(Restrictions.ge(str, dtoField.get(dto)));
                    } else if (HibernateConstrant.HIBERNATE_CRITERIA_LT.equals(expression)) {
                        criteria.add(Restrictions.lt(str, dtoField.get(dto)));
                    } else if (HibernateConstrant.HIBERNATE_CRITERIA_LE.equals(expression)) {
                        criteria.add(Restrictions.le(str, dtoField.get(dto)));

                    } else if (HibernateConstrant.HIBERNATE_CRITERIA_NE.equals(expression)) {
                        criteria.add(Restrictions.ne(str, dtoField.get(dto)));
                    } else if (HibernateConstrant.HIBERNATE_CRITERIA_LIKE.equals(expression)) {
                        criteria.add(Restrictions.like(str, "%" + dtoField.get(dto) + "%"));
                    }
                }

            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.zl.bgec.basicapi.shop.service.impl.ShopServiceImpl.java

@Override
@Transactional(readOnly = true)/*from  w  w  w .j  a va  2s .c o  m*/
public Map<String, Object> getShopIndexInfo(String memberNo) throws Exception {
    String sql = "select tsi.shop_name shopName," + "tsi.shop_address shopAddress," + "tsi.shop_logo shopLogo,"
            + "tsi.status status, " + "tsi.shop_no shopNo "
            + "from tbl_shop_info tsi where tsi.merch_no=:shopNo and tsi.status!='3'";
    Query query = shopDao.createSQLQuery(sql);
    query.setParameter("shopNo", memberNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> results = query.list();
    Map<String, Object> result = new HashMap<String, Object>();
    if (results != null && !results.isEmpty()) {
        result = results.get(0);
    } else {
        return null;
    }
    String shopNo = String.valueOf(result.get("shopNo"));
    Criteria criteria = commodityDao.createCriteria(Restrictions.eq("sellerNo", shopNo));
    criteria.add(Restrictions.eq("deleteFlag", (byte) 0));//
    criteria.add(Restrictions.eq("publishState", "1"));//
    int commodityCount = commodityDao.getRowCount(criteria);// ??
    result.put("commodityCount", String.valueOf(commodityCount));
    criteria = shopCollectDao.createCriteria(Restrictions.eq("shopNo", shopNo));
    int collectCount = shopCollectDao.getRowCount(criteria);
    result.put("collectCount", String.valueOf(collectCount));
    Criteria promotionCriteria = promotionDao.createCriteria(Restrictions.eq("shopNo", shopNo));
    promotionCriteria.add(Restrictions.ge("endTime", new Date()));//
    promotionCriteria.add(Restrictions.eq("status", "2"));//
    promotionCriteria.add(Restrictions.eq("lockFlag", "0"));//?
    promotionCriteria.add(Restrictions.ne("promotionType", "2"));//?
    int count = promotionDao.getRowCount(promotionCriteria);
    result.put("promotionCount", count);
    List<String> values = new ArrayList<String>();
    //      values.add(OrderConstants.BASIC_STATE_REFUND);
    //      values.add(OrderConstants.BASIC_STATE_ALREADY_RECEIVE);
    //      values.add(OrderConstants.BASIC_STATE_REFUND_APPLY);
    values.add(OrderConstants.BASIC_STATE_WAITING_DELIVERY);
    //      values.add(OrderConstants.BASIC_STATE_WAITING_RETURN);
    //      values.add(OrderConstants.BASIC_STATE_WAITING_PAY);
    //      values.add(OrderConstants.BASIC_STATE_ALREADY_DELIVERY);
    Criteria criteriaOrder = orderDao.createCriteria(Restrictions.in("basicState", values));
    criteriaOrder.add(Restrictions.eq("deleteFlag", (byte) 0));
    criteriaOrder.add(Restrictions.eq("shopNo", shopNo));
    String sqlGroupBuy = "select count(*) " + "  from tbl_promotion tp "
            + " left join tbl_product tpr on tp.ref_commo_no = tpr.commo_no"
            + " where tp.promotion_type='2' and tp.delete_flag='0' and tp.shop_no=:shopNo  and :curentTime between tp.start_time and tp.end_time ";
    Query groupBuyQuery = promotionDao.createSQLQuery(sqlGroupBuy);
    groupBuyQuery.setParameter("shopNo", shopNo);
    groupBuyQuery.setParameter("curentTime", new Date());
    BigInteger totalRows = (BigInteger) groupBuyQuery.uniqueResult();
    result.put("groupBuyCount", totalRows.intValue());
    result.put("orderCount", orderDao.getRowCount(criteriaOrder));
    String gradeSql = "select  avg(tcc.service_grade) serviceGrade," + " avg(tcc.delivery_grade) deliveryGrade"
            + " from tbl_commodity_comment tcc " + " where tcc.shop_no = :shopNo " + " group by(tcc.shop_no) ";
    Query queryGrade = shopDao.createSQLQuery(gradeSql);
    queryGrade.setParameter("shopNo", shopNo);
    queryGrade.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> list = queryGrade.list();
    if (list != null && !list.isEmpty()) {
        Double servGrade = list.get(0).get("serviceGrade") == null ? 0
                : Double.valueOf(list.get(0).get("serviceGrade").toString());
        BigDecimal serviceGrade = new BigDecimal(servGrade);
        serviceGrade = serviceGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN);
        result.put("serviceGrade", serviceGrade.doubleValue());
        Double delGrade = list.get(0).get("deliveryGrade") == null ? 0
                : Double.valueOf(list.get(0).get("deliveryGrade").toString());
        BigDecimal deliveryGrade = new BigDecimal(delGrade);
        deliveryGrade = deliveryGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN);
        result.put("deliveryGrade", deliveryGrade.doubleValue());
    } else {
        result.put("serviceGrade", "0");
        result.put("deliveryGrade", "0");
    }

    return result;
}

From source file:com.zutubi.pulse.master.model.persistence.hibernate.HibernateBuildResultDao.java

License:Apache License

private void addDatesToCriteria(long earliestStartTime, long latestStartTime, Criteria criteria) {
    if (earliestStartTime > 0) {
        criteria.add(Restrictions.ge("stamps.startTime", earliestStartTime));
    }// www  .java2  s.  co m

    if (latestStartTime > 0) {
        // CIB-446: Don't accept timestamps that are uninitialised
        criteria.add(Restrictions.ge("stamps.startTime", 0L));
        criteria.add(Restrictions.le("stamps.startTime", latestStartTime));
    }
}