KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > ejb > query > SelectNode


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.ejb.query;
13
14 /**
15  * A select_statement.
16  */

17 public class SelectNode extends Node {
18
19     private boolean distinct;
20     private Node selectList;
21     private Node fromList;
22     private Node where;
23     private Node groupBy;
24     private Node having;
25     private Node orderByList;
26
27     public SelectNode(boolean distinct, Node selectList, Node fromList,
28             Node where, Node groupBy, Node having, Node orderByList) {
29         this.distinct = distinct;
30         this.selectList = selectList;
31         this.fromList = fromList;
32         this.where = where;
33         this.groupBy = groupBy;
34         this.having = having;
35         this.orderByList = orderByList;
36     }
37
38     public boolean isDistinct() {
39         return distinct;
40     }
41
42     public Node getSelectList() {
43         return selectList;
44     }
45
46     public Node getFromList() {
47         return fromList;
48     }
49
50     public Node getWhere() {
51         return where;
52     }
53
54     public Node getGroupBy() {
55         return groupBy;
56     }
57
58     public Node getHaving() {
59         return having;
60     }
61
62     public Node getOrderByList() {
63         return orderByList;
64     }
65
66     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
67         return v.arriveSelectNode(this, msg);
68     }
69
70     public String JavaDoc toStringImp() {
71         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
72         s.append("SELECT ");
73         if (distinct) {
74             s.append("DISTINCT ");
75         }
76         if (selectList != null) {
77             selectList.appendList(s);
78         }
79         s.append("\nFROM ");
80         if (fromList != null) {
81             fromList.appendList(s, "\n ");
82         }
83         if (where != null) {
84             s.append("\nWHERE ");
85             s.append(where);
86         }
87         if (groupBy != null) {
88             s.append("\nGROUP BY ");
89             groupBy.appendList(s);
90             if (having != null) {
91                 s.append("\nHAVING ");
92                 s.append(having);
93             }
94         }
95         if (orderByList != null) {
96             s.append("\nORDER BY ");
97             orderByList.appendList(s);
98         }
99         return s.toString();
100     }
101
102     public void resolve(ResolveContext rc) {
103         resolve(fromList, rc);
104         resolve(selectList, rc);
105         resolve(where, rc);
106         resolve(groupBy, rc);
107         resolve(having, rc);
108         resolve(orderByList, rc);
109     }
110
111 }
112
113
Popular Tags