KickJava   Java API By Example, From Geeks To Geeks.

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


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
package oracle.toplink.essentials.internal.parsing;
23
24
25 // Java imports
26
import java.util.*;
27
28 // TopLink Imports
29
import oracle.toplink.essentials.queryframework.ReadAllQuery;
30 import oracle.toplink.essentials.queryframework.ObjectLevelReadQuery;
31
32 /**
33  * INTERNAL
34  * <p><b>Purpose</b>: Represent an ORDER BY
35  * <p><b>Responsibilities</b>:<ul>
36  * <li> Generate the correct expression for an ORDER BY
37  * </ul>
38  * @author Jon Driscoll
39  * @since TopLink 5.0
40  */

41 public class OrderByNode extends MajorNode {
42
43     List orderByItems = null;
44
45     /**
46      * Return a new OrderByNode.
47      */

48     public OrderByNode() {
49         super();
50     }
51
52     /**
53      * INTERNAL
54      * Add an Order By Item to this node
55      */

56     private void addOrderByItem(Object JavaDoc theNode) {
57         getOrderByItems().add(theNode);
58     }
59
60     /**
61      * INTERNAL
62      * Add the ordering expressions to the passed query
63      */

64     public void addOrderingToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) {
65         if (theQuery.isReadAllQuery()) {
66             Iterator iter = getOrderByItems().iterator();
67             while (iter.hasNext()) {
68                 Node nextNode = (Node)iter.next();
69                 ((ReadAllQuery)theQuery).addOrdering(nextNode.generateExpression(context));
70             }
71         }
72     }
73
74     /**
75      * INTERNAL
76      * Validate node.
77      */

78     public void validate(ParseTreeContext context, SelectNode selectNode) {
79         for (Iterator i = orderByItems.iterator(); i.hasNext(); ) {
80             Node item = (Node)i.next();
81             item.validate(context);
82         }
83     }
84     
85     /**
86      * INTERNAL
87      * Return the order by statements
88      */

89     public List getOrderByItems() {
90         if (orderByItems == null) {
91             setOrderByItems(new Vector());
92         }
93         return orderByItems;
94     }
95
96     /**
97      * INTERNAL
98      * Set the order by statements
99      */

100     public void setOrderByItems(List newItems) {
101         orderByItems = newItems;
102     }
103 }
104
Popular Tags