KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: RowCountProjection.java,v 1.8 2005/02/12 07:19:14 steveebersole Exp $
2
package org.hibernate.criterion;
3
4 import org.hibernate.Criteria;
5 import org.hibernate.Hibernate;
6 import org.hibernate.HibernateException;
7 import org.hibernate.type.Type;
8
9 /**
10  * A row count
11  * @author Gavin King
12  */

13 public class RowCountProjection extends SimpleProjection {
14
15     protected RowCountProjection() {}
16
17     public String JavaDoc toString() {
18         return "count(*)";
19     }
20
21     public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
22     throws HibernateException {
23         return new Type[] { Hibernate.INTEGER };
24     }
25
26     public String JavaDoc toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
27     throws HibernateException {
28         return new StringBuffer JavaDoc()
29             .append("count(*) as y")
30             .append(position)
31             .append('_')
32             .toString();
33     }
34
35 }
36
Popular Tags