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 an ORDER BY item
041: * <p><b>Responsibilities</b>:<ul>
042: * <li> Generate the correct expression for ORDER BY
043: * </ul>
044: * @author Jon Driscoll
045: * @since OracleAS TopLink 10<i>g</i> (9.0.4)
046: */package oracle.toplink.essentials.internal.parsing;
047:
048: import oracle.toplink.essentials.exceptions.EJBQLException;
049: import oracle.toplink.essentials.expressions.Expression;
050:
051: public class OrderByItemNode extends Node {
052: private SortDirectionNode direction = null;
053: private Node orderByItem = null;
054:
055: /**
056: * INTERNAL
057: * Validate node and calculate its type.
058: */
059: public void validate(ParseTreeContext context) {
060: TypeHelper typeHelper = context.getTypeHelper();
061: if (orderByItem != null) {
062: orderByItem.validate(context);
063: Object type = orderByItem.getType();
064: setType(type);
065: if (!typeHelper.isOrderableType(type)) {
066: throw EJBQLException.expectedOrderableOrderByItem(
067: context.getQueryInfo(), orderByItem.getLine(),
068: orderByItem.getColumn(), orderByItem
069: .getAsString(), typeHelper
070: .getTypeName(type));
071: }
072: }
073: }
074:
075: /** */
076: public Expression generateExpression(GenerationContext context) {
077: //BUG 3105651: Indicate to the VariableNodes in the subtree
078: //that they should check the SelectNode before resolving.
079: //If the variable involved is SELECTed, then we want an empty builder
080: //instead (with an empty constructor).
081: boolean oldCheckState = context
082: .shouldCheckSelectNodeBeforeResolving();
083: ((SelectGenerationContext) context)
084: .checkSelectNodeBeforeResolving(true);
085: Expression orderByExpression = getOrderByItem()
086: .generateExpression(context);
087: orderByExpression = getDirection().addToExpression(
088: orderByExpression, context);
089: ((SelectGenerationContext) context)
090: .checkSelectNodeBeforeResolving(oldCheckState);
091: return orderByExpression;
092: }
093:
094: public SortDirectionNode getDirection() {
095: if (direction == null) {
096: setDirection(new SortDirectionNode());
097: }
098: return direction;
099: }
100:
101: public Node getOrderByItem() {
102: return orderByItem;
103: }
104:
105: public void setDirection(SortDirectionNode direction) {
106: this .direction = direction;
107: }
108:
109: public void setOrderByItem(Node orderByItem) {
110: this.orderByItem = orderByItem;
111: }
112: }
|