1 package org.hibernate.criterion; 3 4 5 import org.hibernate.Criteria; 6 import org.hibernate.HibernateException; 7 import org.hibernate.type.Type; 8 import org.hibernate.util.StringHelper; 9 10 14 public class SQLProjection implements Projection { 15 16 private final String sql; 17 private final String groupBy; 18 private final Type[] types; 19 private String [] aliases; 20 private String [] columnAliases; 21 private boolean grouped; 22 23 public String toSqlString( 24 Criteria criteria, 25 int loc, 26 CriteriaQuery criteriaQuery) 27 throws HibernateException { 28 return StringHelper.replace( sql, "{alias}", criteriaQuery.getSQLAlias(criteria) ); 29 } 30 31 public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) 32 throws HibernateException { 33 return StringHelper.replace( groupBy, "{alias}", criteriaQuery.getSQLAlias(criteria) ); 34 } 35 36 public Type[] getTypes(Criteria crit, CriteriaQuery criteriaQuery) 37 throws HibernateException { 38 return types; 39 } 40 41 public String toString() { 42 return sql; 43 } 44 45 protected SQLProjection(String sql, String [] columnAliases, Type[] types) { 46 this(sql, null, columnAliases, types); 47 } 48 49 protected SQLProjection(String sql, String groupBy, String [] columnAliases, Type[] types) { 50 this.sql = sql; 51 this.types = types; 52 this.aliases = columnAliases; 53 this.columnAliases = columnAliases; 54 this.grouped = groupBy!=null; 55 this.groupBy = groupBy; 56 } 57 58 public String [] getAliases() { 59 return aliases; 60 } 61 62 public String [] getColumnAliases(int loc) { 63 return columnAliases; 64 } 65 66 public boolean isGrouped() { 67 return grouped; 68 } 69 70 public Type[] getTypes(String alias, Criteria crit, CriteriaQuery criteriaQuery) { 71 return null; } 73 74 public String [] getColumnAliases(String alias, int loc) { 75 return null; } 77 } 78 | Popular Tags |