1 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 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, CriteriaQuery criteriaQuery) 30 throws HibernateException { 31 return new Type[] { criteriaQuery.getIdentifierType(criteria) }; 32 } 33 34 public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) 35 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] ) 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 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 |