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:net.longfalcon.newsj.persistence.hibernate.ReleaseDAOImpl.java

License:Open Source License

@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<Release> findReleasesBeforeDate(Date before) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Release.class);
    criteria.add(Restrictions.lt("postDate", before));
    criteria.setFetchMode("category", FetchMode.JOIN);

    return criteria.list();
}

From source file:net.longfalcon.newsj.persistence.hibernate.ReleaseNfoDAOImpl.java

License:Open Source License

@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<ReleaseNfo> findReleaseNfoWithNullNfoByAttempts(int attempts) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ReleaseNfo.class);
    criteria.add(Restrictions.isNull("nfo"));
    criteria.add(Restrictions.lt("attemtps", attempts));

    return criteria.list();
}

From source file:net.longfalcon.newsj.persistence.hibernate.ReleaseRegexDAOImpl.java

License:Open Source License

@Override
@Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED, propagation = Propagation.SUPPORTS)
public List<ReleaseRegex> getRegexes(boolean activeOnly, String groupName, boolean userReleaseRegexes) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ReleaseRegex.class);

    if (activeOnly) {
        criteria.add(Restrictions.eq("status", 1));
    }//ww  w .j  a  v a  2 s . c  o  m
    if (!ValidatorUtil.isNull(groupName)) {
        if (groupName.equals("all")) {
            criteria.add(Restrictions.isNull("groupName"));
        } else if (!groupName.equals("-1")) {
            criteria.add(Restrictions.eq("groupName", groupName));
        }
    }

    if (!userReleaseRegexes) {
        criteria.add(Restrictions.lt("id", 100000L));
    }

    // rough approximation of original order by:
    // " order by (rr.groupName like '%*') asc , coalesce(rr.groupName, 'zzz') desc , rr.ordinal asc"
    criteria.addOrder(Order.desc("groupName").nulls(NullPrecedence.FIRST));
    criteria.addOrder(Order.asc("ordinal"));
    return criteria.list();
}

From source file:net.umpay.mailbill.hql.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,./*from w  w w.  j a  v a 2 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:nl.surfnet.coin.teams.service.impl.TeamInviteServiceHibernateImpl.java

License:Apache License

/**
 * {@inheritDoc}//from   www .  java2s .  c  o  m
 */
@Override
public void cleanupExpiredInvitations() {
    long thirtyDaysAgo = (new Date().getTime()) - THIRTY_DAYS;
    List<Invitation> invitations = findByCriteria(Restrictions.lt("timestamp", thirtyDaysAgo));
    for (Invitation invitation : invitations) {
        delete(invitation);
    }
}

From source file:ome.services.search.SearchAction.java

License:Open Source License

private void createdOrModified(Class cls, Criteria criteria, QueryBuilder qb, String path) {

    if (!IGlobal.class.isAssignableFrom(cls)) {

        if (criteria != null) {
            criteria.createAlias("details.creationEvent", "create");
        }//w w w.j  a  v a2 s.  c  o m

        if (values.createdStart != null) {
            if (criteria != null) {
                criteria.add(Restrictions.gt("create.time", values.createdStart));
            }
            if (qb != null) {
                String ctime = qb.unique_alias("ctimestart");
                qb.and(path + "details.creationEvent.time > :" + ctime);
                qb.param(ctime, values.createdStart);
            }
        }

        if (values.createdStop != null) {
            if (criteria != null) {
                criteria.add(Restrictions.lt("create.time", values.createdStop));
            }
            if (qb != null) {
                String ctime = qb.unique_alias("ctimestop");
                qb.and(path + "details.creationEvent.time < :" + ctime);
                qb.param(ctime, values.createdStop);
            }
        }

        if (IMutable.class.isAssignableFrom(cls)) {

            if (criteria != null) {
                criteria.createAlias("details.updateEvent", "update");
            }

            if (values.modifiedStart != null) {
                if (criteria != null) {
                    criteria.add(Restrictions.gt("update.time", values.modifiedStart));
                }

                if (qb != null) {
                    String mtime = qb.unique_alias("mtimestart");
                    qb.and(path + "details.updateEvent.time > :" + mtime);
                    qb.param(mtime, values.modifiedStart);
                }
            }

            if (values.modifiedStop != null) {
                if (criteria != null) {
                    criteria.add(Restrictions.lt("update.time", values.modifiedStop));
                }

                if (qb != null) {
                    String mtime = qb.unique_alias("mtimestart");
                    qb.and(path + "details.updateEvent.time < :" + mtime);
                    qb.param(mtime, values.modifiedStop);
                }
            }
        }
    }
}

From source file:ome.services.search.SearchAction.java

License:Open Source License

private void annotatedBetween(AnnotationCriteria ann, QueryBuilder qb, String path) {
    if (values.annotatedStart != null) {
        if (ann != null) {
            ann.getCreate().add(Restrictions.gt("anncreate.time", values.annotatedStart));
        }/*from  ww w .  j a v a 2s. co m*/

        if (qb != null) {
            String astart = qb.unique_alias("astart");
            qb.and(path + "details.creationEvent.time > :" + astart);
            qb.param(astart, values.annotatedStart);
        }
    }

    if (values.annotatedStop != null) {
        if (ann != null) {
            ann.getCreate().add(Restrictions.lt("anncreate.time", values.annotatedStop));
        }

        if (qb != null) {
            String astop = qb.unique_alias("astop");
            qb.and(path + "details.creationEvent.time < :" + astop);
            qb.param(astop, values.annotatedStop);
        }
    }
}

From source file:org.apache.ode.daohib.bpel.CriteriaBuilder.java

License:Apache License

static void addFilterOnPrefixedDate(Criteria crit, String op, Date date, String dateAttribute) {
    if (op.startsWith("=")) {
        crit.add(Restrictions.eq(dateAttribute, date));
    } else if (op.startsWith("<=")) {
        crit.add(Restrictions.le(dateAttribute, date));
    } else if (op.startsWith(">=")) {
        crit.add(Restrictions.ge(dateAttribute, date));
    } else if (op.startsWith("<")) {
        crit.add(Restrictions.lt(dateAttribute, date));
    } else if (op.startsWith(">")) {
        crit.add(Restrictions.gt(dateAttribute, date));
    }/*from www .  j  a  v a 2  s . c  o  m*/
}

From source file:org.apache.ode.daohib.bpel.ql.HibernateInstancesQueryCompiler.java

License:Apache License

protected LessEvaluator<String, Criterion, Object> compileLess(final Less less) {
    if (less.getIdentifier() instanceof Property) {
        propertyInQuery = true;/*from  w w w.  jav a 2  s  .c  o m*/
        final Property property = (Property) less.getIdentifier();
        return new LessEvaluator<String, Criterion, Object>() {
            public Criterion evaluate(Object paramValue) {
                Conjunction conj = Restrictions.conjunction();
                if (!StringUtils.isEmpty(property.getNamespace())) {
                    conj.add(Restrictions.lt(PROPERTY_NS_DB_FIELD, property.getNamespace()));
                }
                conj.add(Restrictions.lt(PROPERTY_NAME_DB_FIELD, property.getName()));
                conj.add(Restrictions.lt(PROPERTY_VALUE_DB_FIELD, less.getValue().getValue()));

                return conj;
            };

            public String getIdentifier() {
                return property.toString();
            };
        };
    } else {
        final String fieldName = less.getIdentifier().getName();
        final Object value = less.getValue().getValue();

        if (INSTANCE_STATUS_FIELD.equals(fieldName)) {
            throw new IllegalArgumentException("Field " + INSTANCE_STATUS_FIELD + " is not supported.");
        }

        final String dbField = getDBField(fieldName);

        return new LessEvaluator<String, Criterion, Object>() {
            public Criterion evaluate(Object paramValue) {
                return Restrictions.lt(dbField, value);
            }

            public String getIdentifier() {
                return fieldName;
            }
        };
    }
}

From source file:org.apache.usergrid.apm.service.charts.filter.DateIntervalFilter.java

License:Apache License

/** 
 * Prepare criteria according to filter values. Ideally when both from and to are present, it should result into two criterion
 * startTime >= from and endTime <= to but given that delta between startTime and endTime is not huge and we don't have to be 
 * precise upto few minutes, selecting startTime between from and to should work. It should also help with faster query as well.
 * @return/*from w  ww  .j ava 2 s.c  o m*/
 */
public Criterion getCriteria() {

    if (getFilterEmpty())
        return null;

    if (from != null && to != null)
        return Restrictions.between(startTime, from, to);

    Criterion crit = null;
    if (from != null)
        crit = Restrictions.gt(startTime, from);
    else
        crit = Restrictions.lt(endTime, to);

    return crit;
}