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 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, CriteriaQuery criteriaQuery) 35 throws HibernateException { 36 return new Type[] { criteriaQuery.getType(criteria, propertyName) }; 37 } 38 39 public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) 40 throws HibernateException { 41 return new StringBuffer () 42 .append( criteriaQuery.getColumn(criteria, propertyName) ) 43 .append(" as y") 44 .append(position) 45 .append('_') 46 .toString(); 47 } 48 49 public boolean isGrouped() { 50 return grouped; 51 } 52 53 public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) 54 throws HibernateException { 55 if (!grouped) { 56 return super.toGroupSqlString(criteria, criteriaQuery); 57 } 58 else { 59 return criteriaQuery.getColumn(criteria, propertyName); 60 } 61 } 62 63 } 64 | Popular Tags |