Example usage for org.hibernate.criterion Restrictions le

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

Introduction

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

Prototype

public static SimpleExpression le(String propertyName, Object value) 

Source Link

Document

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

Usage

From source file:com.valco.dao.NotasVentaDAO.java

public List<NotasDeVenta> getNotasXRangoFolio(Integer folioInicial, Integer folioFinal) throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;/*from  ww  w  .  ja  va2 s.c o  m*/
    List<NotasDeVenta> notas = new ArrayList<NotasDeVenta>();
    try {
        tx = session.beginTransaction();
        Criteria q = session.createCriteria(NotasDeVenta.class).add(Restrictions.ge("folio", folioInicial))
                .add(Restrictions.le("folio", folioFinal));
        notas = (List<NotasDeVenta>) q.list();
        return notas;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar los clientes.");

    } finally {
        try {
            if (session.isOpen()) {
                session.close();
            }
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar los clientes.");
        }
    }
}

From source file:com.viettel.ttbankplus.servicegw.hibernate.dao.transaction.TransferMerchantDAO.java

License:Open Source License

public List<TransferMerchant> getListTransfer(Date fromDate, Date toDate, ArrayList<String> lstCpCode) {
    try {/*from  ww  w . j  a  va2s.co  m*/
        List<TransferMerchant> lst = null;

        Criteria crt = getSession().createCriteria(TransferMerchant.class);
        crt.add(Restrictions.in("cpCode", lstCpCode)).add(Restrictions.ge("requestDate", fromDate))
                .add(Restrictions.le("requestDate", toDate));
        lst = crt.list();
        return lst;
    } catch (Exception e) {
        return null;
    } finally {
        //        PHUCPT edit Jan, 05th 2017
        DAOFactory.commitCurrentSessions();
        //        end edit
    }
}

From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java

License:Open Source License

public Criterion getCriterion() throws Exception {
    if (condition.equals(EQ)) {
        if (value == null || value.toString().trim().length() == 0) {
            return Restrictions.isNull(fullKey);
        } else {//from  w w  w  .j  av a 2  s .  c om
            return Restrictions.eq(fullKey, value);
        }
    }

    if (condition.equals(NE)) {
        if (value == null || value.toString().trim().length() == 0) {
            return Restrictions.isNotNull(fullKey);
        } else {
            return Restrictions.ne(fullKey, value);
        }
    }

    if (condition.equals(GT)) {
        assertNonNullity(value);
        return Restrictions.gt(fullKey, value);
    }

    if (condition.equals(GE)) {
        assertNonNullity(value);
        return Restrictions.ge(fullKey, value);
    }

    if (condition.equals(LT)) {
        assertNonNullity(value);
        return Restrictions.lt(fullKey, value);
    }

    if (condition.equals(LE)) {
        assertNonNullity(value);
        return Restrictions.le(fullKey, value);
    }

    if (condition.equals(IN_A_RANGE)) {
        assertNonNullity(value);
        assertNonNullity(diff);
        return getPercentRange();
    }

    if (condition.equals(ENDS_WITH)) {
        return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()));
    }

    if (condition.equals(STARTS_WITH)) {
        return Restrictions.like(fullKey, StringUtils.trim(value.toString()) + "%");
    }

    if (condition.equals(CONTAINS)) {
        return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%');
    }

    if (condition.equals(NOT_CONTAIN)) {
        return Restrictions.not(Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%'));
    }

    LOGGER.error(
            "Undefined User Criteria [key:{0}, value:{1}, condition:{3}] couldn't be transformed to search criterion",
            fullKey, value, condition);

    throw new RuntimeException("Undefined User Criteria: " + name);
}

From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java

License:Open Source License

private Criterion getPercentRange() {
    BigDecimal bdValue = new BigDecimal(value.toString());

    BigDecimal range = bdValue.multiply(new BigDecimal(diff).divide(new BigDecimal(100)));

    BigDecimal bdValueFrom = bdValue.subtract(range);
    BigDecimal bdValueTo = bdValue.add(range);
    return Restrictions.and(Restrictions.ge(fullKey, bdValueFrom), Restrictions.le(fullKey, bdValueTo));
}

From source file:com.weigandtconsulting.javaschool.db.hibernate.HibernateApp.java

License:Open Source License

public static void main(String[] args) {
    try {//w  w  w  .  jav  a 2s. c o m
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        // HQL
        List<CustomerContract> customerContract = (List<CustomerContract>) session
                .createQuery("from CustomerContract order by contract").setMaxResults(MAX_RESULT).list();
        displayResult(customerContract);

        // SQL
        List<CustomerContract> customerContractSQL = (List<CustomerContract>) session
                .createSQLQuery("select contract, description, status from CUSTOMER_CONTRACT")
                .addScalar("contract").addScalar("description").addScalar("status")
                .setResultTransformer(Transformers.aliasToBean(CustomerContract.class))
                .setMaxResults(MAX_RESULT).list();
        displayResult(customerContractSQL);

        // Criteria
        List<CustomerContract> customerContractCr = (List<CustomerContract>) session
                .createCriteria(CustomerContract.class).add(Restrictions.le("status", "I"))
                .setMaxResults(MAX_RESULT).list();
        displayResult(customerContractCr);

        //            Transaction tx = session.beginTransaction();
        //            tx.setTimeout(5);
        //          //doSomething(session);
        //            tx.commit();

        session.flush();
        session.close();

    } catch (HibernateException he) {
        he.printStackTrace();
    } finally {
        HibernateUtil.getSessionFactory().close();
    }
}

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

License:Apache License

/**
 * ??Criterion,./* w w w . j  a v  a  2  s.c  o m*/
 */
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,./*from  w w  w .  jav a  2s. 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 w  w  w .  j a va 2 s. c o m
 */
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.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. jav  a  2s . c o m*/
    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());
    }//from www.  j  a v  a 2 s. 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);
}