KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sessionsystem;
2
3 import com.daffodilwoods.daffodildb.server.sql99.dql.execution._OrderCount;
4
5 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator;
6
7
8
9
10
11
12
13
14
15 import com.daffodilwoods.daffodildb.server.datasystem.utility.*;
16 import com.daffodilwoods.database.resource.DException;
17 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
18 import com.daffodilwoods.daffodildb.server.sql99.common._KeyColumnInformation;
19 import com.daffodilwoods.daffodildb.server.sql99.common.TableDetails;
20 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record;
21 import com.daffodilwoods.database.sqlinitiator._Order;
22 import com.daffodilwoods.database.general.*;
23 import com.daffodilwoods.daffodildb.client.*;
24 import com.daffodilwoods.daffodildb.server.sql99.common.ExecutionPlanForBrowser;
25 import com.daffodilwoods.daffodildb.server.sql99.common.ColumnDetails;
26 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
27 import com.daffodilwoods.daffodildb.utils.field.FieldBase;
28 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
29 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.DatabaseConstants;
30 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs;
31 import com.daffodilwoods.daffodildb.utils.FieldUtility;
32 import com.daffodilwoods.daffodildb.utils.BufferRange;
33
34 public class SessionIterator extends BaseExceptionSingleIterator
35         implements _TableOperations,_Iterator, _IndexIteratorInfo{
36     _Iterator iterator;
37     int[] intValue = {0,1,3};
38     _Key sessionKey = new SessionKey();
39     int[] columnIndexes;
40     int[] backUpColumnIndexes;
41     _Reference[] references;
42     Object JavaDoc[] parameters, excludingChild;
43     public static final int LENGTH = 2;
44     /**
45      * Initializes the Iterator (_IndexIterator)
46      * @param iterator0
47      */

48     public SessionIterator(_Iterator iterator0) throws DException{
49         iterator = iterator0;
50         try {
51             columnIndexes = (int[])(iterator.getUniqueColumnReference())[0];
52             backUpColumnIndexes = columnIndexes;
53         }
54         catch (Exception JavaDoc ex) {
55         }
56     }
57
58     /**
59      * searches the particular record from the table while traversing from top to bottom.
60      * @return boolean
61      * @throws DException
62      */

63
64     public boolean seekFromTop(_IndexPredicate[] condition) throws DException {
65         return iterator.seekFromTop(null);
66     }
67     /**
68      * searches the particular record from the table while traversing from top to bottom
69      * @return boolean
70      * @throws DException
71      */

72
73     public boolean seekFromTopRelative(_IndexPredicate condition) throws DException {
74         return iterator.seekFromTopRelative(null);
75     }
76     /**
77      * searches a record in the table while traversing from bottom to top.
78      * @return boolean
79      * @throws DException
80      */

81
82     public boolean seekFromBottom(_IndexPredicate[] condition) throws DException {
83         return iterator.seekFromBottom(condition);
84     }
85
86     public void setKeyCount(Object JavaDoc[][] tableAndKeyCount) throws DException {
87     /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.dql.interfaces._Iterator method*/
88     throw new java.lang.UnsupportedOperationException JavaDoc("Method setKeyCount() not yet implemented.");
89 }
90
91     /**
92      * search a record from the table while traversing from bottom to top
93      * @return boolean
94      * @throws DException
95      */

96
97     public boolean seekFromBottomRelative(_IndexPredicate condition) throws DException {
98         return iterator.seekFromBottomRelative(null);
99     }
100
101     /**
102      * reAdjust the current pointers of the fileIterators.
103      * @param currentKey
104      * @param newKey
105      * @throws DException
106      */

107
108     public void reAdjustFileKey(Object JavaDoc currentKey, Object JavaDoc newKey) throws DException {
109         throw new UnsupportedOperationException JavaDoc(" Not supported ");
110     }
111     /**
112      * reAdjust the current pointers of the memory Iterator.
113      * @throws DException
114      */

115
116     public void reAdjustMemoryKey(Object JavaDoc currentKey, Object JavaDoc newKey) throws DException {
117         throw new UnsupportedOperationException JavaDoc(" Not supported ");
118     }
119
120     /**
121      * passes the call for fetching the record to the iterator.
122      * @return Reocrd
123      * @throws DException
124      */

125
126     public _Record getRecord() throws DException {
127         return iterator.getRecord();
128     }
129
130     /**
131      * moves the pointer to its first position (i.e first record in the iterator list)
132      * @return boolean
133      * @throws DException
134      */

135
136     public boolean first() throws DException {
137         boolean b = iterator.first();
138         return b;
139     }
140
141     /**
142      * moves the pointer to its last position (i.e last record in the iterator list)
143      * @return boolean
144      * @throws DException
145      */

146
147     public boolean last() throws DException {
148         return iterator.last();
149     }
150
151     /**
152      * moves the pointer to its next position (i.e next record in the iterator list from its current position)
153      * @return boolean
154      * @throws DException
155      */

156
157     public boolean next() throws DException {
158         return iterator.next();
159     }
160
161     /**
162      * moves the pointer to its previous position (i.e previous record in the iterator list from its current position)
163      * @return boolean
164      * @throws DException
165      */

166
167     public boolean previous() throws DException {
168         return iterator.previous();
169     }
170
171     /**
172      * inserts value to the current record the iterator points to.
173      * @param value
174      * @throws DException
175      */

176
177     public void insert(Object JavaDoc value) throws DException {
178         ((_TableOperations)iterator).insert(value);
179     }
180
181     /**
182      * updates the reocrd pointed by the iteartor to value.
183      * @param value
184      * @throws DException
185      */

186
187     public void update(Object JavaDoc value) throws DException {
188         ((_TableOperations)iterator).update(value);
189     }
190
191     /**
192      * updates the column given by their index number of a record pointed by the iteartor to value.
193      * @param columns
194      * @param value
195      * @throws DException
196      */

197
198     public void update(int[] columns, Object JavaDoc[] value) throws DException {
199         ((_TableOperations)iterator).update(columns, value);
200     }
201
202     /**
203      * deletes the record , iterator points too.
204      * @throws DException
205      */

206
207     public void delete() throws DException {
208         ((_TableOperations)iterator).delete();
209     }
210
211     /**
212      * Used to set the pointer of the iterator to the given position.
213      * @param key
214      * @return boolean
215      * @throws DException
216      */

217
218     public void move(Object JavaDoc key) throws DException {
219
220         if(! iterator.seek(key)){
221             throw new DException("DSE5528", null);
222         }
223     }
224
225     /**
226      * Returns an Object containing the values of the cloumns passed.
227      * @param columns
228      * @return Object
229      * @throws DException
230      */

231
232     public Object JavaDoc getColumnValues(int[] columns) throws DException {
233         return iterator.getColumnValues(columns);
234     }
235
236     public Object JavaDoc getKey() throws DException {
237         return iterator.getColumnValues(columnIndexes);
238
239     }
240
241
242
243     /**
244      * @param user
245      * @param value
246      * @throws DException
247      */

248
249
250 /**
251  * @param user
252  * @param columns
253  * @param value
254  * @throws DException
255  */

256
257
258 /**
259  * @param user
260  * @throws DException
261  */

262
263
264 /**
265  * @param user
266  * @param value
267  * @throws DException
268  */

269
270
271
272
273 /**
274  * @todo method no implemented
275  * @param variableValues
276  * @throws DException
277  */

278
279     public void setConditionVariableValue(VariableValues variableValues) throws DException{
280     }
281
282     /**
283      * Returns a Obejct of values of columns.
284      * @param reference
285      * @return Object
286      * @throws DException
287      */

288
289     public Object JavaDoc getColumnValues(_Reference[] reference) throws DException{
290         Object JavaDoc obj = null;
291         obj = iterator.getColumnValues(reference);
292         return obj;
293     }
294     public Object JavaDoc getColumnValues(_Reference reference) throws DException{
295         return ((Object JavaDoc[])iterator.getColumnValues( new _Reference[]{ reference}))[0];
296     }
297
298     /**
299      * @todo method not yet implemented
300      * @param references
301      * @param values
302      * @param priority
303      * @throws DException
304      */

305
306     public void setConditionVariableValue(_Reference[] references ,Object JavaDoc[] values , int priority) throws DException{
307         ((_Iterator)iterator).setConditionVariableValue(references,values,priority);
308             columnIndexes = (int[])(iterator.getUniqueColumnReference())[0];
309             if(columnIndexes == null){
310                 iterator.getUniqueColumnReference();
311             }
312     }
313
314     public Object JavaDoc getColumnValues() throws DException{
315         try{
316             return ((_Iterator)iterator).getColumnValues();
317         }catch(ClassCastException JavaDoc ce){
318             return iterator.getColumnValues((int[])null);
319         }
320     }
321
322     public String JavaDoc toString(){
323         return "SESSIONITERATOR["+iterator+"]";
324     }
325     public boolean seek(Object JavaDoc indexKey) throws DException{
326         return iterator.seek(indexKey);
327     }
328     public Object JavaDoc[] getUniqueColumnReference() throws DException{
329         return iterator.getUniqueColumnReference();
330     }
331     public _KeyColumnInformation[] getKeyColumnInformations() throws DException{
332         return iterator.getKeyColumnInformations();
333     }
334     public TableDetails[] getTableDetails() throws DException {
335         return null;
336     }
337     public _Iterator getBaseIterator(ColumnDetails column) throws DException {
338         return this;
339     }
340     public boolean seekFromTopRelative(Object JavaDoc indexKey) throws DException {
341         /**@todo Implement this com.daffodilwoods.daffodildb.server.datasystem.interfaces._IndexIterator method*/
342         throw new java.lang.UnsupportedOperationException JavaDoc("Method seekFromTopRelative() not yet implemented.");
343     }
344     public boolean seekFromBottomRelative(Object JavaDoc indexKey) throws DException {
345         /**@todo Implement this com.daffodilwoods.daffodildb.server.datasystem.interfaces._IndexIterator method*/
346         throw new java.lang.UnsupportedOperationException JavaDoc("Method seekFromBottomRelative() not yet implemented.");
347     }
348     public _OrderCount getOrderCounts() throws com.daffodilwoods.database.resource.DException {
349         return ((_Iterator)iterator).getOrderCounts();
350     }
351
352     public Object JavaDoc[][] getReferenceAndValuePair() throws DException {
353         throw new java.lang.UnsupportedOperationException JavaDoc("Method getReferences() not yet implemented.");
354     }
355     public _Order getDefaultOrder() throws com.daffodilwoods.database.resource.DException {
356         /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.dql.interfaces._Iterator method*/
357         throw new java.lang.UnsupportedOperationException JavaDoc("Method getDefaultOrder() not yet implemented.");
358     }
359
360     public void ensureRecordInMemory() throws com.daffodilwoods.database.resource.DException {
361         ((_IndexIteratorInfo)iterator).ensureRecordInMemory();
362
363     }
364
365     public void moveOnActualKey(Object JavaDoc parm1) throws com.daffodilwoods.database.resource.DException {
366         iterator.seek(parm1);
367     }
368     public Object JavaDoc getActualKey() throws com.daffodilwoods.database.resource.DException {
369         return getKey();
370     }
371
372     public boolean locateKey(Object JavaDoc parm1, boolean parm2) throws com.daffodilwoods.database.resource.DException {
373         return ((_IndexIteratorInfo)iterator).locateKey(parm1,parm2);
374     }
375
376     public int getBtreeIndex() throws com.daffodilwoods.database.resource.DException {
377       return ((_IndexIteratorInfo)iterator).getBtreeIndex();
378     }
379
380     public void setReferencesOfReadCommitted(_Reference[] references0, Object JavaDoc[] parameters0, Object JavaDoc[] excludingChild0 ) throws DException{
381         references = references0;
382         parameters = parameters0;
383         excludingChild = excludingChild0;
384     }
385
386
387      public _ExecutionPlan getExecutionPlan() throws DException{
388         _ExecutionPlan plan = null;
389         try{
390             plan = ((_Iterator)iterator).getExecutionPlan();
391         }catch(ClassCastException JavaDoc cce){
392             _ExecutionPlan cplans[] = new _ExecutionPlan[]{plan};
393             return new ExecutionPlan("SessionIterator",cplans,null,null,null);
394         }
395         return plan;
396     }
397     public boolean seekKeyAddress(Object JavaDoc parm1) throws com.daffodilwoods.database.resource.DException {
398         return ((_IndexIteratorInfo)iterator).seekKeyAddress(parm1);
399     }
400     public Object JavaDoc getPhysicalAddress() throws com.daffodilwoods.database.resource.DException {
401         /**@todo Implement this com.daffodilwoods.daffodildb.server.datasystem.interfaces._IndexIteratorInfo method*/
402         throw new java.lang.UnsupportedOperationException JavaDoc("Method getPhysicalAddress() not yet implemented.");
403
404     }
405     public _Iterator getForeignKeyIterator() throws DException {
406         return (_Iterator)iterator;
407     }
408
409     public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException {
410         ExecutionPlanForBrowser plan = null;
411         try{
412             plan = ((_Iterator)iterator).getExecutionPlanForBrowser();
413         }catch(ClassCastException JavaDoc cce){
414         }
415         return plan;
416     }
417
418     public SuperComparator getComparator() {
419         return ((_IndexIteratorInfo)iterator).getComparator();
420     }
421
422     public SuperComparator getObjectComparator() throws com.daffodilwoods.database.resource.DException {
423         return ((_IndexIteratorInfo)iterator).getObjectComparator();
424     }
425
426     public _Iterator getBaseIteratorHasRecord(ColumnDetails hasRecordColumn) throws DException {
427         throw new DException("DSE565",new Object JavaDoc[]{"getBaseIterator"});
428     }
429     public FieldBase field(_Reference reference) throws com.daffodilwoods.database.resource.DException {
430         return ((FieldBase[])iterator.fields( new _Reference[]{ reference}))[0];
431     }
432     public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods.database.resource.DException {
433         FieldBase[] obj = null;
434         obj = iterator.fields(references);
435         return obj;
436     }
437     public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database.resource.DException {
438         return iterator.fields(columns);
439     }
440     public void releaseResource() throws DException {
441         iterator.releaseResource();
442     }
443     public byte[] getByteKey() throws DException{
444       FieldBase[] columnValues = FieldUtility.changeIntoFildBase(getKey());
445       int numberOfColumns = columnValues.length;
446       int totalLengthOfKey = numberOfColumns * 2 * LENGTH + LENGTH;
447       for (int i = 0; i < numberOfColumns; i++) {
448         totalLengthOfKey += columnValues[i].getLength();
449       }
450       byte[] byteKey = new byte[totalLengthOfKey];
451       int pointer = 0;
452       System.arraycopy(CCzufDpowfsufs.getBytes((short)numberOfColumns),0,byteKey,pointer,LENGTH);
453       pointer+=LENGTH;
454       for (int i = 0; i < numberOfColumns; i++) {
455         short dataType =(short) columnValues[i].getDatatype();
456         short length = 0;
457         byte[] columnValue = new byte[]{};
458          if(!columnValues[i].isNull()){
459            columnValue = columnValues[i].getBytes();
460            length = (short) columnValue.length;
461          }
462
463         System.arraycopy(CCzufDpowfsufs.getBytes(dataType),0,byteKey,pointer,LENGTH);
464         pointer+=LENGTH;
465         System.arraycopy(CCzufDpowfsufs.getBytes(length),0,byteKey,pointer,LENGTH);
466         pointer+=LENGTH;
467         System.arraycopy(columnValue,0,byteKey,pointer,length);
468         pointer+=length;
469       }
470       return byteKey;
471     }
472     public void moveByteKey(byte[] key) throws DException{
473   int pointer=0;
474   int numberOfColumns = CCzufDpowfsufs.getShortValue(key,pointer);
475   pointer+=LENGTH;
476   Object JavaDoc[] columnValues = new FieldBase[numberOfColumns];
477   for (int i = 0; i < numberOfColumns; i++) {
478     int dataType = CCzufDpowfsufs.getShortValue(key,pointer);
479     pointer+=LENGTH;
480     int columnLength = CCzufDpowfsufs.getShortValue(key,pointer);
481     pointer+=LENGTH;
482     byte[] b = new byte[columnLength];
483     System.arraycopy(key,pointer,b,0,columnLength);
484     BufferRange buffer= null;
485     if (columnLength == 0)
486       buffer = FieldUtility.NULLBUFFERRANGE;
487     else
488       buffer = new BufferRange(b, 0, columnLength);
489     columnValues[i] = FieldUtility.getField(dataType,buffer);
490     pointer+=columnLength;
491   }
492   moveOnActualKey(columnValues);
493 }
494
495 public void deleteBlobClobRecord(_DatabaseUser user) throws DException {
496       ((_TableOperations)iterator).deleteBlobClobRecord(user);
497   }
498
499
500 }
501
Popular Tags