KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.dql.iterator.table;
2
3 import com.daffodilwoods.daffodildb.client.*;
4 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record;
5 import com.daffodilwoods.daffodildb.server.sql99.common.*;
6 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
8 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
9 import com.daffodilwoods.daffodildb.utils.field.*;
10 import com.daffodilwoods.database.resource.*;
11 import com.daffodilwoods.database.sqlinitiator.*;
12 import com.daffodilwoods.database.utility.P;
13
14 /**
15  *
16  * <p>Title: ReverseIterator </p>
17  * <p>Description: This Class is used to reverse the underlying iterator.
18  * This Class is responsible to return the records in the specified order.
19  * If a particular table has an index on a table on a particular column and the
20  * user wants to retrieve the records in descending order for that particular
21  * column, records are retrived from the table and records are returned in the
22  * reverse order to maintain the descending order requirement and optimised use
23  * of the index of that table.
24  *
25  * The navigation methods are implemented to reverse the effect of the call to
26  * the iterator and all the remaining methods transfer the call to the
27  * underlying iterator.
28  * </p>
29  * <p>Copyright: Copyright (c) 2004</p>
30  * <p>Company: </p>
31  * @author not attributable
32  * @version 1.0
33  */

34 public class ReverseIterator extends AbstractVariableValues implements _Iterator {
35
36   /**
37    * Underlying iterator from which records to be retrived and to be returned
38    * in the reverse order.
39    */

40   _Iterator iterator;
41
42   private _Reference[] underlyingRef;
43
44   public ReverseIterator(_Iterator iterator) {
45     this.iterator = iterator;
46   }
47
48   /**
49    * This method is used to get the first record of the iterator.
50    * This method returns the last record of the underling iterator to fulfill
51    * the order requirements of reverse iterator.
52    * @return true if record found, false otherwise.
53    * @throws com.daffodilwoods.database.resource.DException
54    */

55   public boolean first() throws com.daffodilwoods.database.resource.DException {
56     return iterator.last();
57   }
58
59   /**
60    * This method is used to get the last record of the iterator.
61    * This method returns the first record of the underling iterator to fulfill
62    * the order requirements of reverse iterator.
63    * @return true if record found, false otherwise.
64    * @throws com.daffodilwoods.database.resource.DException
65    */

66   public boolean last() throws com.daffodilwoods.database.resource.DException {
67     return iterator.first();
68   }
69
70   /**
71    * This method is used to get the next record of the iterator.
72    * This method returns the previos record of the underling iterator to fulfill
73    * the order requirements of reverse iterator.
74    * @return true if record found, false otherwise.
75    * @throws com.daffodilwoods.database.resource.DException
76    */

77   public boolean next() throws com.daffodilwoods.database.resource.DException {
78     return iterator.previous();
79   }
80
81   /**
82    * This method is used to get the previous record of the iterator.
83    * This method returns the next record of the underling iterator to fulfill
84    * the order requirements of reverse iterator.
85    * @return true if record found, false otherwise.
86    * @throws com.daffodilwoods.database.resource.DException
87    */

88   public boolean previous() throws com.daffodilwoods.database.resource.DException {
89     return iterator.next();
90   }
91
92   /**
93    * The following methods just transfer the call to the underlying iterator.
94    * There is no need to change the following methods for reverse order
95    * requirement, thus, these method just transfer call to underlying iterator.
96    */

97
98   public _OrderCount getOrderCounts() throws com.daffodilwoods.database.resource.DException {
99     return iterator.getOrderCounts();
100   }
101
102   public TableDetails[] getTableDetails() throws com.daffodilwoods.database.resource.DException {
103     return iterator.getTableDetails();
104   }
105
106   public _Iterator getBaseIterator(ColumnDetails column) throws com.daffodilwoods.database.resource.DException {
107     return iterator.getBaseIterator(column);
108   }
109
110   public void setKeyCount(Object JavaDoc[][] parm1) throws com.daffodilwoods.database.resource.DException {
111      iterator.setKeyCount(parm1);
112   }
113
114   public void setConditionVariableValue(_Reference[] parm1, Object JavaDoc[] parm2, int parm3) throws com.daffodilwoods.database.resource.DException {
115     if(underlyingRef!=null){
116      parm1 = GeneralPurposeStaticClass.getJointReferences(parm1,underlyingRef);
117      parm2 = GeneralPurposeStaticClass.getJointValues(this, parm2,underlyingRef.length);
118    }
119     iterator.setConditionVariableValue(parm1, parm2 , parm3);
120   }
121
122   public Object JavaDoc getColumnValues() throws com.daffodilwoods.database.resource.DException {
123     return iterator.getColumnValues() ;
124   }
125
126   public _KeyColumnInformation[] getKeyColumnInformations() throws com.daffodilwoods.database.resource.DException {
127     return iterator.getKeyColumnInformations();
128   }
129
130   public Object JavaDoc[] getUniqueColumnReference() throws com.daffodilwoods.database.resource.DException {
131     return iterator.getUniqueColumnReference();
132   }
133
134   public boolean seek(Object JavaDoc parm1) throws com.daffodilwoods.database.resource.DException {
135     return iterator.seek(parm1);
136   }
137
138   public _Order getDefaultOrder() throws com.daffodilwoods.database.resource.DException {
139     return iterator.getDefaultOrder();
140   }
141
142   public _ExecutionPlan getExecutionPlan() throws com.daffodilwoods.database.resource.DException {
143     return iterator.getExecutionPlan();
144   }
145
146   public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws com.daffodilwoods.database.resource.DException {
147     return iterator.getExecutionPlanForBrowser();
148   }
149
150   public boolean seekFromTop(_IndexPredicate[] parm1) throws com.daffodilwoods.database.resource.DException {
151      return iterator.seekFromTop(parm1);
152   }
153
154   public boolean seekFromTopRelative(Object JavaDoc parm1) throws com.daffodilwoods.database.resource.DException {
155      return iterator.seekFromTopRelative(parm1);
156   }
157
158   public boolean seekFromBottom(_IndexPredicate[] parm1) throws com.daffodilwoods.database.resource.DException {
159      return iterator.seekFromBottom(parm1);
160   }
161
162   public boolean seekFromBottomRelative(Object JavaDoc parm1) throws com.daffodilwoods.database.resource.DException {
163      return iterator.seekFromBottomRelative(parm1);
164   }
165
166   public Object JavaDoc getKey() throws com.daffodilwoods.database.resource.DException {
167     return iterator.getKey();
168   }
169
170   public void move(Object JavaDoc parm1) throws com.daffodilwoods.database.resource.DException {
171     iterator.move(parm1);
172   }
173
174   public byte[] getByteKey() throws DException {
175    return iterator.getByteKey();
176  }
177
178  public void moveByteKey(byte[] key) throws DException {
179    iterator.moveByteKey(key);
180  }
181
182
183   public Object JavaDoc getColumnValues(int[] parm1) throws com.daffodilwoods.database.resource.DException {
184      return iterator.getColumnValues(parm1);
185   }
186
187   public _Record getRecord() throws com.daffodilwoods.database.resource.DException {
188      return iterator.getRecord();
189   }
190
191   public Object JavaDoc getColumnValues(_Reference[] parm1) throws com.daffodilwoods.database.resource.DException {
192     return iterator.getColumnValues(parm1);
193   }
194
195   public Object JavaDoc getColumnValues(_Reference parm1) throws com.daffodilwoods.database.resource.DException {
196     return iterator.getColumnValues(parm1);
197   }
198
199   public _Iterator getBaseIteratorHasRecord(ColumnDetails parm1) throws com.daffodilwoods.database.resource.DException {
200      return iterator.getBaseIteratorHasRecord(parm1);
201   }
202
203   public Object JavaDoc[][] getFunctionalColumnMapping() throws DException {
204      return iterator.getFunctionalColumnMapping();
205   }
206
207   public FieldBase field(_Reference reference) throws com.daffodilwoods.database.resource.DException {
208      return iterator.field(reference);
209   }
210
211   public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods.database.resource.DException {
212      return iterator.fields(references);
213   }
214
215   public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database.resource.DException {
216      throw new java.lang.UnsupportedOperationException JavaDoc("Method fields() not yet implemented.");
217   }
218
219   public void releaseResource() throws DException {
220     iterator.releaseResource();
221   }
222
223   public String JavaDoc toString(){
224      return "ReverseIterator["+iterator+"]";
225   }
226
227   public void setSpecificUnderlyingReferences(_Reference[] specificUnderlyingReferences) throws DException{
228     underlyingRef=specificUnderlyingReferences;
229     }
230
231 }
232
Popular Tags