KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > query > AggregateNode


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.jdo.query;
13
14 import com.versant.core.metadata.ClassMetaData;
15
16 /**
17  * Node to represent aggregate expressions
18  */

19 public class AggregateNode extends UnaryNode {
20
21     public static final int TYPE_SUM = 1;
22     public static final int TYPE_AVG = 2;
23     public static final int TYPE_COUNT = 3;
24     public static final int TYPE_MIN = 4;
25     public static final int TYPE_MAX = 5;
26
27     private int type;
28
29     public AggregateNode(Node child, int type) {
30         super(child);
31         this.asValue = child.asValue;
32         this.type = type;
33     }
34
35     public AggregateNode() {
36         type = TYPE_COUNT;
37     }
38
39     /**
40      * Resolve field refs and so on relative to the compiler. This must
41      * recursively resolve any child nodes.
42      */

43     public void resolve(QueryParser comp, ClassMetaData cmd, boolean ordering) {
44         childList.resolve(comp, cmd, ordering);
45     }
46
47     public String JavaDoc 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 JavaDoc toString() {
68         return super.toString() + "Type " + getTypeString() + " as " + asValue;
69     }
70
71     public Object JavaDoc accept(NodeVisitor visitor, Object JavaDoc[] results) {
72         return visitor.visitAggregateNode(this, results);
73     }
74
75     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
76         return v.arriveAggregateNode(this, msg);
77     }
78 }
79
Popular Tags