KickJava   Java API By Example, From Geeks To Geeks.

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


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, 2005, Oracle. All rights reserved.
22

23 /**
24  * INTERNAL
25  * <p><b>Purpose</b>: This node represents an ORDER BY item
26  * <p><b>Responsibilities</b>:<ul>
27  * <li> Generate the correct expression for ORDER BY
28  * </ul>
29  * @author Jon Driscoll
30  * @since OracleAS TopLink 10<i>g</i> (9.0.4)
31  */

32 package oracle.toplink.essentials.internal.parsing;
33
34 import oracle.toplink.essentials.exceptions.EJBQLException;
35 import oracle.toplink.essentials.expressions.Expression;
36
37 public class OrderByItemNode extends Node {
38     private SortDirectionNode direction = null;
39     private Node orderByItem = null;
40
41     /**
42      * INTERNAL
43      * Validate node and calculate its type.
44      */

45     public void validate(ParseTreeContext context) {
46         TypeHelper typeHelper = context.getTypeHelper();
47         if (orderByItem != null) {
48             orderByItem.validate(context);
49             Object JavaDoc type = orderByItem.getType();
50             setType(type);
51             if (!typeHelper.isOrderableType(type)) {
52                 throw EJBQLException.expectedOrderableOrderByItem(
53                     orderByItem.getAsString(), typeHelper.getTypeName(type));
54             }
55         }
56     }
57
58     /** */
59     public Expression generateExpression(GenerationContext context) {
60         //BUG 3105651: Indicate to the VariableNodes in the subtree
61
//that they should check the SelectNode before resolving.
62
//If the variable involved is SELECTed, then we want an empty builder
63
//instead (with an empty constructor).
64
boolean oldCheckState = context.shouldCheckSelectNodeBeforeResolving();
65         ((SelectGenerationContext)context).checkSelectNodeBeforeResolving(true);
66         Expression orderByExpression = getOrderByItem().generateExpression(context);
67         orderByExpression = getDirection().addToExpression(orderByExpression, context);
68         ((SelectGenerationContext)context).checkSelectNodeBeforeResolving(oldCheckState);
69         return orderByExpression;
70     }
71
72     public SortDirectionNode getDirection() {
73         if (direction == null) {
74             setDirection(new SortDirectionNode());
75         }
76         return direction;
77     }
78
79     public Node getOrderByItem() {
80         return orderByItem;
81     }
82
83     public void setDirection(SortDirectionNode direction) {
84         this.direction = direction;
85     }
86
87     public void setOrderByItem(Node orderByItem) {
88         this.orderByItem = orderByItem;
89     }
90 }
91
Popular Tags