KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: IdentifierProjection.java,v 1.1 2005/05/31 20:24:39 oneovthafew Exp $
2
package org.hibernate.criterion;
3
4 import org.hibernate.Criteria;
5 import org.hibernate.HibernateException;
6 import org.hibernate.type.Type;
7 import org.hibernate.util.StringHelper;
8
9 /**
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 JavaDoc toString() {
26         return "id";
27     }
28
29     public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
30     throws HibernateException {
31         return new Type[] { criteriaQuery.getIdentifierType(criteria) };
32     }
33
34     public String JavaDoc toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
35     throws HibernateException {
36         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
37         String JavaDoc[] cols = criteriaQuery.getIdentifierColumns(criteria);
38         for ( int i=0; i<cols.length; i++ ) {
39             buf.append( cols[i] )
40                 .append(" as y")
41                 .append(position + i)
42                 .append('_');
43         }
44         return buf.toString();
45     }
46
47     public boolean isGrouped() {
48         return grouped;
49     }
50     
51     public String JavaDoc toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
52     throws HibernateException {
53         if (!grouped) {
54             return super.toGroupSqlString(criteria, criteriaQuery);
55         }
56         else {
57             return StringHelper.join( ", ", criteriaQuery.getIdentifierColumns(criteria) );
58         }
59     }
60
61 }
62
Popular Tags