/** * Creates a BETWEEN restriction for this property between the given min and max * * @param min The minimum * @param max The maximum * * @return The BETWEEN restriction * * @see Restrictions#between(String, Object, Object) */ public Criterion between(Object min, Object max) { return Restrictions.between( getPropertyName(), min, max ); }
private void loadModificationsForPMR(List<PipelineMaterialRevision> pmrs) { List<Criterion> criterions = new ArrayList<>(); for (PipelineMaterialRevision pmr : pmrs) { if (goCache.get(pmrModificationsKey(pmr)) != null) { continue; } final Criterion modificationClause = Restrictions.between("id", pmr.getFromModification().getId(), pmr.getToModification().getId()); final SimpleExpression idClause = Restrictions.eq("materialInstance", pmr.getMaterialInstance()); criterions.add(Restrictions.and(idClause, modificationClause)); } List<Modification> modifications = (List<Modification>) getHibernateTemplate().findByCriteria(buildModificationDetachedQuery(criterions)); sortPersistentObjectsById(modifications, false); for (Modification modification : modifications) { List<String> cacheKeys = pmrModificationsKey(modification, pmrs); for (String cacheKey : cacheKeys) { List<Modification> modificationList = (List<Modification>) goCache.get(cacheKey); if (modificationList == null) { modificationList = new ArrayList<>(); goCache.put(cacheKey, modificationList); } modificationList.add(modification); } } }
.add(Restrictions.between("person.heightInches", HEIGHT_INCHES - 0.01d, HEIGHT_INCHES + 0.01d)) .uniqueResult(); assertEquals(HEIGHT_INCHES, u.getPerson().getHeightInches(), 0.01d);
.add(Restrictions.between("heightInches", HUMAN_INCHES - 0.01d, HUMAN_INCHES + 0.01d)) .uniqueResult(); assertEquals(HUMAN_INCHES, b.getHeightInches(), 0.01d);
.add( Restrictions.between("sizeInInches", HEIGHT_INCHES - 0.01d, HEIGHT_INCHES + 0.01d)) .uniqueResult(); assertEquals(HEIGHT_INCHES, staff.getSizeInInches(), 0.01d);
.add(Restrictions.between("heightInches", HEIGHT_INCHES - 0.01d, HEIGHT_INCHES + 0.01d)) .uniqueResult(); assertEquals(HEIGHT_INCHES, p.getHeightInches(), 0.01d); u = (User)s.createCriteria(User.class) .add(Restrictions.between("passwordExpiryDays", PASSWORD_EXPIRY_DAYS - 0.01d, PASSWORD_EXPIRY_DAYS + 0.01d)) .uniqueResult(); assertEquals(PASSWORD_EXPIRY_DAYS, u.getPasswordExpiryDays(), 0.01d);
.add(Restrictions.between("heightInches", HEIGHT_INCHES - 0.01d, HEIGHT_INCHES + 0.01d)) .uniqueResult(); assertEquals(HEIGHT_INCHES, p.getHeightInches(), 0.01d); e = (Employee)s.createCriteria(Employee.class) .add(Restrictions.between("passwordExpiryDays", PASSWORD_EXPIRY_DAYS - 0.01d, PASSWORD_EXPIRY_DAYS + 0.01d)) .uniqueResult(); assertEquals(PASSWORD_EXPIRY_DAYS, e.getPasswordExpiryDays(), 0.01d);
.add(Restrictions.between("heightInches", HEIGHT_INCHES - 0.01d, HEIGHT_INCHES + 0.01d)) .uniqueResult(); assertEquals(HEIGHT_INCHES, p.getHeightInches(), 0.01d); e = (Employee)s.createCriteria(Employee.class) .add(Restrictions.between("passwordExpiryDays", PASSWORD_EXPIRY_DAYS - 0.01d, PASSWORD_EXPIRY_DAYS + 0.01d)) .uniqueResult(); assertEquals(PASSWORD_EXPIRY_DAYS, e.getPasswordExpiryDays(), 0.01d);
@Override public DetachedCriteria getCriteria(DetachedCriteria criteria, String key, Object value) throws QueryException { List values=(List) value; if(values.size()==2){ if(values.get(0)==null){ if(values.get(1)!=null) criteria.add(Restrictions.le(key,values.get(1))); }else if(values.get(1)==null){ criteria.add(Restrictions.ge(key,values.get(0))); }else{ criteria.add(Restrictions.between(key,values.get(0),values.get(1))); } } return criteria; } };
@SuppressWarnings("unchecked") public List<ScheduledMessage> getScheduledMessages(Date startDate, Date endDate) { Session session = sessionFactory.getCurrentSession(); return (List<ScheduledMessage>) session.createCriteria( ScheduledMessage.class).add( Restrictions.between("scheduledFor", startDate, endDate)) .list(); }
private void onlyYearAndMonthAndDay(String value, Criteria criteria) { try { DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date startDate = format.parse(value); DateTime dt = new DateTime(startDate.getTime()); dt = dt.plusDays(1); Date endDate = dt.toDate(); criteria.add(Restrictions.between("loginAttemptDate", startDate, endDate)); } catch (Exception e) { // Do nothing } }
@Override public Criterion getHibernateCriterion( QueryPath queryPath ) { return Restrictions.between( queryPath.getPath(), args.get( 0 ), args.get( 1 ) ); }
private void onlyYear(String value, Criteria criteria) { try { DateFormat format = new SimpleDateFormat("yyyy"); Date startDate = format.parse(value); DateTime dt = new DateTime(startDate.getTime()); dt = dt.plusYears(1); Date endDate = dt.toDate(); criteria.add(Restrictions.between("loginAttemptDate", startDate, endDate)); } catch (Exception e) { // Do nothing } }
private void onlyYearAndMonthAndDayAndHourAndMinute(String value, Criteria criteria) { try { DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date startDate = format.parse(value); DateTime dt = new DateTime(startDate.getTime()); dt = dt.plusMinutes(1); Date endDate = dt.toDate(); criteria.add(Restrictions.between("loginAttemptDate", startDate, endDate)); } catch (Exception e) { // Do nothing } }
public Criteria addTimespanTo(Criteria criteria) { if (parameters.getTimespan() != null) { Interval interval = parameters.getTimespan().toInterval(); Date start = interval.getStart().toDate(); Date end = interval.getEnd().toDate(); criteria.add(Restrictions.or( // check overlap between(COLUMN_TIMESTART, start, end), between(COLUMN_TIMEEND, start, end) )); } return criteria; }
@Override public Query between(String property, Object start, Object end) { addToCriteria(Restrictions.between(calculatePropertyName(property), start, end)); return this; }
@Override public Query between(String property, Object start, Object end) { addToCriteria(Restrictions.between(calculatePropertyName(property), start, end)); return this; }
@Override public Query between(String property, Object start, Object end) { addToCriteria(Restrictions.between(calculatePropertyName(property), start, end)); return this; }
@Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.Criterion criterion, String alias) { Query.Between btwCriterion = (Query.Between) criterion; return Restrictions.between(calculatePropertyName(calculatePropertyName(btwCriterion.getProperty(), alias), alias), btwCriterion.getFrom(), btwCriterion.getTo()); } });
/** {@inheritDoc} */ @Override public Object visit(PropertyIsBetween filter, Object userData) { String propertyName = getPropertyName(filter.getExpression()); String finalName = parsePropertyName(propertyName, userData); Object lo = castLiteral(getLiteralValue(filter.getLowerBoundary()), propertyName); Object hi = castLiteral(getLiteralValue(filter.getUpperBoundary()), propertyName); return Restrictions.between(finalName, lo, hi); }