01: //$Id: GroupByParser.java 4907 2004-12-08 00:24:14Z oneovthafew $
02: package org.hibernate.hql.classic;
03:
04: import org.hibernate.QueryException;
05: import org.hibernate.util.StringHelper;
06:
07: /**
08: * Parses the GROUP BY clause of an aggregate query
09: */
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 token, QueryTranslatorImpl q)
30: throws QueryException {
31:
32: if (q.isName(StringHelper.root(token))) {
33: ParserHelper.parse(pathExpressionParser, q.unalias(token),
34: ParserHelper.PATH_SEPARATORS, q);
35: q.appendGroupByToken(pathExpressionParser.getWhereColumn());
36: pathExpressionParser.addAssociation(q);
37: } else {
38: q.appendGroupByToken(token);
39: }
40: }
41:
42: public void start(QueryTranslatorImpl q) throws QueryException {
43: }
44:
45: public void end(QueryTranslatorImpl q) throws QueryException {
46: }
47:
48: }
|