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.database.resource.*; 10 import com.daffodilwoods.database.sqlinitiator.*; 11 import com.daffodilwoods.database.utility.P; 12 import com.daffodilwoods.daffodildb.utils.field.FieldLong; 13 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs; 14 import com.daffodilwoods.daffodildb.utils.BufferRange; 15 16 32 public class CounterIterator 33 extends BaseSingleIterator { 34 35 38 _Iterator baseIterator; 39 42 _Reference[] references; 43 46 long counter; 47 48 51 52 private int state ; 53 54 55 56 public CounterIterator(_Iterator baseIterator0, _Reference[] references0) { 57 super(baseIterator0); 58 baseIterator = baseIterator0; 59 references = references0; 60 state = INVALIDSTATE; 61 62 } 63 64 70 public boolean first() throws DException { 71 boolean flag = baseIterator.first(); 72 state = flag ? VALIDSTATE : AFTERLAST; 73 counter = flag ? 1 : 0; 74 return flag; 75 } 76 77 90 public boolean last() throws DException { 91 boolean flag = baseIterator.first(); 92 counter = 0; 93 if (flag) { 94 do { 95 counter++; 96 } 97 while (flag = baseIterator.next()); 98 baseIterator.previous(); 99 } 100 state = flag ? VALIDSTATE : AFTERLAST ; 101 102 return counter > 0; 103 } 104 105 111 public boolean next() throws DException { 112 switch (state) { 113 case INVALIDSTATE: 114 throw new DException("DSE4116", null); 115 case BEFOREFIRST: 116 return first(); 117 case AFTERLAST: 118 return false; 119 } 120 121 boolean flag = baseIterator.next(); 122 state = flag ? VALIDSTATE : AFTERLAST; 123 counter = flag ? counter + 1 : counter; 124 return flag; 125 } 126 127 128 134 public boolean previous() throws DException { 135 boolean flag ; 136 switch (state) { 137 case INVALIDSTATE: 138 throw new DException("DSE4117", null); 139 case BEFOREFIRST: 140 return false; 141 case AFTERLAST : 142 flag = baseIterator.previous(); 143 state = flag ? VALIDSTATE : BEFOREFIRST ; return flag; 145 } 146 147 flag = baseIterator.previous(); 148 149 state = flag ? VALIDSTATE : BEFOREFIRST ; 150 151 counter = flag ? counter - 1 : counter; 152 return flag; 153 } 154 155 156 164 public void move(Object key) throws DException { 165 166 Object oldKey = baseIterator.getKey(); 167 int tempCounter = 0; 168 boolean match = false; 169 if (baseIterator.first()) { 170 do { 171 if (baseIterator.getKey().equals(key)) { 172 match = true; 173 } 174 tempCounter++; 175 } 176 while (!match && baseIterator.next()); 177 } 178 if (match) { 179 counter = tempCounter; 180 } 181 else { 182 baseIterator.move(oldKey); 183 state = VALIDSTATE; 184 } 185 } 186 187 196 public Object getColumnValues(_Reference[] refs) throws DException { 197 if (state != VALIDSTATE) 198 throw new DException("DSE2019", new Object [] {new Integer (state)}); 199 200 Object [] values = new Object [references.length]; 201 for (int i = 0; i < refs.length; i++) { 202 values[i] = getColumnValues(refs[i]); 203 } 204 return values; 205 } 206 207 219 public Object getColumnValues(_Reference ref) throws DException { 220 boolean matched = false; 221 if (state != VALIDSTATE) 222 throw new DException("DSE2019", new Object [] {new Integer (state)}); 223 224 225 for (int i = 0; i < references.length && !matched; i++) { 226 matched = ref == references[i]; 227 } 228 return matched 229 ? 230 new FieldLong(new BufferRange(CCzufDpowfsufs.getBytes(counter)), 231 Datatypes.LONG) : baseIterator.getColumnValues(ref); 232 233 } 234 235 240 public _ExecutionPlan getExecutionPlan() throws DException { 241 _ExecutionPlan plan = baseIterator.getExecutionPlan(); 242 _ExecutionPlan cplans[] = plan == null ? null : new _ExecutionPlan[] { 243 plan}; 244 return new ExecutionPlan("CounterIterator", cplans, null, null, null); 245 } 246 247 252 public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException { 253 int length = 1; 254 ExecutionPlanForBrowser cplans[] = new ExecutionPlanForBrowser[length]; 255 cplans[0] = baseIterator.getExecutionPlanForBrowser(); 256 return new ExecutionPlanForBrowser("ROWNUM", "CounterIterator", cplans, null, null, null); 257 } 258 259 263 264 public Object getKey() throws DException { 265 return baseIterator.getKey(); 266 } 267 268 public _OrderCount getOrderCounts() throws DException { 269 return baseIterator.getOrderCounts(); 270 } 271 272 public TableDetails[] getTableDetails() throws DException { 273 return baseIterator.getTableDetails(); 274 } 275 276 public _Iterator getBaseIterator(ColumnDetails column) throws DException { 277 return baseIterator.getBaseIterator(column); 278 } 279 280 public void setConditionVariableValue(_Reference[] references, 281 Object [] values, int priority) throws 282 DException { 283 if (underlyingRef != null) { 284 references = GeneralPurposeStaticClass.getJointReferences(references, 285 underlyingRef); 286 values = GeneralPurposeStaticClass.getJointValues(this, values, 287 underlyingRef.length); 288 } 289 baseIterator.setConditionVariableValue(references, values, priority); 290 } 291 292 public _KeyColumnInformation[] getKeyColumnInformations() throws DException { 293 return baseIterator.getKeyColumnInformations(); 294 } 295 296 public void setKeyCount(Object [][] tableAndKeyCount) throws DException { 297 baseIterator.setKeyCount(tableAndKeyCount); 298 } 299 300 public Object [] getUniqueColumnReference() throws DException { 301 return baseIterator.getUniqueColumnReference(); 302 } 303 304 public _Order getDefaultOrder() throws DException { 305 return baseIterator.getDefaultOrder(); 306 } 307 308 public Object getColumnValues() throws DException { 309 312 313 throw new java.lang.UnsupportedOperationException ( 314 "Method getColumnValues() not yet implemented."); 315 } 316 317 public Object getColumnValues(int[] columns) throws DException { 318 319 throw new java.lang.UnsupportedOperationException ( 320 "Method getColumnValues() not yet implemented."); 321 } 322 323 public _Record getRecord() throws DException { 324 325 throw new java.lang.UnsupportedOperationException ( 326 "Method getRecord() not yet implemented."); 327 } 328 329 public boolean seek(Object indexKey) throws DException { 330 331 throw new java.lang.UnsupportedOperationException ( 332 "Method seek() not yet implemented."); 333 } 334 335 public boolean seekFromTop(_IndexPredicate[] condition) throws DException { 336 337 throw new java.lang.UnsupportedOperationException ( 338 "Method seekFromTop() not yet implemented."); 339 } 340 341 public boolean seekFromTopRelative(Object indexKey) throws DException { 342 343 throw new java.lang.UnsupportedOperationException ( 344 "Method seekFromTopRelative() not yet implemented."); 345 } 346 347 public boolean seekFromBottom(_IndexPredicate[] condition) throws DException { 348 349 throw new java.lang.UnsupportedOperationException ( 350 "Method seekFromBottom() not yet implemented."); 351 } 352 353 public boolean seekFromBottomRelative(Object indexKey) throws DException { 354 355 throw new java.lang.UnsupportedOperationException ( 356 "Method seekFromBottomRelative() not yet implemented."); 357 } 358 359 public Object getUpdatedEffect(_Reference[] references, Object [] values) throws 360 DException { 361 throw new UnsupportedOperationException ("getUpdatedEffect() Not Supported"); 362 } 363 364 365 } 366 | Popular Tags |