KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > AggregatorInfo


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.AggregatorInfo
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute;
23
24 import org.apache.derby.iapi.sql.ResultDescription;
25 import org.apache.derby.iapi.services.io.StoredFormatIds;
26 import org.apache.derby.iapi.services.io.FormatIdUtil;
27 import org.apache.derby.iapi.services.io.Formatable;
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29
30 import java.io.ObjectOutput JavaDoc;
31 import java.io.ObjectInput JavaDoc;
32 import java.io.IOException JavaDoc;
33 /**
34  * This is a simple class used to store the run time information
35  * needed to invoke an aggregator. This class is serializable
36  * because it is stored with the plan. It is serializable rather
37  * than externalizable because it isn't particularly complicated
38  * and presumbably we don't need version control on plans.
39  *
40  * @author jamie
41  */

42 public class AggregatorInfo implements Formatable
43 {
44     /********************************************************
45     **
46     ** This class implements Formatable. That means that it
47     ** can write itself to and from a formatted stream. If
48     ** you add more fields to this class, make sure that you
49     ** also write/read them with the writeExternal()/readExternal()
50     ** methods.
51     **
52     ** If, inbetween releases, you add more fields to this class,
53     ** then you should bump the version number emitted by the getTypeFormatId()
54     ** method. OR, since this is something that is used
55     ** in stored prepared statements, it is ok to change it
56     ** if you make sure that stored prepared statements are
57     ** invalidated across releases.
58     **
59     ********************************************************/

60
61     /*
62     ** See the constructor for the meaning of these fields
63     */

64     String JavaDoc aggregateName;
65     int inputColumn;
66     int outputColumn;
67     int aggregatorColumn;
68     String JavaDoc aggregatorClassName;
69     boolean isDistinct;
70     ResultDescription rd;
71
72     /**
73      * Niladic constructor for Formattable
74      */

75     public AggregatorInfo() {}
76
77     /**
78      * Consructor
79      *
80      * @param aggregateName the name of the aggregate. Not
81      * actually used anywhere except diagnostics. Should
82      * be the names as found in the language (e.g. MAX).
83      * @param aggregatorClassName the name of the aggregator
84      * used to process this aggregate. Aggregator expected
85      * to have a null arg constructor and implement
86      * Aggregator.
87      * @param inputColNum the input column number
88      * @param outputColNum the output column number
89      * @param aggregatorColNum the column number in which the
90      * aggregator is stored.
91      * @param isDistinct if it is a distinct aggregate
92      * @param rd the result description
93      *
94      */

95     public AggregatorInfo
96     (
97         String JavaDoc aggregateName,
98         String JavaDoc aggregatorClassName,
99         int inputColNum,
100         int outputColNum,
101         int aggregatorColNum,
102         boolean isDistinct,
103         ResultDescription rd
104     )
105     {
106         this.aggregateName = aggregateName;
107         this.aggregatorClassName = aggregatorClassName;
108         this.inputColumn = inputColNum;
109         this.outputColumn = outputColNum;
110         this.aggregatorColumn = aggregatorColNum;
111         this.isDistinct = isDistinct;
112         this.rd = rd;
113     }
114
115     /**
116      * Get the name of the aggergate (e.g. MAX)
117      *
118      * @return the aggeregate name
119      */

120     public String JavaDoc getAggregateName()
121     {
122         return aggregateName;
123     }
124
125     /**
126      * Get the name of the class that implements the user
127      * aggregator for this class.
128      *
129      * @return the aggeregator class name
130      */

131     public String JavaDoc getAggregatorClassName()
132     {
133         return aggregatorClassName;
134     }
135
136
137     /**
138      * Get the column number for the aggregator
139      * column.
140      *
141      * @return the aggeregator colid
142      */

143     public int getAggregatorColNum()
144     {
145         return aggregatorColumn;
146     }
147
148     /**
149      * Get the column number for the input
150      * (addend) column.
151      *
152      * @return the aggeregator colid
153      */

154     public int getInputColNum()
155     {
156         return inputColumn;
157     }
158
159     /**
160      * Get the column number for the output
161      * (result) column.
162      *
163      * @return the aggeregator colid
164      */

165     public int getOutputColNum()
166     {
167         return outputColumn;
168     }
169
170     /**
171      * Is the aggergate distinct
172      *
173      * @return whether it is distinct
174      */

175     public boolean isDistinct()
176     {
177         return isDistinct;
178     }
179
180     /**
181      * Get the result description for the input value
182      * to this aggregate.
183      *
184      * @return the rd
185      */

186     public ResultDescription getResultDescription()
187     {
188         return rd;
189     }
190
191     /**
192      * Get a string for the object
193      *
194      * @return string
195      */

196     public String JavaDoc toString()
197     {
198         if (SanityManager.DEBUG)
199         {
200             return "AggregatorInfo = Name: "+ aggregateName +
201                 "\n\tClass: " + aggregatorClassName +
202                 "\n\tInputColNum: " + inputColumn +
203                 "\n\tOutputColNum: " + outputColumn +
204                 "\n\tAggregatorColNum: " + aggregatorColumn +
205                 "\n\tDistinct: " + isDistinct +
206                 "\n" + rd;
207         }
208         else
209         {
210             return "";
211         }
212     }
213
214
215     //////////////////////////////////////////////
216
//
217
// FORMATABLE
218
//
219
//////////////////////////////////////////////
220
/**
221      * Write this object out
222      *
223      * @param out write bytes here
224      *
225      * @exception IOException thrown on error
226      */

227     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
228     {
229         out.writeObject(aggregateName);
230         out.writeInt(inputColumn);
231         out.writeInt(outputColumn);
232         out.writeInt(aggregatorColumn);
233         out.writeObject(aggregatorClassName);
234         out.writeBoolean(isDistinct);
235         out.writeObject(rd);
236     }
237
238     /**
239      * Read this object from a stream of stored objects.
240      *
241      * @param in read this.
242      *
243      * @exception IOException thrown on error
244      * @exception ClassNotFoundException thrown on error
245      */

246     public void readExternal(ObjectInput JavaDoc in)
247         throws IOException JavaDoc, ClassNotFoundException JavaDoc
248     {
249         aggregateName = (String JavaDoc)in.readObject();
250         inputColumn = in.readInt();
251         outputColumn = in.readInt();
252         aggregatorColumn = in.readInt();
253         aggregatorClassName = (String JavaDoc)in.readObject();
254         isDistinct = in.readBoolean();
255         rd = (ResultDescription)in.readObject();
256     }
257     
258     /**
259      * Get the formatID which corresponds to this class.
260      *
261      * @return the formatID of this class
262      */

263     public int getTypeFormatId() { return StoredFormatIds.AGG_INFO_V01_ID; }
264 }
265
Popular Tags