KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > iterator > table > SingleTableIterator


1 package com.daffodilwoods.daffodildb.server.sql99.dql.iterator.table;
2
3 import com.daffodilwoods.daffodildb.client.*;
4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
5 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record;
6 import com.daffodilwoods.daffodildb.server.sql99.common.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
8 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
9 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
10 import com.daffodilwoods.database.general.*;
11 import com.daffodilwoods.database.resource.*;
12 import com.daffodilwoods.database.sqlinitiator.*;
13 import com.daffodilwoods.database.utility.P;
14 import com.daffodilwoods.database.general.SystemFields;
15 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
16 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._IndexIterator;
17 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._IndexIteratorInfo;
18
19 /**
20  *
21  * <p>Title: SingleTableIterator </p>
22  * <p>Description: This Class is used to retrieve the records from the database
23  * persistent base level table (that is leaf table in any of iterators hierarchy).
24  * </p>
25  * <p>Copyright: Copyright (c) 2004</p>
26  * <p>Company: </p>
27  * @author not attributable
28  * @version 1.0
29  */

30 public class SingleTableIterator extends BaseSingleIterator implements _TableOperations ,_IndexIteratorInfo{
31   /**
32    * Variable representing the data system level underlying iterator.
33    */

34   private _Iterator backupIterator;
35   /**
36     * Variable representing the table properties.
37     */

38    private TableDetails tableDetails;
39    /**
40     * Variable representing the order information applied on single table.
41     */

42    private _Order order;
43
44    /**
45     * VARIABLE IS NOT IN USE.
46     */

47    private TableDetails[] underLyingTables;
48    private boolean flag = false;
49
50    public SingleTableIterator(_Iterator iterator0, TableDetails tableDetails0, TableDetails[] underLyingTables0, _Order order0) {
51       super(iterator0);
52       backupIterator = iterator0;
53       tableDetails = tableDetails0;
54       underLyingTables = underLyingTables0;
55       order = order0;
56    }
57
58    /**
59     * Returns the table characteristics of this table.
60     * @return table properties.
61     * @throws com.daffodilwoods.database.resource.DException
62     */

63    public TableDetails[] getTableDetails() throws com.daffodilwoods.database.resource.DException {
64       return new TableDetails[] {tableDetails};
65    }
66
67    /**
68     * This mehtod is used to get the base level iterator corresoponding to
69     * passed column.
70     * @param column passed column for which table is to be returned.
71     * @return base level iterator if the passed column exists in the table,
72     * null otherwise.
73     * @throws com.daffodilwoods.database.resource.DException
74     */

75    public _Iterator getBaseIterator(ColumnDetails column) throws com.daffodilwoods.database.resource.DException {
76       if (column.getTableDetails() == tableDetails) {
77          return this;
78       }
79       return null;
80    }
81
82    /**
83     * This method is used to get the appropriate index information on the table.
84     * This method set the name of the table for each of the column involved in
85     * the index.
86     * @return index of the table
87     * @throws com.daffodilwoods.database.resource.DException
88     */

89    public _KeyColumnInformation[] getKeyColumnInformations() throws com.daffodilwoods.database.resource.DException {
90       _KeyColumnInformation[] keyColumnInformation = iterator.getKeyColumnInformations();
91       try {
92         int rightKeysCount = 0;
93         for (int i = 0; i < keyColumnInformation.length; i++) {
94           rightKeysCount += keyColumnInformation[i].getColumnDetails().getSize();
95         }
96       }
97       catch (DException ex) {
98       }
99       for (int i = 0, length = keyColumnInformation.length; i < length; ++i) {
100          keyColumnInformation[i].setTableDetails(tableDetails);
101       }
102       return keyColumnInformation;
103    }
104
105    /**
106     * This method is used to return the key of the iterator as an object array.
107     * @return key of a particular record
108     * @throws com.daffodilwoods.database.resource.DException
109     */

110    public Object JavaDoc getKey() throws DException {
111       Object JavaDoc object = iterator.getKey();
112       return (object instanceof Object JavaDoc[]) ? object : new Object JavaDoc[] {object};
113    }
114
115    /**
116     * This method is used to align the underlying iterator at the passed key.
117     * This methods extracts the key from the passed key as returned and transfers
118     * the call to underlying data system level iterator.
119     * @param parm1 key where to move the underlying iterator
120     * @throws DException
121     */

122    public void move(Object JavaDoc parm1) throws DException {
123       try {
124          Object JavaDoc[] array = (Object JavaDoc[]) parm1;
125          iterator.move(array.length == 1 ? array[0] : array);
126       } catch (ClassCastException JavaDoc ex) {
127          iterator.move(parm1);
128       }
129    }
130
131    /**
132     * This method is used to get the number of columns involved in the
133     * Order.
134     * @return order applied on the single table. Returns null in the form of
135     * instance of OrderCountif no order applied on the table
136     * @throws DException
137     */

138    public _OrderCount getOrderCounts() throws DException {
139       if (order == null) {
140          return new OrderCount(0, order);
141       }
142       return new OrderCount(order.getKeyColumnDetails().length, order);
143    }
144
145    /**
146     * This method is responsible to get the default order i.e. rowid column
147     * for this table.
148     * @return a ColumnDetails class instance corresponding to rowId column.
149     * @throws DException
150     */

151    public _Order getDefaultOrder() throws DException {
152       ColumnDetails rowIdCd = new ColumnDetails();
153       String JavaDoc catalogName = tableDetails.getCatalogName();
154       String JavaDoc schemaName = tableDetails.getSchemaName();
155       rowIdCd.setColumnName(new String JavaDoc[] {catalogName, schemaName, SystemFields.systemFields[SystemFields.rowId]});
156       rowIdCd.setTableDetails(tableDetails);
157       rowIdCd.setType(TypeConstants.REFERENCE);
158       rowIdCd.setDatatype(Datatype.LONG);
159       rowIdCd.setSize(Datatype.LONGSIZE);
160       return new SelectOrder(new ColumnDetails[] {rowIdCd});
161    }
162
163    /**
164     * This method is responsible to display the executionPlan of a Select Query.
165     * @return _ExecutionPlan
166     * @throws DException
167     */

168    public _ExecutionPlan getExecutionPlan() throws DException {
169       _ExecutionPlan cplan = iterator.getExecutionPlan();
170       _ExecutionPlan cplans[] = cplan == null ? null : new _ExecutionPlan[] {cplan};
171       String JavaDoc order = getOrderString();
172       ExecutionPlan plan = new ExecutionPlan("SingleTableIterator[" + tableDetails + "]", cplans, null, order, null);
173       return plan;
174    }
175
176    /**
177     * This method is used to assist in displaying the order information applied
178     * on the table.
179     * @return order information
180     * @throws DException
181     */

182    private String JavaDoc getOrderString() throws DException {
183       String JavaDoc indexName = "";
184       boolean[] b = order.getOrderOfColumns();
185       ColumnDetails[] columns = order.getKeyColumnDetails();
186       for (int j = 0, length1 = columns.length; j < length1; j++) {
187          indexName += columns[j].getColumn() + " " + (b[j] ? " ASC ," : " DESC ,");
188       }
189       return indexName;
190    }
191
192    /**
193     * This method is responsible to display the iterators hierarchy of a Select Query.
194     * @return ExecutionPlanForBrowser
195     * @throws DException
196     */

197    public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException {
198       int length = 1;
199       ExecutionPlanForBrowser cplans[] = new ExecutionPlanForBrowser[length];
200       cplans[0] = iterator.getExecutionPlanForBrowser();
201       String JavaDoc refer = tableDetails.getAppropriateOnlyTableName();
202       return iterator.getExecutionPlanForBrowser();
203    }
204
205    /**
206     * This method is used to maintain mapping of columns vs. value expressions.
207     * Value expressions are solved at upper level.
208     * @return NULL
209     * @throws DException
210     */

211    public Object JavaDoc[][] getFunctionalColumnMapping() throws DException {
212       return null;
213    }
214
215    public _Iterator getBaseIteratorHasRecord(ColumnDetails parm1) throws DException {
216       return null;
217    }
218
219    public void setKeyCount(Object JavaDoc[][] tableAndKeyCount) throws DException {
220      flag = true;
221    }
222
223    public byte[] getByteKey() throws DException {
224      byte[] keys = null;
225      try {
226         keys = iterator.getByteKey();
227      }
228      catch (UnsupportedOperationException JavaDoc ex) {
229         throw new DException("DSE0",new Object JavaDoc[]{ex.getMessage()});
230      }
231       return keys;
232    }
233
234    public void moveByteKey(byte[] key) throws DException {
235      if (flag) {
236        byte[] keyAfterRemovingSizeField = new byte[key.length - 1];
237        System.arraycopy(key, 1, keyAfterRemovingSizeField, 0,
238                         keyAfterRemovingSizeField.length);
239        iterator.moveByteKey(keyAfterRemovingSizeField);
240      }
241      else
242        iterator.moveByteKey(key);
243    }
244
245    /**
246     * The following methods transfer the call to underlying data system level
247     * iterator.
248     */

249
250    public boolean first() throws DException {
251       return iterator.first();
252    }
253
254    public boolean last() throws DException {
255       return iterator.last();
256    }
257
258    public boolean next() throws DException {
259       return iterator.next();
260    }
261
262    public boolean previous() throws DException {
263       return iterator.previous();
264    }
265
266    public Object JavaDoc getColumnValues() throws DException {
267       return iterator.getColumnValues();
268    }
269
270    public Object JavaDoc getColumnValues(int[] parm1) throws DException {
271       return iterator.getColumnValues(parm1);
272    }
273
274    public void setConditionVariableValue(_Reference[] parm1, Object JavaDoc[] parm2, int parm3) throws DException {
275       try {
276         if(underlyingRef!=null){
277           parm1 = GeneralPurposeStaticClass.getJointReferences(parm1,underlyingRef);
278           parm2 = GeneralPurposeStaticClass.getJointValues(this, parm2,underlyingRef.length);
279         }
280          iterator.setConditionVariableValue(parm1, parm2, parm3);
281       } catch (Exception JavaDoc E) {
282       }
283    }
284
285    public _Record getRecord() throws DException {
286       return iterator.getRecord();
287    }
288
289    public void insert(Object JavaDoc parm1) throws DException {
290       ( (_TableOperations) iterator).insert(parm1);
291    }
292
293    public void update(Object JavaDoc parm1) throws DException {
294       ( (_TableOperations) iterator).update(parm1);
295    }
296
297    public void update(int[] parm1, Object JavaDoc[] parm2) throws DException {
298       ( (_TableOperations) iterator).update(parm1, parm2);
299    }
300
301    public void delete() throws DException {
302       ( (_TableOperations) iterator).delete();
303    }
304
305    public Object JavaDoc[] getUniqueColumnReference() throws DException {
306       return iterator.getUniqueColumnReference();
307    }
308
309    public boolean seek(Object JavaDoc parm1) throws DException {
310       return iterator.seek(parm1);
311    }
312
313    public boolean seekFromTop(_IndexPredicate[] parm1) throws DException {
314       return iterator.seekFromTop(parm1);
315    }
316
317    public boolean seekFromTopRelative(Object JavaDoc indexKey) throws DException {
318       return iterator.seekFromTopRelative(indexKey);
319    }
320
321    public boolean seekFromBottom(_IndexPredicate[] parm1) throws DException {
322       return iterator.seekFromBottom(parm1);
323    }
324
325    public boolean seekFromBottomRelative(Object JavaDoc indexKey) throws DException {
326       return iterator.seekFromBottomRelative(indexKey);
327    }
328
329    public Object JavaDoc getUpdatedEffect(_Reference[] references, Object JavaDoc[] values) throws DException {
330       throw new UnsupportedOperationException JavaDoc("getUpdatedEffect() Not Supported");
331    }
332
333    public String JavaDoc toString() {
334       try {
335          return "SingleTableIterator" + hashCode() + "[" + iterator + "][" + tableDetails.getNameOfTable() + "]";
336       } catch (DException d) {
337          return null;
338       }
339    }
340    public void deleteBlobClobRecord(_DatabaseUser user) throws DException {
341      ( (_TableOperations) iterator).deleteBlobClobRecord(user) ;
342      }
343
344   /**
345    * getBtreeIndex
346    *
347    * @return int
348    */

349   public int getBtreeIndex() {
350     return 0;
351   }
352
353   /**
354    * locateKey
355    *
356    * @param key Object
357    * @param top boolean
358    * @return boolean
359    */

360   public boolean locateKey(Object JavaDoc key, boolean top) throws DException{
361     return ((_IndexIteratorInfo)iterator).locateKey(key,top) ;
362   }
363
364   /**
365    * ensureRecordInMemory
366    */

367   public void ensureRecordInMemory() throws DException{
368     ((_IndexIteratorInfo)iterator).ensureRecordInMemory() ;
369   }
370
371   /**
372    * moveOnActualKey
373    *
374    * @param key Object
375    */

376   public void moveOnActualKey(Object JavaDoc key) throws DException{
377     ((_IndexIteratorInfo)iterator).moveOnActualKey(key);
378   }
379
380   /**
381    * getActualKey
382    *
383    * @return Object
384    */

385   public Object JavaDoc getActualKey() throws DException {
386   return ((_IndexIteratorInfo)iterator).getActualKey() ;
387   }
388
389   /**
390    * seekKeyAddress
391    *
392    * @param indexKey Object
393    * @return boolean
394    */

395   public boolean seekKeyAddress(Object JavaDoc indexKey) throws DException{
396    return ((_IndexIteratorInfo)iterator).seekKeyAddress(indexKey);
397   }
398
399   /**
400    * getPhysicalAddress
401    *
402    * @return Object
403    */

404   public Object JavaDoc getPhysicalAddress() throws DException {
405    return ((_IndexIteratorInfo)iterator).getPhysicalAddress() ;
406   }
407
408   /**
409    * getComparator
410    *
411    * @return SuperComparator
412    */

413   public SuperComparator getComparator() {
414     return ((_IndexIteratorInfo)iterator).getComparator() ;
415   }
416
417   /**
418    * getObjectComparator
419    *
420    * @return SuperComparator
421    */

422   public SuperComparator getObjectComparator() throws DException{
423   return ((_IndexIteratorInfo)iterator).getObjectComparator() ;
424   }
425
426 }
427
Popular Tags