KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sessionsystem > FilterIterator


1 package com.daffodilwoods.daffodildb.server.sessionsystem;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.client.*;
6 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.*;
7 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
8 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record;
9 import com.daffodilwoods.daffodildb.server.sql99.common.*;
10 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
11 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
12 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
13 import com.daffodilwoods.daffodildb.utils.comparator.*;
14 import com.daffodilwoods.daffodildb.utils.field.*;
15 import com.daffodilwoods.database.resource.*;
16 import com.daffodilwoods.database.sqlinitiator.*;
17
18 /**
19  *
20  * <p>Title: UnionIterator</p>
21  * <p>Description:Objective of the union iterator is to manage the operations of both the iterators it has.
22  */

23 public class FilterIterator
24     extends BaseExceptionSingleIterator
25     implements _TableIterator, _Iterator, _TableOperations,
26     _UserTableOperations,_IndexIteratorInfo {
27   _Iterator[] iterators;
28   /**
29    * Used to maintain the pointer of the UnionIterator
30    */

31
32   protected int status;
33   private Object JavaDoc transactionId;
34
35
36   /**
37    * Constructs the Union iterator with an array of two index iterators and an index table.
38    * @param iterators0 is an array of two index iterators one to iterate on the memory table and the other to iterate on file table..
39    * @param table0 is an index table that maintains the operations on memory and the file table.
40    */

41
42   _Reference[] reference;
43
44   public FilterIterator(_Iterator[] iterators0, _Reference[] references0,
45                         Object JavaDoc transactionId0) {
46     iterators = iterators0;
47     reference = references0;
48     transactionId = transactionId0;
49     status = -1;
50   }
51
52   /**
53    * set it's pointer to the first record in the table
54    * @return true if it gets the key corresponding to the first record in the table.
55    */

56
57   public boolean first() throws DException {
58     if (iterators[0].first()) {
59       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
60       values[1] = transactionId;
61       iterators[1].setConditionVariableValue(reference, values, 1);
62       if (iterators[1].first())
63         return next();
64       return true;
65     }
66     return false;
67   }
68
69   /**
70    * sets the pointer to the last record in the table
71        * @return true if it gets the key corresponding to the last record in the table.
72    */

73
74   public boolean last() throws DException {
75     if (iterators[0].last()) {
76       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
77       values[1] = transactionId;
78       iterators[1].setConditionVariableValue(reference, values, 1);
79       if (iterators[1].first())
80         return previous();
81       return true;
82     }
83     return false;
84   }
85   public void setKeyCount(Object JavaDoc[][] tableAndKeyCount) throws DException {
86     /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.dql.interfaces._Iterator method*/
87     throw new java.lang.UnsupportedOperationException JavaDoc("Method setKeyCount() not yet implemented.");
88   }
89
90   /**
91    * sets the pointer to the next record in the table
92        * @return true if it gets the key corresponding to the next record in the table.
93    */

94
95   public boolean next() throws DException {
96     if (iterators[0].next()) {
97       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
98       values[1] = transactionId;
99       iterators[1].setConditionVariableValue(reference, values, 1);
100       if (iterators[1].first())
101         return next();
102       return true;
103     }
104     return false;
105   }
106
107   /**
108    * sets the pointer to the previous record in the table.
109    * @return true if it gets the key corresponding to the previous record in the table.
110    */

111
112   public boolean previous() throws DException {
113     if (iterators[0].previous()) {
114       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
115       values[1] = transactionId;
116       iterators[1].setConditionVariableValue(reference, values, 1);
117       if (iterators[1].first())
118         return previous();
119       return true;
120     }
121     return false;
122   }
123
124   public Object JavaDoc getKey() throws DException {
125     return iterators[0].getKey();
126   }
127
128   /**
129    * moves the pointer to the given key in the table
130    * @param key Key to which the iterator will move its pointer
131    * @return true true if it gets the record corresponding to the given key in the table.
132    */

133
134   public void move(Object JavaDoc key) throws DException {
135     if (key == null)
136       return;
137     iterators[0].move(key);
138   }
139
140   /**
141    * retreives the value of the record at the current pointer from the table.
142    * @param columns array of columns whose value is to be retreived.
143    * @return an array of values corresponding to those columns.
144    */

145
146   public Object JavaDoc getColumnValues(int[] columns) throws DException {
147     return iterators[0].getColumnValues(columns);
148   }
149
150   /**
151    * Used to set the current key of all the file iterators to the given key position.
152    * @param currentKey The current key of the iterator
153    * @param newKey The Key to which the iterator will move its pointer.
154    */

155
156   public void delete(_DatabaseUser user) throws DException {
157     ( (_UserTableOperations) iterators[0]).delete(user);
158   }
159
160   public void delete() throws DException {
161     ( (_TableOperations) iterators[0]).delete();
162   }
163
164   public void insert(_DatabaseUser user, Object JavaDoc values) throws DException {
165     ( (_UserTableOperations) iterators[0]).insert(user, values);
166   }
167
168   public void insert(Object JavaDoc values) throws DException {
169     ( (_TableOperations) iterators[0]).insert(values);
170   }
171
172   public void update(Object JavaDoc values) throws DException {
173     ( (_TableOperations) iterators[0]).update(values);
174   }
175
176   public void update(_DatabaseUser user, Object JavaDoc values) throws DException {
177     ( (_UserTableOperations) iterators[0]).update(user, values);
178   }
179
180   public void update(int[] columns, Object JavaDoc[] values) throws DException {
181     ( (_TableOperations) iterators[0]).update(columns, values);
182   }
183
184   public void update(_DatabaseUser user, int[] columns, Object JavaDoc[] values) throws
185       DException {
186     ( (_UserTableOperations) iterators[0]).update(user, columns, values);
187   }
188
189   public _KeyColumnInformation[] getKeyColumnInformations() throws DException {
190     return iterators[0].getKeyColumnInformations();
191   }
192
193   public Object JavaDoc[] getUniqueColumnReference() throws DException {
194     return iterators[0].getUniqueColumnReference();
195   }
196
197   public int getBtreeIndex() throws DException {
198     return ( (IndexTableIterator) iterators[0]).getBtreeIndex();
199   }
200
201   public _Record getRecord() throws com.daffodilwoods.database.resource.
202
      DException {
203     return iterators[0].getRecord();
204   }
205
206   public Object JavaDoc getColumnValues(_Reference[] parm1) throws com.daffodilwoods.
207
      database.resource.DException {
208     return iterators[0].getColumnValues(parm1);
209   }
210
211   public boolean seek(Object JavaDoc indexKey) throws DException {
212     if (iterators[0].seek(indexKey)) {
213       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
214       values[1] = transactionId;
215       iterators[1].setConditionVariableValue(reference, values, 1);
216       return iterators[1].first() ? false : true;
217
218     }
219     return false;
220   }
221
222   public boolean seekFromBottomRelative(Object JavaDoc indexKey) throws DException {
223     if (iterators[0].seekFromBottomRelative(indexKey)) {
224       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
225       values[1] = transactionId;
226       iterators[1].setConditionVariableValue(reference, values, 1);
227       return iterators[1].first() ? false : true;
228
229     }
230     return false;
231   }
232
233   public boolean seekFromTopRelative(Object JavaDoc indexKey) throws DException {
234     if (iterators[0].seekFromTopRelative(indexKey)) {
235       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
236       values[1] = transactionId;
237       iterators[1].setConditionVariableValue(reference, values, 1);
238       return iterators[1].first() ? false : true;
239
240     }
241     return false;
242   }
243
244   public boolean seekFromTop(_IndexPredicate[] condition) throws DException {
245     if (iterators[0].seekFromTop(condition)) {
246       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
247       values[1] = transactionId;
248       iterators[1].setConditionVariableValue(reference, values, 1);
249       return iterators[1].first() ? false : true;
250     }
251     return false;
252   }
253
254   public boolean seekFromBottom(_IndexPredicate[] condition) throws DException {
255     if (iterators[0].seekFromBottom(condition)) {
256       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
257       values[1] = transactionId;
258       iterators[1].setConditionVariableValue(reference, values, 1);
259       return iterators[1].last() ? false : true;
260
261     }
262     return false;
263   }
264
265   public boolean locateKey(Object JavaDoc key, boolean top) throws DException {
266     if ( ( (_IndexIteratorInfo) iterators[0]).locateKey(key, top)) {
267       Object JavaDoc[] values = (Object JavaDoc[]) iterators[0].getColumnValues(new int[] {0, 1});
268       values[1] = transactionId;
269       iterators[1].setConditionVariableValue(reference, values, 1);
270       return iterators[1].last() ? true : false;
271
272     }
273     return false;
274   }
275
276   public _OrderCount getOrderCounts() throws com.daffodilwoods.database.
277
      resource.DException {
278     /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.dql.interfaces._Iterator method*/
279     throw new java.lang.UnsupportedOperationException JavaDoc(
280         "Method getOrderCounts() not yet implemented.");
281   }
282
283   public TableDetails[] getTableDetails() throws com.daffodilwoods.database.
284
      resource.DException {
285     /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.dql.interfaces._Iterator method*/
286     throw new java.lang.UnsupportedOperationException JavaDoc(
287         "Method getTableDetails() not yet implemented.");
288   }
289
290   public _Iterator getBaseIterator(ColumnDetails column) throws com.
291
      daffodilwoods.database.resource.DException {
292     /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.dql.interfaces._Iterator method*/
293     throw new java.lang.UnsupportedOperationException JavaDoc(
294         "Method getBaseIterator() not yet implemented.");
295   }
296
297   public void setConditionVariableValue(_Reference[] parm1, Object JavaDoc[] parm2,
298                                         int parm3) throws com.daffodilwoods.
299
      database.resource.DException {
300     iterators[0].setConditionVariableValue(parm1, parm2, parm3);
301   }
302
303   public Object JavaDoc getColumnValues() throws com.daffodilwoods.database.resource.
304
      DException {
305     return iterators[0].getColumnValues();
306   }
307
308   public Object JavaDoc getColumnValues(_Reference parm1) throws com.daffodilwoods.
309
      database.resource.DException {
310     return iterators[0].getColumnValues(parm1);
311   }
312
313   public void setIterator(_Iterator parm1) throws com.daffodilwoods.database.
314
      resource.DException {
315     /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.utils._VariableValues method*/
316     throw new java.lang.UnsupportedOperationException JavaDoc(
317         "Method setIterator() not yet implemented.");
318   }
319
320   public void addReferences(_Reference[] parm1) throws com.daffodilwoods.
321
      database.resource.DException {
322     /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.utils._VariableValues method*/
323     throw new java.lang.UnsupportedOperationException JavaDoc(
324         "Method addReferences() not yet implemented.");
325   }
326
327   public Object JavaDoc[][] getReferenceAndValuePair() throws com.daffodilwoods.
328
      database.resource.DException {
329     /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.utils._VariableValues method*/
330     throw new java.lang.UnsupportedOperationException JavaDoc(
331         "Method getReferenceAndValuePair() not yet implemented.");
332   }
333
334   public _Order getDefaultOrder() throws com.daffodilwoods.database.resource.
335
      DException {
336     /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.dql.interfaces._Iterator method*/
337     throw new java.lang.UnsupportedOperationException JavaDoc(
338         "Method getDefaultOrder() not yet implemented.");
339   }
340
341   public Object JavaDoc getColumnValues(int column) throws DException {
342     /**@todo Implement this com.daffodilwoods.daffodildb.server.datasystem.interfaces._TableIterator method*/
343     throw new java.lang.UnsupportedOperationException JavaDoc(
344         "Method getColumnValues() not yet implemented.");
345   }
346
347   public _ExecutionPlan getExecutionPlan() throws DException {
348     int length = iterators.length;
349     _ExecutionPlan cplans[] = new _ExecutionPlan[length];
350     for (int i = 0; i < length; i++) {
351       cplans[i] = iterators[i].getExecutionPlan();
352     }
353     return new ExecutionPlan("FilterIterator", cplans, null, null, null);
354   }
355
356   public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException {
357     int length = iterators.length;
358     ExecutionPlanForBrowser cplans[] = new ExecutionPlanForBrowser[length];
359     for (int i = 0; i < length; i++) {
360       cplans[i] = iterators[i].getExecutionPlanForBrowser();
361     }
362     return new ExecutionPlanForBrowser("Filter", "FilterIterator", cplans,
363                                        "" + Arrays.asList(reference), null, null);
364   }
365
366   public SuperComparator getComparator() {
367     return ( (_IndexIteratorInfo) iterators[0]).getComparator();
368   }
369
370   public SuperComparator getObjectComparator() throws com.daffodilwoods.
371
      database.resource.DException {
372     return ( (_IndexIteratorInfo) iterators[0]).getObjectComparator();
373   }
374
375   public _Iterator getBaseIteratorHasRecord(ColumnDetails hasRecordColumn) throws
376       DException {
377     throw new DException("DSE565", new Object JavaDoc[] {"getBaseIterator"});
378   }
379
380   public FieldBase field(_Reference reference) throws com.daffodilwoods.
381
      database.resource.DException {
382     return iterators[0].field(reference);
383   }
384
385   public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods.
386
      database.resource.DException {
387     return iterators[0].fields(reference);
388   }
389
390   public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database.
391
      resource.DException {
392     return iterators[0].fields(columns);
393   }
394
395   public FieldBase field(int column) throws DException {
396     /**@todo Implement this com.daffodilwoods.daffodildb.server.datasystem.interfaces._TableIterator method*/
397     throw new java.lang.UnsupportedOperationException JavaDoc(
398         "Method field() not yet implemented.");
399   }
400
401   public void releaseResource() throws DException {
402     iterators[0].releaseResource();
403   }
404
405     public void ensureRecordInMemory() throws DException{
406       ((_IndexIteratorInfo)iterators[0]).ensureRecordInMemory();
407     }
408     public void moveOnActualKey(Object JavaDoc key) throws DException{
409        throw new java.lang.UnsupportedOperationException JavaDoc(
410     "Method moveOnActualKey() not yet implemented.");
411
412      }
413     public Object JavaDoc getActualKey() throws DException{
414        throw new java.lang.UnsupportedOperationException JavaDoc(
415     "Method getActualKey() not yet implemented.");
416
417      }
418      public boolean seekKeyAddress(Object JavaDoc indexKey) throws DException{
419        throw new java.lang.UnsupportedOperationException JavaDoc(
420     "Method seekKeyAddress() not yet implemented.");
421
422      }
423      public Object JavaDoc getPhysicalAddress () throws DException{
424        throw new java.lang.UnsupportedOperationException JavaDoc(
425            "Method getPhysicalAddress() not yet implemented.");
426      }
427
428      public void deleteBlobClobRecord( _DatabaseUser user) throws DException {
429              ( (_TableOperations) iterators[0]).deleteBlobClobRecord(user) ;
430        }
431
432 }
433
Popular Tags