1 package org.hibernate.criterion; 3 4 import org.hibernate.Criteria; 5 import org.hibernate.HibernateException; 6 import org.hibernate.type.Type; 7 8 12 public class AggregateProjection extends SimpleProjection { 13 14 protected final String propertyName; 15 private final String aggregate; 16 17 protected AggregateProjection(String aggregate, String propertyName) { 18 this.aggregate = aggregate; 19 this.propertyName = propertyName; 20 } 21 22 public String 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 toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) 32 throws HibernateException { 33 return new StringBuffer () 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 |