KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > ejb > 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.ejb.query;
13
14 /**
15  * MIN, MAX etc.
16  */

17 public class AggregateNode extends Node {
18
19     public static final int AVG = 1;
20     public static final int MAX = 2;
21     public static final int MIN = 3;
22     public static final int SUM = 4;
23     public static final int COUNT = 5;
24
25     private int op;
26     private boolean distinct;
27     private PathNode path;
28
29     public AggregateNode(int op, boolean distinct, PathNode path) {
30         this.op = op;
31         this.distinct = distinct;
32         this.path = path;
33     }
34
35     public int getOp() {
36         return op;
37     }
38
39     public boolean isDistinct() {
40         return distinct;
41     }
42
43     public PathNode getPath() {
44         return path;
45     }
46
47     public String JavaDoc getOpStr() {
48         switch (op) {
49             case AVG: return "AVG";
50             case MAX: return "MAX";
51             case MIN: return "MIN";
52             case SUM: return "SUM";
53             case COUNT: return "COUNT";
54         }
55         return "<? op " + op + "?>";
56     }
57
58     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
59         return v.arriveAggregateNode(this, msg);
60     }
61
62     public String JavaDoc toStringImp() {
63         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
64         s.append(getOpStr());
65         s.append('(');
66         if (distinct) {
67             s.append("DISTINCT ");
68         }
69         s.append(path);
70         s.append(')');
71         return s.toString();
72     }
73
74     public void resolve(ResolveContext rc) {
75         path.resolve(rc);
76     }
77
78 }
79
80
Popular Tags