KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > execution > AggregateCountAll


1 package com.daffodilwoods.daffodildb.server.sql99.dql.execution;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.sql99.common.*;
6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
7 import com.daffodilwoods.daffodildb.server.sql99.expression.*;
8 import com.daffodilwoods.daffodildb.utils.field.*;
9 import com.daffodilwoods.database.resource.*;
10 import com.daffodilwoods.daffodildb.server.sql99.expression.valueexpression;
11
12 /**
13  * <p>Title: AggregateCountAll </p>
14  * <p>Description:
15  * This class is responsible for retriving the number of rows belonging to one
16  * group. NULL values are ignored in count function evaluation. </p>
17  * <p>Copyright: Copyright (c) 2004</p>
18  * <p>Company: </p>
19  * @author not attributable
20  * @version 1.0
21  */

22 public class AggregateCountAll implements _Aggregate, Datatypes {
23
24   /**
25    * Variable representing the number of records involved in one group
26    */

27   private long count = 0;
28   /**
29    * Instance variable representing the expression/column involed
30    * in the count function argument.
31    */

32   private valueexpression column;
33
34    /**
35     * Initializes the value expression.
36     * @param column0 represents the value expression passed as argument to
37     * COUNT ALL function
38     * @throws DException throws an exception when aggregate function is
39     * performed on column of data type BLOB, CLOB and Boolean data type.
40     */

41    public AggregateCountAll(valueexpression column0) throws DException {
42       column = column0;
43       GeneralPurposeStaticClass.checkForValidColumnsInAggregatesMaxMinAndCount(column0.getColumnDetails(), "COUNT");
44       if (column0.getCardinality() > 1) {
45          throw new DException("DSE4119", new Object JavaDoc[] {"AGGREGATE FUNCTION COUNT"});
46       }
47
48     }
49
50    /**
51     * Intitializes the number of rows for each group. This is needed at the
52     * start of each group.
53     * @throws DException
54     */

55    public void initialize() throws DException {
56       count = 0;
57    }
58
59    /**
60     * This method is required to retrive number of rows belonging to
61     * a particular group.
62     * @return the number of the records involved in the group.
63     * @throws DException
64     */

65    public Object JavaDoc getResult() throws DException {
66       return new FieldLiteral(new Long JavaDoc(count), LONG);
67    }
68
69    public void releaseResource() throws DException {
70    }
71
72    public valueexpression getValueExpression() {
73       return column;
74    }
75
76    /**
77     * This method is responsible to add a new record in to a group and to perform
78     * to correspondingly increase the number of records in the group. NULL values
79     * are ignored in aggregate function computation.
80     * @param iterator group by iterator retriving the values of columns
81     * involved in aggregate computation.
82     * @throws DException
83     */

84
85    public void addRecord(Object JavaDoc newObject) throws DException{
86       if (((FieldBase)newObject).isNull()) {
87          return;
88       }
89       count++;
90
91    }
92 }
93
Popular Tags