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