01: //$Id: PropertyProjection.java 5685 2005-02-12 07:19:50Z steveebersole $
02: package org.hibernate.criterion;
03:
04: import org.hibernate.Criteria;
05: import org.hibernate.HibernateException;
06: import org.hibernate.type.Type;
07:
08: /**
09: * A property value, or grouped property value
10: * @author Gavin King
11: */
12: public class PropertyProjection extends SimpleProjection {
13:
14: private String propertyName;
15: private boolean grouped;
16:
17: protected PropertyProjection(String prop, boolean grouped) {
18: this .propertyName = prop;
19: this .grouped = grouped;
20: }
21:
22: protected PropertyProjection(String prop) {
23: this (prop, false);
24: }
25:
26: public String getPropertyName() {
27: return propertyName;
28: }
29:
30: public String toString() {
31: return propertyName;
32: }
33:
34: public Type[] getTypes(Criteria criteria,
35: CriteriaQuery criteriaQuery) throws HibernateException {
36: return new Type[] { criteriaQuery.getType(criteria,
37: propertyName) };
38: }
39:
40: public String toSqlString(Criteria criteria, int position,
41: CriteriaQuery criteriaQuery) throws HibernateException {
42: return new StringBuffer().append(
43: criteriaQuery.getColumn(criteria, propertyName))
44: .append(" as y").append(position).append('_')
45: .toString();
46: }
47:
48: public boolean isGrouped() {
49: return grouped;
50: }
51:
52: public String toGroupSqlString(Criteria criteria,
53: CriteriaQuery criteriaQuery) throws HibernateException {
54: if (!grouped) {
55: return super.toGroupSqlString(criteria, criteriaQuery);
56: } else {
57: return criteriaQuery.getColumn(criteria, propertyName);
58: }
59: }
60:
61: }
|