KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > hql > classic > GroupByParser


1 //$Id: GroupByParser.java,v 1.1 2004/12/08 00:22:20 oneovthafew Exp $
2
package org.hibernate.hql.classic;
3
4 import org.hibernate.QueryException;
5 import org.hibernate.util.StringHelper;
6
7 /**
8  * Parses the GROUP BY clause of an aggregate query
9  */

10 public class GroupByParser implements Parser {
11
12     //this is basically a copy/paste of OrderByParser ... might be worth refactoring
13

14     // This uses a PathExpressionParser but notice that compound paths are not valid,
15
// only bare names and simple paths:
16

17     // SELECT p FROM p IN CLASS eg.Person GROUP BY p.Name, p.Address, p
18

19     // The reason for this is SQL doesn't let you sort by an expression you are
20
// not returning in the result set.
21

22     private final PathExpressionParser pathExpressionParser;
23
24     {
25         pathExpressionParser = new PathExpressionParser();
26         pathExpressionParser.setUseThetaStyleJoin( true ); //TODO: would be nice to use false, but issues with MS SQL
27
}
28
29     public void token(String JavaDoc token, QueryTranslatorImpl q) throws QueryException {
30
31         if ( q.isName( StringHelper.root( token ) ) ) {
32             ParserHelper.parse( pathExpressionParser, q.unalias( token ), ParserHelper.PATH_SEPARATORS, q );
33             q.appendGroupByToken( pathExpressionParser.getWhereColumn() );
34             pathExpressionParser.addAssociation( q );
35         }
36         else {
37             q.appendGroupByToken( token );
38         }
39     }
40
41     public void start(QueryTranslatorImpl q) throws QueryException {
42     }
43
44     public void end(QueryTranslatorImpl q) throws QueryException {
45     }
46
47
48 }
49
50
51
52
53
54
Popular Tags