KickJava   Java API By Example, From Geeks To Geeks.

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


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.dql.tableexpression.groupbyclause.*;
8 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
9 import com.daffodilwoods.daffodildb.utils.comparator.*;
10 import com.daffodilwoods.database.resource.*;
11 import com.daffodilwoods.database.utility.*;
12
13 /**
14  * It represents the executable groupbyclause. It is required to solve group by.
15  * It allows user to check whether current row can be included in group or not.
16  * <p>Title: </p>
17  * <p>Description: </p>
18  * <p>Copyright: Copyright (c) 2003</p>
19  * <p>Company: </p>
20  * @author unascribed
21  * @version 1.0
22  */

23
24 public class GroupByCondition {
25
26    /**
27     * Represents groupbyclause.
28     */

29
30    private groupbyclause _grouppByClause;
31
32    /**
33     * Represents the previous value.
34     */

35
36    private Object JavaDoc previous;
37
38    /**
39     * Represents variable values to get the values of columns of group by clause.
40     */

41
42    private _VariableValues variableValues;
43
44    /**
45     * Represents a comparator which is used to compare the values of group by
46     * clause for different rows.
47     */

48
49    private SuperComparator comparator;
50
51    /**
52     * Initializes the variable values and the comparator for the columns
53     * involved in group by.
54     * @param _grouppByClause0
55     * @param iterator
56     * @param tableDetails
57     * @throws DException
58     */

59
60    public GroupByCondition(groupbyclause _grouppByClause0, _Iterator iterator, TableDetails[] tableDetails) throws DException {
61       _grouppByClause = _grouppByClause0;
62       _Reference[] ref = _grouppByClause.getReferences(tableDetails);
63       variableValues = new VariableValues(ref, null);
64       variableValues.setIterator(iterator);
65       ColumnDetails[] columns = _grouppByClause0.getColumnDetails();
66       boolean[] order = new boolean[columns.length];
67       Arrays.fill(order, true);
68       comparator = GeneralPurposeStaticClass.getOrderComparator(columns, order);
69    }
70
71    /**
72     * Sets the itertor in variable values.This iterator is used to provide the
73     * values of group by clause.
74     * @param iterator
75     * @throws DException
76     */

77
78    public void setIterator(_Iterator iterator) throws DException {
79       variableValues.setIterator(iterator);
80    }
81
82    /**
83     * Compares the values of group by clause for current row with the values of
84     * group by clause for previous row. It also sets the current value as
85     * previous after comparison.
86     * @return
87     * @throws DException
88     */

89
90    public boolean compare() throws DException {
91       Object JavaDoc object = _grouppByClause.run(variableValues);
92       if (previous == null) {
93          previous = object;
94          return true;
95       }
96       boolean bool = false;
97       try {
98          bool = comparator.compare(previous, object) == 0;
99       } catch (NullPointerException JavaDoc ex) {
100          throw ex;
101       }
102       previous = object;
103       return bool;
104    }
105
106    /**
107     * It is used to initialize previous object to its default value. It is
108     * needed at the start of each group.
109     * @throws DException
110     */

111
112    public void setPreviousState() throws DException {
113       previous = null;
114    }
115
116    /**
117     * Returns the columns involved in group by.
118     * @return
119     * @throws DException
120     */

121
122    public ColumnDetails[] getColumnDetails() throws DException {
123       return _grouppByClause.getColumnDetails();
124    }
125
126    public String JavaDoc toString() {
127       return "" + _grouppByClause;
128    }
129
130    /**
131     * Returns groupbyclause.
132     * @return
133     */

134
135    public groupbyclause get_grouppByClause() {
136       return _grouppByClause;
137    }
138
139    /**
140     * Sets the passed value of passed references in variable values.
141     * @param references
142     * @param values
143     * @param priority
144     * @throws DException
145     */

146
147    public void setConditionVariableValue(_Reference[] references, Object JavaDoc[] values, int priority) throws DException {
148       variableValues.setConditionVariableValue(references, values, priority);
149    }
150
151 }
152
Popular Tags