KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: SQLProjection.java,v 1.7 2005/02/12 07:19:14 steveebersole Exp $
2
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 /**
11  * A SQL fragment. The string {alias} will be replaced by the
12  * alias of the root entity.
13  */

14 public class SQLProjection implements Projection {
15
16     private final String JavaDoc sql;
17     private final String JavaDoc groupBy;
18     private final Type[] types;
19     private String JavaDoc[] aliases;
20     private String JavaDoc[] columnAliases;
21     private boolean grouped;
22
23     public String JavaDoc 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 JavaDoc 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 JavaDoc toString() {
42         return sql;
43     }
44
45     protected SQLProjection(String JavaDoc sql, String JavaDoc[] columnAliases, Type[] types) {
46         this(sql, null, columnAliases, types);
47     }
48     
49     protected SQLProjection(String JavaDoc sql, String JavaDoc groupBy, String JavaDoc[] 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 JavaDoc[] getAliases() {
59         return aliases;
60     }
61     
62     public String JavaDoc[] getColumnAliases(int loc) {
63         return columnAliases;
64     }
65     
66     public boolean isGrouped() {
67         return grouped;
68     }
69
70     public Type[] getTypes(String JavaDoc alias, Criteria crit, CriteriaQuery criteriaQuery) {
71         return null; //unsupported
72
}
73
74     public String JavaDoc[] getColumnAliases(String JavaDoc alias, int loc) {
75         return null; //unsupported
76
}
77 }
78
Popular Tags