001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037:
038: /**
039: * INTERNAL
040: * <p><b>Purpose</b>: This node represents a HAVING
041: * <p><b>Responsibilities</b>:<ul>
042: * <li> Generate the correct expression for HAVING
043: * </ul>
044: */package oracle.toplink.essentials.internal.parsing;
045:
046: // TopLink Imports
047: import oracle.toplink.essentials.queryframework.ReportQuery;
048: import oracle.toplink.essentials.queryframework.ObjectLevelReadQuery;
049: import oracle.toplink.essentials.exceptions.EJBQLException;
050: import oracle.toplink.essentials.expressions.Expression;
051:
052: public class HavingNode extends MajorNode {
053:
054: private Node having = null;
055:
056: /**
057: * INTERNAL
058: * Validate the current node.
059: */
060: public void validate(ParseTreeContext context,
061: GroupByNode groupbyNode) {
062: if (having != null) {
063: having.validate(context);
064:
065: if ((groupbyNode != null)
066: && !groupbyNode.isValidHavingExpr(having)) {
067: throw EJBQLException.invalidHavingExpression(context
068: .getQueryInfo(), having.getLine(), having
069: .getColumn(), having.getAsString(), groupbyNode
070: .getAsString());
071: }
072: }
073: }
074:
075: /**
076: * INTERNAL
077: * Add the having expression to the passed query
078: */
079: public void addHavingToQuery(ObjectLevelReadQuery theQuery,
080: GenerationContext context) {
081: if (theQuery.isReportQuery()) {
082: Expression havingExpression = getHaving()
083: .generateExpression(context);
084: ((ReportQuery) theQuery)
085: .setHavingExpression(havingExpression);
086: }
087: }
088:
089: /**
090: * INTERNAL
091: * Return the HAVING expression
092: */
093: public Node getHaving() {
094: return having;
095: }
096:
097: /**
098: * INTERNAL
099: * Set the HAVING expression
100: */
101: public void setHaving(Node having) {
102: this.having = having;
103: }
104: }
|