001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.ejb.query;
012:
013: /**
014: * A select_statement.
015: */
016: public class SelectNode extends Node {
017:
018: private boolean distinct;
019: private Node selectList;
020: private Node fromList;
021: private Node where;
022: private Node groupBy;
023: private Node having;
024: private Node orderByList;
025:
026: public SelectNode(boolean distinct, Node selectList, Node fromList,
027: Node where, Node groupBy, Node having, Node orderByList) {
028: this .distinct = distinct;
029: this .selectList = selectList;
030: this .fromList = fromList;
031: this .where = where;
032: this .groupBy = groupBy;
033: this .having = having;
034: this .orderByList = orderByList;
035: }
036:
037: public boolean isDistinct() {
038: return distinct;
039: }
040:
041: public Node getSelectList() {
042: return selectList;
043: }
044:
045: public Node getFromList() {
046: return fromList;
047: }
048:
049: public Node getWhere() {
050: return where;
051: }
052:
053: public Node getGroupBy() {
054: return groupBy;
055: }
056:
057: public Node getHaving() {
058: return having;
059: }
060:
061: public Node getOrderByList() {
062: return orderByList;
063: }
064:
065: public Object arrive(NodeVisitor v, Object msg) {
066: return v.arriveSelectNode(this , msg);
067: }
068:
069: public String toStringImp() {
070: StringBuffer s = new StringBuffer();
071: s.append("SELECT ");
072: if (distinct) {
073: s.append("DISTINCT ");
074: }
075: if (selectList != null) {
076: selectList.appendList(s);
077: }
078: s.append("\nFROM ");
079: if (fromList != null) {
080: fromList.appendList(s, "\n ");
081: }
082: if (where != null) {
083: s.append("\nWHERE ");
084: s.append(where);
085: }
086: if (groupBy != null) {
087: s.append("\nGROUP BY ");
088: groupBy.appendList(s);
089: if (having != null) {
090: s.append("\nHAVING ");
091: s.append(having);
092: }
093: }
094: if (orderByList != null) {
095: s.append("\nORDER BY ");
096: orderByList.appendList(s);
097: }
098: return s.toString();
099: }
100:
101: public void resolve(ResolveContext rc) {
102: resolve(fromList, rc);
103: resolve(selectList, rc);
104: resolve(where, rc);
105: resolve(groupBy, rc);
106: resolve(having, rc);
107: resolve(orderByList, rc);
108: }
109:
110: }
|