KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: PropertyProjection.java,v 1.14 2005/02/12 07:19:14 steveebersole Exp $
2
package org.hibernate.criterion;
3
4 import org.hibernate.Criteria;
5 import org.hibernate.HibernateException;
6 import org.hibernate.type.Type;
7
8 /**
9  * A property value, or grouped property value
10  * @author Gavin King
11  */

12 public class PropertyProjection extends SimpleProjection {
13
14     private String JavaDoc propertyName;
15     private boolean grouped;
16     
17     protected PropertyProjection(String JavaDoc prop, boolean grouped) {
18         this.propertyName = prop;
19         this.grouped = grouped;
20     }
21     
22     protected PropertyProjection(String JavaDoc prop) {
23         this(prop, false);
24     }
25
26     public String JavaDoc getPropertyName() {
27         return propertyName;
28     }
29     
30     public String JavaDoc toString() {
31         return propertyName;
32     }
33
34     public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
35     throws HibernateException {
36         return new Type[] { criteriaQuery.getType(criteria, propertyName) };
37     }
38
39     public String JavaDoc toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
40     throws HibernateException {
41         return new StringBuffer JavaDoc()
42             .append( criteriaQuery.getColumn(criteria, propertyName) )
43             .append(" as y")
44             .append(position)
45             .append('_')
46             .toString();
47     }
48
49     public boolean isGrouped() {
50         return grouped;
51     }
52     
53     public String JavaDoc toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
54     throws HibernateException {
55         if (!grouped) {
56             return super.toGroupSqlString(criteria, criteriaQuery);
57         }
58         else {
59             return criteriaQuery.getColumn(criteria, propertyName);
60         }
61     }
62
63 }
64
Popular Tags