KickJava   Java API By Example, From Geeks To Geeks.

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


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.database.utility.*;
11
12 /**
13  * <p>Title: AggregateAvgDistinct </p>
14  * <p>Description:
15  * This class is responsible for computing AVERAGE DISTINCT aggregate
16  * function for a particular group of rows. DUPLICATE and NULL values are
17  * ignored in average function evaluation. </p>
18  * <p>Copyright: Copyright (c) 2004</p>
19  * <p>Company: </p>
20  * @author not attributable
21  * @version 1.0
22  */

23 public class AggregateAvgDistinct extends AggregateAvgAll implements _Aggregate, Datatypes, IntegerPool {
24
25   /**
26    * List for caching distinct values involved in function computation.
27    */

28   private ArrayList aList; //for quantifier (distinct)
29

30   /**
31    * Initializes the value expression and its data type, and the list having
32    * distinct values taking part in aggregate function computation.
33    * @param column0 represents the value expression passed as argument to
34    * AVG ALL function.
35    * @throws DException throws an exception when aggregate function is
36    * performed on column of data type character string, datetime, BLOB,
37    * CLOB and Boolean data type.
38    */

39    public AggregateAvgDistinct(valueexpression column0) throws DException {
40       super(column0);
41       aList = new ArrayList();
42    }
43
44    /**
45     * This method initializes the variables involved in function computation.
46     * This method also makes the list empty for storing distinct values
47     * belonging to a particular group.
48     * @throws DException
49     */

50    public void initialize() throws DException {
51       aList.clear();
52       super.initialize();
53    }
54
55    /**
56     * This method is responsible to add a new record in to a group and
57     * to correspondingly update the number of rows in the group and sum of the
58     * values. If the new value is added into the group is already present in the
59     * list, new value is just ignored, otherwise, no of rows and the sum of values
60     * are updated. For first value in the group, sum of the values is initialized
61     * acc to datatype. NULL values are ingnored in aggregate function computation.
62     * @param iterator group by iterator retriving the values of columns
63     * involved in aggregate computation.
64     * @throws DException
65     */

66
67    public void addRecord(Object JavaDoc obj) throws DException {
68       FieldBase newObject = (FieldBase) obj;
69       if (newObject.isNull()) {
70          return;
71       }
72       if (initialized) {
73          init();
74          initialized = false;
75       }
76       if (!aList.contains(newObject.getObject())) {
77          count++;
78          getSum(result, newObject);
79          aList.add(newObject.getObject());
80       }
81    }
82
83 }
84
Popular Tags