Example usage for org.hibernate.criterion Restrictions lt

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

Introduction

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

Prototype

public static SimpleExpression lt(String propertyName, Object value) 

Source Link

Document

Apply a "less than" constraint to the named property

Usage

From source file:org.generationcp.middleware.dao.TransactionDAO.java

License:Open Source License

public long countAllReserve() throws MiddlewareQueryException {
    try {// w ww.  ja v  a  2s. c  om
        Criteria criteria = getSession().createCriteria(Transaction.class);
        criteria.setProjection(Projections.rowCount());
        criteria.add(Restrictions.eq("status", Integer.valueOf(0)));
        criteria.add(Restrictions.lt("quantity", Integer.valueOf(0)));
        return ((Long) criteria.uniqueResult()).longValue(); //count
    } catch (HibernateException e) {
        throw new MiddlewareQueryException(
                "Error with countAllReserve() query from Transaction: " + e.getMessage(), e);
    }
}

From source file:org.generationcp.middleware.dao.TransactionDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Transaction> getAllReserveByRequestor(Integer personId, int start, int numOfRows)
        throws MiddlewareQueryException {
    try {//from  w  w w .j  a v  a 2s . c o  m
        Criteria criteria = getSession().createCriteria(Transaction.class);
        criteria.add(Restrictions.eq("status", Integer.valueOf(0)));
        criteria.add(Restrictions.lt("quantity", Integer.valueOf(0)));
        criteria.add(Restrictions.eq("personId", personId));
        criteria.setFirstResult(start);
        criteria.setMaxResults(numOfRows);
        return criteria.list();
    } catch (HibernateException e) {
        throw new MiddlewareQueryException("Error with getAllReserveByRequestor(personId=" + personId
                + ") query from Transaction: " + e.getMessage(), e);
    }
}

From source file:org.generationcp.middleware.dao.TransactionDAO.java

License:Open Source License

public long countAllReserveByRequestor(Integer personId) throws MiddlewareQueryException {
    try {/*from w w  w  . j  ava 2  s . com*/
        Criteria criteria = getSession().createCriteria(Transaction.class);
        criteria.setProjection(Projections.rowCount());
        criteria.add(Restrictions.eq("status", Integer.valueOf(0)));
        criteria.add(Restrictions.lt("quantity", Integer.valueOf(0)));
        criteria.add(Restrictions.eq("personId", personId));
        return ((Long) criteria.uniqueResult()).longValue(); //count
    } catch (HibernateException e) {
        throw new MiddlewareQueryException("Error with countAllReserveByRequestor(personId=" + personId
                + ") query from Transaction: " + e.getMessage(), e);
    }
}

From source file:org.generationcp.middleware.dao.TransactionDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Transaction> getAllWithdrawals(int start, int numOfRows) throws MiddlewareQueryException {
    try {//  ww w . ja va2  s .  c o m
        Criteria criteria = getSession().createCriteria(Transaction.class);
        criteria.add(Restrictions.lt("quantity", Integer.valueOf(0)));
        criteria.setFirstResult(start);
        criteria.setMaxResults(numOfRows);
        return criteria.list();
    } catch (HibernateException e) {
        throw new MiddlewareQueryException(
                "Error with getAllWithdrawals() query from Transaction: " + e.getMessage(), e);
    }
}

From source file:org.generationcp.middleware.dao.TransactionDAO.java

License:Open Source License

public long countAllWithdrawals() throws MiddlewareQueryException {
    try {//  www . j av  a 2  s .c om
        Criteria criteria = getSession().createCriteria(Transaction.class);
        criteria.setProjection(Projections.rowCount());
        criteria.add(Restrictions.lt("quantity", Integer.valueOf(0)));
        return ((Long) criteria.uniqueResult()).longValue(); //count
    } catch (HibernateException e) {
        throw new MiddlewareQueryException(
                "Error with countAllWithdrawals() query from Transaction: " + e.getMessage(), e);
    }
}

From source file:org.geolatte.common.cql.hibernate.HibernateCriteriaBuilder.java

License:Open Source License

@Override
public void outALtExpr(ALtExpr node) {

    String propertyAlias = createAlias(node.getLeft());
    translatedExpressions.put(node, Restrictions.lt(propertyAlias, reader.parseAsPropertyType(
            translatedLiterals.get(node.getRight()).toString(), getPropertyPath(node.getLeft()))));
}

From source file:org.geolatte.common.cql.hibernate.HibernateCriteriaBuilder.java

License:Open Source License

@Override
public void outABeforeExpr(ABeforeExpr node) {

    String propertyAlias = createAlias(node.getAttr());
    translatedExpressions.put(node,// ww  w  .ja v a 2s.  com
            Restrictions.lt(propertyAlias, parseDate(node.getDateTime().toString().trim())));
}

From source file:org.geolatte.common.cql.hibernate.HibernateCriteriaBuilder.java

License:Open Source License

@Override
public void outADuringExpr(ADuringExpr node) {

    PTimespanLiteral timespan = node.getTimeSpan();

    Criterion greaterThan;/*from w  ww.  j  a va2s .c  o  m*/
    Criterion lowerThan;

    if (timespan instanceof AFromToTimespanLiteral) {

        AFromToTimespanLiteral fromToTimespan = (AFromToTimespanLiteral) timespan;
        greaterThan = Restrictions.gt(node.getAttr().toString().trim(),
                parseDate(fromToTimespan.getFrom().getText().trim()));
        lowerThan = Restrictions.lt(node.getAttr().toString().trim(),
                parseDate(fromToTimespan.getTo().getText().trim()));
    } else if (timespan instanceof AFromDurationTimespanLiteral) {

        AFromDurationTimespanLiteral fromDurationTimespan = (AFromDurationTimespanLiteral) timespan;
        Date fromDate = parseDate(fromDurationTimespan.getFrom().getText().trim());
        Duration duration = (Duration) translatedLiterals.get(fromDurationTimespan.getDuration());

        // Calculate to 'to' date
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(fromDate);
        calendar.add(Calendar.YEAR, duration.getYears());
        calendar.add(Calendar.MONTH, duration.getMonths());
        calendar.add(Calendar.DATE, duration.getDays());
        calendar.add(Calendar.HOUR, duration.getHours());
        calendar.add(Calendar.MINUTE, duration.getMinutes());
        calendar.add(Calendar.SECOND, duration.getSeconds());
        Date toDate = calendar.getTime();

        greaterThan = Restrictions.gt(node.getAttr().toString().trim(), fromDate);
        lowerThan = Restrictions.lt(node.getAttr().toString().trim(), toDate);

    } else { // if (timespan instanceof ADurationToTimespanLiteral)

        greaterThan = null;
        lowerThan = null;
    }

    Criterion combined = Restrictions.and(greaterThan, lowerThan);
    translatedExpressions.put(node, combined);
}

From source file:org.geomajas.layer.hibernate.CriteriaVisitor.java

License:Open Source License

/** {@inheritDoc} */
@Override//from  w w  w . j ava  2  s .  c  om
public Object visit(PropertyIsLessThan filter, Object userData) {
    String propertyName = getPropertyName(filter.getExpression1());
    String finalName = parsePropertyName(propertyName, userData);

    Object literal = getLiteralValue(filter.getExpression2());
    return Restrictions.lt(finalName, castLiteral(literal, propertyName));
}

From source file:org.geomajas.layer.hibernate.CriteriaVisitor.java

License:Open Source License

/** {@inheritDoc} */
@Override/*ww w  . j ava 2 s  . co m*/
public Object visit(Before before, Object extraData) {
    String propertyName = getPropertyName(before.getExpression1());
    String finalName = parsePropertyName(propertyName, before);
    Object literal = getLiteralValue(before.getExpression2());
    if (literal instanceof Date) {
        return Restrictions.lt(finalName, literal);
    } else {
        throw new UnsupportedOperationException("visit(Object userData)");
    }
}