KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > parsing > HavingNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22

23 /**
24  * INTERNAL
25  * <p><b>Purpose</b>: This node represents a HAVING
26  * <p><b>Responsibilities</b>:<ul>
27  * <li> Generate the correct expression for HAVING
28  * </ul>
29  */

30 package oracle.toplink.essentials.internal.parsing;
31
32 // TopLink Imports
33
import oracle.toplink.essentials.queryframework.ReportQuery;
34 import oracle.toplink.essentials.queryframework.ObjectLevelReadQuery;
35 import oracle.toplink.essentials.exceptions.EJBQLException;
36 import oracle.toplink.essentials.expressions.Expression;
37
38 public class HavingNode extends MajorNode {
39
40     private Node having = null;
41
42     /**
43      * INTERNAL
44      * Validate the current node.
45      */

46     public void validate(ParseTreeContext context, GroupByNode groupbyNode) {
47         if (having != null) {
48             having.validate(context);
49             
50             if ((groupbyNode != null) && !groupbyNode.isValidHavingExpr(having)) {
51                 throw EJBQLException.invalidHavingExpression(
52                     having.getAsString(), groupbyNode.getAsString());
53             }
54         }
55     }
56     
57     /**
58      * INTERNAL
59      * Add the having expression to the passed query
60      */

61     public void addHavingToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) {
62         if (theQuery.isReportQuery()) {
63             Expression havingExpression = getHaving().generateExpression(context);
64             ((ReportQuery)theQuery).setHavingExpression(havingExpression);
65         }
66     }
67
68     /**
69      * INTERNAL
70      * Return the HAVING expression
71      */

72     public Node getHaving() {
73         return having;
74     }
75
76     /**
77      * INTERNAL
78      * Set the HAVING expression
79      */

80     public void setHaving(Node having) {
81         this.having = having;
82     }
83 }
84
Popular Tags