KickJava   Java API By Example, From Geeks To Geeks.

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


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: AggregateSumDistinct </p>
14  * <p>Description:
15  * This class is responsible for computing SUM DISTINCT aggregate
16  * function for a particular group of rows. DUPLICATE and NULL values are
17  * not considered while computing SUM DISTINCT. </p>
18  * <p>Copyright: Copyright (c) 2004</p>
19  * <p>Company: </p>
20  * @author not attributable
21  * @version 1.0
22  */

23 public class AggregateSumDistinct extends AggregateSumAll 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     * Initializes the value expression and its data type.
31     * @throws DException throws an exception
32     * 1) when the cardinality of the value expression is more than one. SUM
33     * function can be performed on one column at one time.
34     * 2) when aggregate function is performed on column of
35     * data type character string, datetime and BLOB, CLOB and Boolean data type.
36     */

37
38    public AggregateSumDistinct(valueexpression column0) throws DException {
39       super(column0);
40    }
41
42    /**
43     * This method initializes the variables involved in SUM function computation.
44     * This method also makes the list empty for storing distinct values
45     * belonging to a particular group, when a group starts.
46     * @throws DException
47     */

48    public void initialize() throws DException {
49       aList = new ArrayList();
50       super.initialize();
51    }
52
53    /**
54     * This method is responsible to add a new record in to a group and to
55     * correspondingly update the sum of the values. If the new value is
56     * null or duplicate of some other value, then it is ignored.
57     * @param iterator group by iterator retriving the values of columns
58     * involved in aggregate computation.
59     * @throws DException
60     */

61
62   public void addRecord(Object JavaDoc obj) throws DException {
63       FieldBase newObject = (FieldBase) obj;
64       if (newObject.isNull()) {
65          return;
66       }
67       if (!aList.contains(newObject.getObject())) {
68          getSum(result, newObject);
69          aList.add(newObject.getObject());
70       }
71    }
72
73 }
74
Popular Tags