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: package oracle.toplink.essentials.internal.parsing;
038:
039: // Java imports
040: import java.util.*;
041:
042: // TopLink Imports
043: import oracle.toplink.essentials.queryframework.ReadAllQuery;
044: import oracle.toplink.essentials.queryframework.ObjectLevelReadQuery;
045:
046: /**
047: * INTERNAL
048: * <p><b>Purpose</b>: Represent an ORDER BY
049: * <p><b>Responsibilities</b>:<ul>
050: * <li> Generate the correct expression for an ORDER BY
051: * </ul>
052: * @author Jon Driscoll
053: * @since TopLink 5.0
054: */
055: public class OrderByNode extends MajorNode {
056:
057: List orderByItems = null;
058:
059: /**
060: * Return a new OrderByNode.
061: */
062: public OrderByNode() {
063: super ();
064: }
065:
066: /**
067: * INTERNAL
068: * Add an Order By Item to this node
069: */
070: private void addOrderByItem(Object theNode) {
071: getOrderByItems().add(theNode);
072: }
073:
074: /**
075: * INTERNAL
076: * Add the ordering expressions to the passed query
077: */
078: public void addOrderingToQuery(ObjectLevelReadQuery theQuery,
079: GenerationContext context) {
080: if (theQuery.isReadAllQuery()) {
081: Iterator iter = getOrderByItems().iterator();
082: while (iter.hasNext()) {
083: Node nextNode = (Node) iter.next();
084: ((ReadAllQuery) theQuery).addOrdering(nextNode
085: .generateExpression(context));
086: }
087: }
088: }
089:
090: /**
091: * INTERNAL
092: * Validate node.
093: */
094: public void validate(ParseTreeContext context, SelectNode selectNode) {
095: for (Iterator i = orderByItems.iterator(); i.hasNext();) {
096: Node item = (Node) i.next();
097: item.validate(context);
098: }
099: }
100:
101: /**
102: * INTERNAL
103: * Return the order by statements
104: */
105: public List getOrderByItems() {
106: if (orderByItems == null) {
107: setOrderByItems(new Vector());
108: }
109: return orderByItems;
110: }
111:
112: /**
113: * INTERNAL
114: * Set the order by statements
115: */
116: public void setOrderByItems(List newItems) {
117: orderByItems = newItems;
118: }
119: }
|