List of usage examples for org.hibernate.criterion Restrictions lt
public static SimpleExpression lt(String propertyName, Object value)
From source file:org.apache.usergrid.apm.service.charts.filter.SmallerThanFilter.java
License:Apache License
public Criterion getCriteria() { if (getFilterEmpty()) return null; return Restrictions.lt(propertyName, propertyValue); }
From source file:org.balisunrise.daa.hibernate.HCriteria.java
License:Open Source License
private org.hibernate.criterion.Criterion makeCriterion(String propertyName, FilterType type, Object value, Object otherValue) {/* ww w . j av a2 s. c o m*/ switch (type) { case EQUALS: return Restrictions.eq(propertyName, value); case EQUALS_OR_NULL: return Restrictions.eqOrIsNull(propertyName, value); case DIFFERENT: return Restrictions.ne(propertyName, value); case DIFFERENT_OR_NOT_NULL: return Restrictions.neOrIsNotNull(propertyName, value); case GREATHER: return Restrictions.gt(propertyName, value); case GREATHER_EQUALS: return Restrictions.ge(propertyName, value); case LESS: return Restrictions.lt(propertyName, value); case LESS_EQUALS: return Restrictions.le(propertyName, value); case LIKE: return Restrictions.like(propertyName, value + "%"); case ILIKE: return Restrictions.ilike(propertyName, "%" + value + "%"); case BETWEEN: return Restrictions.between(propertyName, value, otherValue); case IN: if (value instanceof Collection) return Restrictions.in(propertyName, (Collection) value); else if (value instanceof Object[]) return Restrictions.in(propertyName, (Object[]) value); else return Restrictions.in(propertyName, new Object[] { value }); case NULL: return Restrictions.isNull(propertyName); case NOT_NULL: return Restrictions.isNotNull(propertyName); default: return null; } }
From source file:org.broadleafcommerce.core.offer.dao.OfferDaoImpl.java
License:Apache License
@Override public List<Offer> readOffersByAutomaticDeliveryType() { //TODO change this to a JPA criteria Criteria criteria = ((HibernateEntityManager) em).getSession().createCriteria(OfferImpl.class); Date myDate = getCurrentDateAfterFactoringInDateResolution(); Calendar c = Calendar.getInstance(); c.setTime(myDate);//from w w w.j a v a 2 s.c om c.add(Calendar.DATE, +1); criteria.add(Restrictions.lt("startDate", c.getTime())); c = Calendar.getInstance(); c.setTime(myDate); c.add(Calendar.DATE, -1); criteria.add(Restrictions.or(Restrictions.isNull("endDate"), Restrictions.gt("endDate", c.getTime()))); criteria.add(Restrictions.or(Restrictions.eq("archiveStatus.archived", 'N'), Restrictions.isNull("archiveStatus.archived"))); // Automatically Added or (Automatically Added is null and deliveryType is Automatic) criteria.add(Restrictions.or(Restrictions.eq("automaticallyAdded", true), Restrictions .and(Restrictions.isNull("automaticallyAdded"), Restrictions.eq("deliveryType", "AUTOMATIC")))); criteria.setCacheable(true); criteria.setCacheRegion("query.Offer"); return criteria.list(); }
From source file:org.candlepin.gutterball.curator.ComplianceSnapshotCurator.java
License:Open Source License
/** * Retrieves an iterator over the compliance snapshots for the specified consumer. * * @param consumerUUID/*from w w w . ja v a2 s .co m*/ * The UUID for the consumer for which to retrieve compliance snapshots. * * @param startDate * The start date to use to filter snapshots retrieved. If specified, only snapshots occurring * after the start date, and the snapshot immediately preceding it, will be retrieved. * * @param endDate * The end date to use to filter snapshots retrieved. If specified, only snapshots occurring * before the end date will be retrieved. * * @param pageRequest * A PageRequest instance containing paging information from the request. If null, no paging * will be performed. * * @return * A Page instance containing an iterator over the snapshots for the specified consumer, and * the paging information for the query. */ @SuppressWarnings("checkstyle:indentation") public Page<Iterator<Compliance>> getSnapshotIteratorForConsumer(String consumerUUID, Date startDate, Date endDate, PageRequest pageRequest) { Page<Iterator<Compliance>> page = new Page<Iterator<Compliance>>(); page.setPageRequest(pageRequest); Session session = this.currentSession(); Criteria query = session.createCriteria(Compliance.class, "comp1"); query.createAlias("comp1.consumer", "cons1"); query.add(Restrictions.eq("cons1.uuid", consumerUUID)); if (startDate != null) { DetachedCriteria subquery = DetachedCriteria.forClass(Compliance.class, "comp2"); subquery.createAlias("comp2.consumer", "cons2"); subquery.createAlias("cons2.consumerState", "state2"); subquery.add(Restrictions.or(Restrictions.isNull("state2.deleted"), Restrictions.gt("state2.deleted", startDate))); subquery.add(Restrictions.lt("state2.created", startDate)); subquery.add(Restrictions.eqProperty("cons2.uuid", "cons1.uuid")); subquery.add(Restrictions.lt("comp2.date", startDate)); subquery.setProjection(Projections.projectionList().add(Projections.max("comp2.date"))); query.add(Restrictions.disjunction().add(Restrictions.ge("comp1.date", startDate)) .add(Subqueries.propertyEq("comp1.date", subquery))); } if (endDate != null) { query.add(Restrictions.le("comp1.date", endDate)); } query.setCacheMode(CacheMode.IGNORE); query.setReadOnly(true); if (pageRequest != null && pageRequest.isPaging()) { page.setMaxRecords(this.getRowCount(query)); query.setFirstResult((pageRequest.getPage() - 1) * pageRequest.getPerPage()); query.setMaxResults(pageRequest.getPerPage()); if (pageRequest.getSortBy() != null) { query.addOrder( pageRequest.getOrder() == PageRequest.Order.ASCENDING ? Order.asc(pageRequest.getSortBy()) : Order.desc(pageRequest.getSortBy())); } } page.setPageData(new AutoEvictingColumnarResultsIterator<Compliance>(session, query.scroll(ScrollMode.FORWARD_ONLY), 0)); return page; }
From source file:org.candlepin.model.PoolCurator.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Pool> listExpiredPools() { Date today = new Date(); Criteria crit = createSecureCriteria().add(Restrictions.lt("endDate", today)); List<Pool> results = crit.list(); if (results == null) { results = new LinkedList<Pool>(); }// www . ja v a 2s . c om return results; }
From source file:org.caratarse.auth.model.util.CriteriaFilterHelper.java
License:Apache License
public static void addQueryFilter(final DetachedCriteria crit, QueryFilter filter) { if (filter == null) { return;// w w w. java 2 s. com } filter.iterate(new FilterCallback() { @Override public void filterOn(FilterComponent c) { switch (c.getOperator()) { case CONTAINS: // String-related crit.add(Restrictions.ilike(c.getField(), c.getValue().toString(), MatchMode.ANYWHERE)); break; case STARTS_WITH: // String-related crit.add(Restrictions.ilike(c.getField(), c.getValue().toString(), MatchMode.START)); break; case GREATER_THAN: crit.add(Restrictions.gt(c.getField(), c.getValue())); break; case GREATER_THAN_OR_EQUAL_TO: crit.add(Restrictions.ge(c.getField(), c.getValue())); break; case LESS_THAN: crit.add(Restrictions.lt(c.getField(), c.getValue())); break; case LESS_THAN_OR_EQUAL_TO: crit.add(Restrictions.le(c.getField(), c.getValue())); break; case NOT_EQUALS: crit.add(Restrictions.ne(c.getField(), c.getValue())); break; case EQUALS: default: crit.add(Restrictions.eq(c.getField(), c.getValue())); break; } } }); }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriterionAdapter.java
License:Apache License
protected void addSimplePropertyCriterionAdapters() { criterionAdaptors.put(Query.IdEquals.class, new CriterionAdaptor() { @Override/*www . ja va 2 s. c o m*/ public org.hibernate.criterion.Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.Criterion criterion, String alias) { return Restrictions.idEq(((Query.IdEquals) criterion).getValue()); } }); criterionAdaptors.put(Query.Equals.class, new CriterionAdaptor<Query.Equals>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.Equals criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).eq((DetachedCriteria) value); } return Restrictions.eq(propertyName, value); } }); criterionAdaptors.put(Query.NotEquals.class, new CriterionAdaptor<Query.NotEquals>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.NotEquals criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).ne((DetachedCriteria) value); } return Restrictions.ne(propertyName, value); } }); criterionAdaptors.put(Query.GreaterThan.class, new CriterionAdaptor<Query.GreaterThan>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.GreaterThan criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).gt((DetachedCriteria) value); } return Restrictions.gt(propertyName, value); } }); criterionAdaptors.put(Query.GreaterThanEquals.class, new CriterionAdaptor<Query.GreaterThanEquals>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.GreaterThanEquals criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).ge((DetachedCriteria) value); } return Restrictions.ge(propertyName, value); } }); criterionAdaptors.put(Query.LessThan.class, new CriterionAdaptor<Query.LessThan>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.LessThan criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).lt((DetachedCriteria) value); } return Restrictions.lt(propertyName, value); } }); criterionAdaptors.put(Query.LessThanEquals.class, new CriterionAdaptor<Query.LessThanEquals>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.LessThanEquals criterion, String alias) { String propertyName = getPropertyName(criterion, alias); Object value = criterion.getValue(); if (value instanceof DetachedCriteria) { return Property.forName(propertyName).le((DetachedCriteria) value); } return Restrictions.le(propertyName, value); } }); }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateQuery.java
License:Apache License
@Override public Query lt(String property, Object value) { addToCriteria(Restrictions.lt(calculatePropertyName(property), value)); return this; }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.HibernateQuery.java
License:Apache License
@Override public Query lt(String property, Object value) { criteria.add(Restrictions.lt(property, value)); return this; }
From source file:org.dspace.checker.dao.impl.MostRecentChecksumDAOImpl.java
License:BSD License
@Override public MostRecentChecksum getOldestRecord(Context context, Date lessThanDate) throws SQLException { // "select bitstream_id " // + "from most_recent_checksum " // + "where to_be_processed = true " // + "and last_process_start_date < ? " // + "order by date_trunc('milliseconds', last_process_end_date), " // + "bitstream_id " + "ASC LIMIT 1"; Criteria criteria = createCriteria(context, MostRecentChecksum.class); criteria.add(Restrictions.and(Restrictions.eq("toBeProcessed", true), Restrictions.lt("processStartDate", lessThanDate))); criteria.addOrder(Order.asc("processEndDate")).addOrder(Order.asc("bitstream.id")); criteria.setMaxResults(1);// w w w . j a va2 s. co m return singleResult(criteria); }