01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.ejb.query;
12:
13: /**
14: * MIN, MAX etc.
15: */
16: public class AggregateNode extends Node {
17:
18: public static final int AVG = 1;
19: public static final int MAX = 2;
20: public static final int MIN = 3;
21: public static final int SUM = 4;
22: public static final int COUNT = 5;
23:
24: private int op;
25: private boolean distinct;
26: private PathNode path;
27:
28: public AggregateNode(int op, boolean distinct, PathNode path) {
29: this .op = op;
30: this .distinct = distinct;
31: this .path = path;
32: }
33:
34: public int getOp() {
35: return op;
36: }
37:
38: public boolean isDistinct() {
39: return distinct;
40: }
41:
42: public PathNode getPath() {
43: return path;
44: }
45:
46: public String getOpStr() {
47: switch (op) {
48: case AVG:
49: return "AVG";
50: case MAX:
51: return "MAX";
52: case MIN:
53: return "MIN";
54: case SUM:
55: return "SUM";
56: case COUNT:
57: return "COUNT";
58: }
59: return "<? op " + op + "?>";
60: }
61:
62: public Object arrive(NodeVisitor v, Object msg) {
63: return v.arriveAggregateNode(this , msg);
64: }
65:
66: public String toStringImp() {
67: StringBuffer s = new StringBuffer();
68: s.append(getOpStr());
69: s.append('(');
70: if (distinct) {
71: s.append("DISTINCT ");
72: }
73: s.append(path);
74: s.append(')');
75: return s.toString();
76: }
77:
78: public void resolve(ResolveContext rc) {
79: path.resolve(rc);
80: }
81:
82: }
|