1 package org.hibernate.criterion; 3 4 5 import org.hibernate.Criteria; 6 import org.hibernate.HibernateException; 7 import org.hibernate.engine.TypedValue; 8 import org.hibernate.util.StringHelper; 9 10 14 public class BetweenExpression implements Criterion { 15 16 private final String propertyName; 17 private final Object lo; 18 private final Object hi; 19 20 protected BetweenExpression(String propertyName, Object lo, Object hi) { 21 this.propertyName = propertyName; 22 this.lo = lo; 23 this.hi = hi; 24 } 25 26 public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) 27 throws HibernateException { 28 return StringHelper.join( 29 " and ", 30 StringHelper.suffix( criteriaQuery.getColumnsUsingProjection(criteria, propertyName), " between ? and ?" ) 31 ); 32 33 } 35 36 public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 37 throws HibernateException { 38 return new TypedValue[] { 39 criteriaQuery.getTypedValue(criteria, propertyName, lo), 40 criteriaQuery.getTypedValue(criteria, propertyName, hi) 41 }; 42 } 43 44 public String toString() { 45 return propertyName + " between " + lo + " and " + hi; 46 } 47 48 } 49 | Popular Tags |