KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: PropertyExpression.java,v 1.10 2005/02/12 07:19:14 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  * superclass for comparisons between two properties (with SQL binary operators)
12  * @author Gavin King
13  */

14 public class PropertyExpression implements Criterion {
15
16     private final String JavaDoc propertyName;
17     private final String JavaDoc otherPropertyName;
18     private final String JavaDoc op;
19
20     private static final TypedValue[] NO_TYPED_VALUES = new TypedValue[0];
21
22     protected PropertyExpression(String JavaDoc propertyName, String JavaDoc otherPropertyName, String JavaDoc op) {
23         this.propertyName = propertyName;
24         this.otherPropertyName = otherPropertyName;
25         this.op = op;
26     }
27
28     public String JavaDoc toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
29     throws HibernateException {
30         String JavaDoc[] xcols = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);
31         String JavaDoc[] ycols = criteriaQuery.getColumnsUsingProjection(criteria, otherPropertyName);
32         String JavaDoc result = StringHelper.join(
33             " and ",
34             StringHelper.add(xcols, getOp(), ycols)
35         );
36         if (xcols.length>1) result = '(' + result + ')';
37         return result;
38         //TODO: get SQL rendering out of this package!
39
}
40
41     public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
42     throws HibernateException {
43         return NO_TYPED_VALUES;
44     }
45
46     public String JavaDoc toString() {
47         return propertyName + getOp() + otherPropertyName;
48     }
49
50     public String JavaDoc getOp() {
51         return op;
52     }
53
54 }
55
Popular Tags