KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > criterion > BetweenExpression


1 //$Id: BetweenExpression.java,v 1.8 2005/02/12 07:19:13 steveebersole Exp $
2
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 /**
11  * Constrains a property to between two values
12  * @author Gavin King
13  */

14 public class BetweenExpression implements Criterion {
15
16     private final String JavaDoc propertyName;
17     private final Object JavaDoc lo;
18     private final Object JavaDoc hi;
19
20     protected BetweenExpression(String JavaDoc propertyName, Object JavaDoc lo, Object JavaDoc hi) {
21         this.propertyName = propertyName;
22         this.lo = lo;
23         this.hi = hi;
24     }
25
26     public String JavaDoc 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         //TODO: get SQL rendering out of this package!
34
}
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 JavaDoc toString() {
45         return propertyName + " between " + lo + " and " + hi;
46     }
47
48 }
49
Popular Tags