KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: AggregateProjection.java,v 1.11 2005/02/12 07:19:13 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  * An aggregation
10  * @author max
11  */

12 public class AggregateProjection extends SimpleProjection {
13
14     protected final String JavaDoc propertyName;
15     private final String JavaDoc aggregate;
16     
17     protected AggregateProjection(String JavaDoc aggregate, String JavaDoc propertyName) {
18         this.aggregate = aggregate;
19         this.propertyName = propertyName;
20     }
21
22     public String JavaDoc toString() {
23         return aggregate + "(" + propertyName + ')';
24     }
25
26     public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
27     throws HibernateException {
28         return new Type[] { criteriaQuery.getType(criteria, propertyName) };
29     }
30
31     public String JavaDoc toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery)
32     throws HibernateException {
33         return new StringBuffer JavaDoc()
34             .append(aggregate)
35             .append("(")
36             .append( criteriaQuery.getColumn(criteria, propertyName) )
37             .append(") as y")
38             .append(loc)
39             .append('_')
40             .toString();
41     }
42
43 }
44
Popular Tags