Example usage for org.hibernate.criterion Restrictions gt

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

Introduction

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

Prototype

public static SimpleExpression gt(String propertyName, Object value) 

Source Link

Document

Apply a "greater than" constraint to the named property

Usage

From source file:org.javamexico.dao.hib3.ForumDAO.java

License:Open Source License

public List<Foro> getForosRecientes(int page, int pageSize) {
    Session sess = sfact.getCurrentSession();
    @SuppressWarnings("unchecked")
    List<Foro> qus = sess.createCriteria(Foro.class).add(Restrictions.gt("status", 0))
            .addOrder(Order.desc("fecha")).setMaxResults(pageSize).setFirstResult((page - 1) * pageSize).list();
    return qus;//from ww w.ja  va  2s . co  m
}

From source file:org.javamexico.dao.hib3.QuestionDAO.java

License:Open Source License

public List<Pregunta> getPreguntasMasVotadas(int limit) {
    Session sess = sfact.getCurrentSession();
    @SuppressWarnings("unchecked")
    List<Pregunta> qus = sess.createCriteria(Pregunta.class).add(Restrictions.gt("status", 0))
            .addOrder(Order.desc("votos")).setMaxResults(limit).list();
    return qus;/*from   ww w . jav a 2 s  .com*/
}

From source file:org.javamexico.dao.hib3.QuestionDAO.java

License:Open Source License

public List<Pregunta> getPreguntasRecientes(int page, int pageSize) {
    Session sess = sfact.getCurrentSession();
    @SuppressWarnings("unchecked")
    List<Pregunta> qus = sess.createCriteria(Pregunta.class).add(Restrictions.gt("status", 0))
            .addOrder(Order.desc("fechaPregunta")).setMaxResults(pageSize).setFirstResult((page - 1) * pageSize)
            .list();//from  w  ww  .  j a va  2  s .c  o  m
    return qus;
}

From source file:org.jbpm.test.JbpmTestCase.java

License:Open Source License

protected int getJobCount() {
    return processEngine.execute(new Command<Integer>() {
        private static final long serialVersionUID = 1L;

        public Integer execute(Environment environment) {
            org.hibernate.Session session = environment.get(org.hibernate.Session.class);
            return (Integer) session.createCriteria("org.jbpm.pvm.internal.job.JobImpl")
                    .add(Restrictions.gt("retries", 0)).setProjection(Projections.rowCount()).uniqueResult();
        }/* w  w  w.jav  a  2  s  .  c  o m*/
    });
}

From source file:org.jpos.ee.pm.core.DBEntityFilter.java

License:Open Source License

protected Criterion getCompareCriterion(String fid, List<Object> values) {
    Object value_0 = values.get(0);
    switch (getFilterOperation(fid)) {
    case LIKE://www.  ja v a2 s  . c  o m
        if (value_0 instanceof String) {
            return Restrictions.ilike(fid, "%" + value_0 + "%");
        } else {
            return Restrictions.eq(fid, value_0);
        }
    case GE:
        return Restrictions.ge(fid, value_0);
    case GT:
        return Restrictions.gt(fid, value_0);
    case LE:
        return Restrictions.le(fid, value_0);
    case LT:
        return Restrictions.lt(fid, value_0);
    case NE:
        return Restrictions.not(Restrictions.eq(fid, value_0));
    default:
        return Restrictions.eq(fid, value_0);
    }
}

From source file:org.jpos.gl.GLSession.java

License:Open Source License

/**
 * Get Both Balances at given date/*from w  w  w . j a  v a  2  s.c o m*/
 * @param journal the journal.
 * @param acct the account.
 * @param date date (inclusive).
 * @param inclusive either true or false
 * @param layers the layers
 * @param maxId maximum GLEntry ID to be considered in the query (if greater than zero)
 * @return array of 2 BigDecimals with balance and entry count.
 * @throws GLException if user doesn't have READ permission on this jounral.
 */
public BigDecimal[] getBalances(Journal journal, Account acct, Date date, boolean inclusive, short[] layers,
        long maxId) throws HibernateException, GLException {
    checkPermission(GLPermission.READ, journal);
    BigDecimal balance[] = { ZERO, Z };
    if (acct.getChildren() != null) {
        if (acct.isChart()) {
            return getChartBalances(journal, (CompositeAccount) acct, date, inclusive, layers, maxId);
        }
        Iterator iter = acct.getChildren().iterator();
        while (iter.hasNext()) {
            Account a = (Account) iter.next();
            BigDecimal[] b = getBalances(journal, a, date, inclusive, layers, maxId);
            balance[0] = balance[0].add(b[0]);
            // session.evict (a); FIXME this conflicts with r251 (cascade=evict genearting a failed to lazily initialize a collection
        }
    } else if (acct.isFinalAccount()) {
        Criteria entryCrit = session.createCriteria(GLEntry.class).add(Restrictions.eq("account", acct))
                .add(Restrictions.in("layer", toShortArray(layers)));
        if (maxId > 0L)
            entryCrit.add(Restrictions.le("id", maxId));

        Criteria txnCrit = entryCrit.createCriteria("transaction").add(Restrictions.eq("journal", journal));
        if (date != null) {
            if (inclusive) {
                txnCrit.add(Restrictions.lt("postDate", Util.tomorrow(date)));
            } else {
                date = Util.floor(date);
                txnCrit.add(Restrictions.lt("postDate", date));
            }
            Checkpoint chkp = getRecentCheckpoint(journal, acct, date, inclusive, layers);
            if (chkp != null) {
                balance[0] = chkp.getBalance();
                txnCrit.add(Restrictions.gt("postDate", chkp.getDate()));
            }

        } else {
            BalanceCache bcache = getBalanceCache(journal, acct, layers);
            if (bcache != null) {
                balance[0] = bcache.getBalance();
                entryCrit.add(Restrictions.gt("id", bcache.getRef()));
            }
        }
        List l = txnCrit.list();
        balance[0] = applyEntries(balance[0], l);
        balance[1] = new BigDecimal(l.size()); // hint for checkpoint
    }
    return balance;
}

From source file:org.jspresso.framework.model.persistence.hibernate.criterion.DefaultCriteriaFactory.java

License:Open Source License

/**
 * Creates a criterion by processing a comparable query structure.
 *
 * @param path//ww  w . j a  v a2s .  c o m
 *     the path to the comparable property.
 * @param queryStructure
 *     the comparable query structure.
 * @param componentDescriptor
 *     the component descriptor
 * @param queryComponent
 *     the query component
 * @param context
 *     the context
 * @return the created criterion or null if no criterion necessary.
 */
protected Criterion createComparableQueryStructureRestriction(String path,
        ComparableQueryStructure queryStructure, IComponentDescriptor<?> componentDescriptor,
        IQueryComponent queryComponent, Map<String, Object> context) {
    Junction queryStructureRestriction = null;
    if (queryStructure.isRestricting()) {
        queryStructureRestriction = Restrictions.conjunction();
        String comparator = queryStructure.getComparator();
        Object infValue = queryStructure.getInfValue();
        Object supValue = queryStructure.getSupValue();
        Object compareValue = infValue;
        if (compareValue == null) {
            compareValue = supValue;
        }
        switch (comparator) {
        case ComparableQueryStructureDescriptor.EQ:
            queryStructureRestriction.add(Restrictions.eq(path, compareValue));
            break;
        case ComparableQueryStructureDescriptor.GT:
            queryStructureRestriction.add(Restrictions.gt(path, compareValue));
            break;
        case ComparableQueryStructureDescriptor.GE:
            queryStructureRestriction.add(Restrictions.ge(path, compareValue));
            break;
        case ComparableQueryStructureDescriptor.LT:
            queryStructureRestriction.add(Restrictions.lt(path, compareValue));
            break;
        case ComparableQueryStructureDescriptor.LE:
            queryStructureRestriction.add(Restrictions.le(path, compareValue));
            break;
        case ComparableQueryStructureDescriptor.NU:
            queryStructureRestriction.add(Restrictions.isNull(path));
            break;
        case ComparableQueryStructureDescriptor.NN:
            queryStructureRestriction.add(Restrictions.isNotNull(path));
            break;
        case ComparableQueryStructureDescriptor.BE:
            if (infValue != null && supValue != null) {
                queryStructureRestriction.add(Restrictions.between(path, infValue, supValue));
            } else if (infValue != null) {
                queryStructureRestriction.add(Restrictions.ge(path, infValue));
            } else {
                queryStructureRestriction.add(Restrictions.le(path, supValue));
            }
            break;
        default:
            break;
        }
    }
    return queryStructureRestriction;
}

From source file:org.kaaproject.kaa.server.common.dao.impl.sql.HibernateHistoryDao.java

License:Apache License

@Override
public List<History> findBySeqNumberStart(String appId, int startSeqNum) {
    List<History> histories = Collections.emptyList();
    LOG.debug("Searching history by application id [{}] start sequence number [{}]", appId, startSeqNum);
    if (isNotBlank(appId)) {
        histories = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
                Restrictions.and(Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
                        Restrictions.gt(SEQUENCE_NUMBER_PROPERTY, startSeqNum)));
    }/* w  w  w  . j  a  va2s.c o m*/

    if (LOG.isTraceEnabled()) {
        LOG.trace("[{},{}] Search result: {}.", appId, startSeqNum, Arrays.toString(histories.toArray()));
    } else {
        LOG.debug("[{},{}] Search result: {}.", appId, startSeqNum, histories.size());
    }
    return histories;
}

From source file:org.kaaproject.kaa.server.common.dao.impl.sql.HibernateHistoryDao.java

License:Apache License

@Override
public List<History> findBySeqNumberRange(String appId, int startSeqNum, int endSeqNum) {
    List<History> histories = Collections.emptyList();
    LOG.debug("Searching history by application id {} start sequence number {} and end {}", appId, startSeqNum,
            endSeqNum);//from w  w w. j  av a  2s .  c  o  m
    if (isNotBlank(appId)) {
        histories = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
                Restrictions.and(Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
                        Restrictions.gt(SEQUENCE_NUMBER_PROPERTY, startSeqNum),
                        Restrictions.le(SEQUENCE_NUMBER_PROPERTY, endSeqNum)));
    }

    if (LOG.isTraceEnabled()) {
        LOG.trace("[{},{},{}] Search result: {}.", appId, startSeqNum, endSeqNum,
                Arrays.toString(histories.toArray()));
    } else {
        LOG.debug("[{},{},{}] Search result: {}.", appId, startSeqNum, endSeqNum, histories.size());
    }
    return histories;
}

From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.GridCQLToDetachedCriteria.java

License:Open Source License

private Criterion processAttribute(Attribute att, String parentAlias) {
    String attName = null;/*from   w  w w.  j  a va2s  . c  o  m*/

    if (prefixCastorUnderscore) {
        attName = addCastorUnderscore(att.getName());
    } else {
        attName = att.getName();
    }

    String name = parentAlias + "." + attName;
    String value = att.getValue();
    Criterion restriction = null;

    Predicate attPredicate = att.getPredicate();

    if (attPredicate.equals(Predicate.EQUAL_TO)) {
        restriction = Restrictions.eq(name, value);
    }
    if (attPredicate.equals(Predicate.LIKE)) {
        restriction = Restrictions.like(name, value);
    }
    if (attPredicate.equals(Predicate.GREATER_THAN)) {
        restriction = Restrictions.gt(name, value);
    }
    if (attPredicate.equals(Predicate.GREATER_THAN_EQUAL_TO)) {
        restriction = Restrictions.ge(name, value);
    }
    if (attPredicate.equals(Predicate.LESS_THAN)) {
        restriction = Restrictions.lt(name, value);
    }
    if (attPredicate.equals(Predicate.LESS_THAN_EQUAL_TO)) {
        restriction = Restrictions.le(name, value);
    }
    if (attPredicate.equals(Predicate.IS_NULL)) {
        restriction = Restrictions.isNull(name);
    }
    if (attPredicate.equals(Predicate.IS_NOT_NULL)) {
        restriction = Restrictions.isNotNull(name);
    }
    if (attPredicate.equals(Predicate.NOT_EQUAL_TO)) {
        restriction = Restrictions.ne(name, value);
    }
    return restriction;
}