KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > filter > lib > Count


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, S. Chassande-Barrioz, A. Lefebvre
22  */

23
24 package org.objectweb.medor.filter.lib;
25
26 import org.objectweb.jorm.type.api.PTypeSpace;
27 import org.objectweb.medor.expression.api.Expression;
28 import org.objectweb.medor.expression.api.ExpressionException;
29 import org.objectweb.medor.expression.api.MalformedExpressionException;
30 import org.objectweb.medor.expression.api.Operand;
31 import org.objectweb.medor.expression.api.Operator;
32 import org.objectweb.medor.expression.api.ParameterOperand;
33 import org.objectweb.medor.expression.lib.BasicVariableOperand;
34
35 import java.util.Map JavaDoc;
36
37 /**
38  * Count aggregate function.
39  * <p>
40  * Count applies to :
41  * <ol>
42  * <li>a FieldOperand, which is part of a NestedField.</li>
43  * <li>a Collection of values (TupleCollection), specifying which Field
44  * is to be aggregated</li>
45  * <li>a Collection of values (Java Collection)</li>
46  * </ol>
47  * <p>In the case of Count, it may be that no operand is specified. In this
48  * case, like in SQL (*), the Tuples made of all Fields of the NestedField
49  * are considered.
50  * @author Alexandre Lefebvre
51  */

52 public class Count extends BasicAggregateOperator {
53
54     private boolean countAll = false;
55
56     public Count() {
57         countAll = true;
58     }
59
60     public Count(Expression e) {
61         super(PTypeSpace.LONG, e);
62     }
63
64     public Count(Expression e, boolean distinct) {
65         super(PTypeSpace.LONG, e, distinct);
66     }
67
68     public Object JavaDoc clone(Object JavaDoc clone, Map JavaDoc obj2clone) throws CloneNotSupportedException JavaDoc {
69         clone = super.clone(clone, obj2clone);
70         ((Count) clone).countAll = countAll;
71         return clone;
72     }
73
74     public String JavaDoc getOperatorString() {
75         return Operator.COUNT;
76     }
77
78     public Operand compileExpression()
79             throws ExpressionException, MalformedExpressionException {
80         if (expressions[0] != null) {
81             expressions[0].compileExpression();
82                 result = new BasicVariableOperand(expressions[0].getType());
83                 verified = true;
84         }
85         else
86         // Operands not yet assigned
87
throw new MalformedExpressionException("null children value");
88         return result;
89     }
90
91     public Operand evaluate(ParameterOperand[] pos, Object JavaDoc o)
92             throws ExpressionException {
93         throw new ExpressionException("Implementation of Avg by MEDOR not yet implemented");
94     }
95
96     public boolean countAll() {
97         return countAll;
98     }
99
100     public void setCountAll() {
101         countAll = true;
102         distinct = false;
103     }
104 }
105
Popular Tags