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.jdo.query;
12:
13: import com.versant.core.metadata.ClassMetaData;
14:
15: /**
16: * Node to represent aggregate expressions
17: */
18: public class AggregateNode extends UnaryNode {
19:
20: public static final int TYPE_SUM = 1;
21: public static final int TYPE_AVG = 2;
22: public static final int TYPE_COUNT = 3;
23: public static final int TYPE_MIN = 4;
24: public static final int TYPE_MAX = 5;
25:
26: private int type;
27:
28: public AggregateNode(Node child, int type) {
29: super (child);
30: this .asValue = child.asValue;
31: this .type = type;
32: }
33:
34: public AggregateNode() {
35: type = TYPE_COUNT;
36: }
37:
38: /**
39: * Resolve field refs and so on relative to the compiler. This must
40: * recursively resolve any child nodes.
41: */
42: public void resolve(QueryParser comp, ClassMetaData cmd,
43: boolean ordering) {
44: childList.resolve(comp, cmd, ordering);
45: }
46:
47: public String getTypeString() {
48: switch (type) {
49: case AggregateNode.TYPE_AVG:
50: return "AVG";
51: case AggregateNode.TYPE_COUNT:
52: return "COUNT";
53: case AggregateNode.TYPE_MAX:
54: return "MAX";
55: case AggregateNode.TYPE_MIN:
56: return "MIN";
57: case AggregateNode.TYPE_SUM:
58: return "SUM";
59: }
60: return "UNKNOWN(" + type + ")";
61: }
62:
63: public int getType() {
64: return type;
65: }
66:
67: public String toString() {
68: return super .toString() + "Type " + getTypeString() + " as "
69: + asValue;
70: }
71:
72: public Object accept(NodeVisitor visitor, Object[] results) {
73: return visitor.visitAggregateNode(this , results);
74: }
75:
76: public Object arrive(NodeVisitor v, Object msg) {
77: return v.arriveAggregateNode(this, msg);
78: }
79: }
|