1 package com.daffodilwoods.daffodildb.server.sql99.dql.iterator.condition; 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.iterator.*; 8 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 9 import com.daffodilwoods.daffodildb.utils.comparator.*; 10 import com.daffodilwoods.database.resource.*; 11 import com.daffodilwoods.database.sqlinitiator.*; 12 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference; 13 import com.daffodilwoods.database.utility.P; 14 15 27 28 public class IndexedFilterIterator 29 extends BaseSingleIterator 30 implements _TableOperations, _UserTableOperations, _IndexIteratorInfo { 31 32 35 ConditionVariableValue conditionVariableValue; 36 40 _IndexPredicate[] indexPredicate; 41 44 private _Iterator backUpIterator; 45 48 49 private int state; 50 51 52 public IndexedFilterIterator(_Iterator indexedIterator, 53 ConditionVariableValue conditionVariableValue, 54 _IndexPredicate[] indexArray) { 55 super(indexedIterator); 56 this.conditionVariableValue = conditionVariableValue; 57 this.indexPredicate = indexArray; 58 backUpIterator = indexedIterator; 59 state = INVALIDSTATE; 60 } 61 62 71 72 public boolean first() throws DException { 73 boolean flag = iterator.seekFromTop(indexPredicate); 74 state = flag ? VALIDSTATE : AFTERLAST; 75 76 return flag; 77 } 78 79 88 89 public boolean last() throws DException { 90 boolean flag = iterator.seekFromBottom(indexPredicate); 91 state = flag ? VALIDSTATE : BEFOREFIRST; 92 return flag; 93 } 94 95 107 108 public boolean next() throws DException { 109 switch (state) { 110 case INVALIDSTATE: 111 throw new DException("DSE4116", null); 112 case BEFOREFIRST: 113 return first(); 114 case AFTERLAST: 115 return false; 116 } 117 while (true) { 118 boolean next = iterator.next(); 119 try { 120 next = next ? conditionVariableValue.run().hashCode() == 0 : next; 121 state = next ? VALIDSTATE : AFTERLAST; 122 } 123 catch (DException de) { 124 if (de.getDseCode().equalsIgnoreCase("DSE2004")) 125 continue; 126 else { 127 ; throw de; 129 } 130 } 131 return next; 132 } 133 } 134 135 147 148 public boolean previous() throws DException { 149 switch (state) { 150 case INVALIDSTATE: 151 throw new DException("DSE4117", null); 152 case BEFOREFIRST: 153 return false; 154 case AFTERLAST: 155 return last(); 156 } 157 while (true) { 158 boolean prev = iterator.previous(); 159 try { 160 prev = prev ? conditionVariableValue.run().hashCode() == 0 : prev; 161 state = prev ? VALIDSTATE : BEFOREFIRST; 162 } 163 catch (DException de) { 164 if (de.getDseCode().equalsIgnoreCase("DSE2004")) 165 continue; 166 else 167 throw de; 168 } 169 return prev; 170 } 171 } 172 173 182 183 public Object getColumnValues(_Reference[] leftColumnReferences) throws 184 DException { 185 if (state != VALIDSTATE) 186 throw new DException("DSE2019", new Object [] {new Integer (state)}); 187 try { 188 return iterator.getColumnValues(leftColumnReferences); 189 } 190 catch (ArrayIndexOutOfBoundsException E) { 191 throw E; 192 } 193 } 194 195 public String toString() { 196 String str = "INDEXEDFILTERITERATOR"; 197 str += "[" + iterator + "][ConditionVariableValues" + 198 conditionVariableValue + "]"; 199 return str; 200 } 201 202 210 public void setConditionVariableValue(_Reference[] references, 211 Object [] values, int priority) throws 212 DException { 213 if(underlyingRef!=null){ 214 references = GeneralPurposeStaticClass.getJointReferences(references,underlyingRef); 215 values = GeneralPurposeStaticClass.getJointValues(this, values,underlyingRef.length); 216 } 217 218 super.setConditionVariableValue(references, values, priority); 219 conditionVariableValue.setVariableValues(references, values, priority); 220 for (int i = 0; i < indexPredicate.length; i++) { 221 ( (ConditionVariableValue) indexPredicate[i]).setVariableValues(references, values, priority); 222 } 223 } 224 225 236 public boolean seekFromTopRelative(Object indexKey) throws com.daffodilwoods. 237 database.resource.DException { 238 while (true) { 239 boolean next = iterator.seekFromTopRelative(indexKey); 240 241 try { 242 next = next ? conditionVariableValue.run().hashCode() == 0 : next; 243 state = next ? VALIDSTATE : AFTERLAST; 244 } 245 catch (DException de) { 246 if (de.getDseCode().equalsIgnoreCase("DSE2004")) 247 continue; 248 else 249 throw de; 250 } 251 return next; 252 } 253 } 254 255 265 public boolean seekFromBottomRelative(Object indexKey) throws com. 266 daffodilwoods.database.resource.DException { 267 while (true) { 268 boolean prev = iterator.seekFromBottomRelative(indexKey); 269 try { 270 prev = prev ? conditionVariableValue.run().hashCode() == 0 : prev; 271 state = prev ? VALIDSTATE : BEFOREFIRST; 272 } 273 catch (DException de) { 274 if (de.getDseCode().equalsIgnoreCase("DSE2004")) 275 continue; 276 else 277 throw de; 278 } 279 return prev; 280 } 281 } 282 283 288 public Object getKey() throws com.daffodilwoods.database.resource.DException { 289 return iterator.getKey(); 290 } 291 292 297 public void move(Object parm1) throws com.daffodilwoods.database.resource. 298 DException { 299 iterator.move(parm1); 300 state = VALIDSTATE; 301 } 302 303 311 public Object getColumnValues(int[] parm1) throws com.daffodilwoods.database. 312 resource.DException { 313 return iterator.getColumnValues(parm1); 314 } 315 316 323 public Object getColumnValues() throws DException { 324 if (state != VALIDSTATE) 325 throw new DException("DSE2019", new Object [] {new Integer (state)}); 326 return iterator.getColumnValues(); 327 } 328 329 335 public TableDetails[] getTableDetails() throws com.daffodilwoods.database. 336 resource.DException { 337 return iterator.getTableDetails(); 338 } 339 340 347 public _Iterator getBaseIterator(ColumnDetails column) throws com. 348 daffodilwoods.database.resource.DException { 349 return iterator.getBaseIterator(column); 350 } 351 352 public _KeyColumnInformation[] getKeyColumnInformations() throws DException { 353 _KeyColumnInformation[] key = iterator.getKeyColumnInformations(); 354 return key; 355 } 356 357 366 public Object getColumnValues(_Reference references) throws DException { 367 if (state != VALIDSTATE) 368 throw new DException("DSE2019", new Object [] {new Integer (state)}); 369 try { 370 return iterator.getColumnValues(references); 371 } 372 catch (ArrayIndexOutOfBoundsException E) { 373 throw E; 374 } 375 } 376 377 public _ExecutionPlan getExecutionPlan() throws DException { 378 _ExecutionPlan cplan = iterator.getExecutionPlan(); 379 _ExecutionPlan cplans[] = cplan == null ? null : new _ExecutionPlan[] { 380 cplan}; 381 int length = indexPredicate == null ? 0 : indexPredicate.length; 382 String condition = "Index Condition : "; 383 for (int i = 0; i < length; i++) { 384 condition += indexPredicate[i] + " , "; 385 } 386 387 condition += " And Non Index Condition : "; 388 ExecutionPlan plan = new ExecutionPlan("IndexedFilterIterator", cplans, 389 condition + conditionVariableValue, null, null); 390 return plan; 391 } 392 393 public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException { 394 ExecutionPlanForBrowser cplan = iterator.getExecutionPlanForBrowser(); 395 ExecutionPlanForBrowser cplans[] = cplan == null ? null : 396 new ExecutionPlanForBrowser[] { 397 cplan}; 398 int length = indexPredicate == null ? 0 : indexPredicate.length; 399 String condition = ""; 400 for (int i = 0; i < length; i++) { 401 condition += indexPredicate[i] + " , "; 402 } 403 ExecutionPlanForBrowser plan = new ExecutionPlanForBrowser("Index Seek " + 404 condition, "IndexedFilterIterator", cplans, "" + conditionVariableValue, null, null); 405 return plan; 406 } 407 408 414 public void releaseResource() throws DException { 415 super.releaseResource(); 416 conditionVariableValue.releaseResource(); 417 for (int i = 0; i < indexPredicate.length; i++) { 418 ( (ConditionVariableValue) indexPredicate[i]).releaseResource(); 419 } 420 } 421 422 427 public _Record getRecord() throws com.daffodilwoods.database.resource. 428 DException { 429 return iterator.getRecord(); 430 } 431 432 437 438 439 public void delete() throws com.daffodilwoods.database.resource.DException { 440 ( (_TableOperations) iterator).delete(); 441 } 442 443 public void insert(_DatabaseUser parm1, Object parm2) throws com. 444 daffodilwoods.database.resource.DException { 445 ( (_UserTableOperations) iterator).insert(parm1, parm2); 446 } 447 448 public void update(_DatabaseUser parm1, Object parm2) throws com. 449 daffodilwoods.database.resource.DException { 450 ( (_UserTableOperations) iterator).update(parm1, parm2); 451 } 452 453 public void update(_DatabaseUser parm1, int[] parm2, Object [] parm3) throws 454 com.daffodilwoods.database.resource.DException { 455 ( (_UserTableOperations) iterator).update(parm1, parm2, parm3); 456 } 457 458 public void delete(_DatabaseUser parm1) throws com.daffodilwoods.database. 459 resource.DException { 460 ( (_UserTableOperations) iterator).delete(parm1); 461 } 462 463 public void insert(Object parm1) throws com.daffodilwoods.database.resource. 464 DException { 465 ( (_TableOperations) iterator).insert(parm1); 466 } 467 468 public void update(Object parm1) throws com.daffodilwoods.database.resource. 469 DException { 470 ( (_TableOperations) iterator).update(parm1); 471 } 472 473 public void update(int[] parm1, Object [] parm2) throws com.daffodilwoods. 474 database.resource.DException { 475 ( (_TableOperations) iterator).update(parm1, parm2); 476 } 477 478 public Object [] getUniqueColumnReference() throws DException { 479 return backUpIterator.getUniqueColumnReference(); 480 } 481 482 public boolean seek(Object indexKey) throws DException { 483 boolean b = iterator.seek(indexKey); 484 if (b) 485 state = VALIDSTATE; 486 return b; 487 } 488 489 public int getBtreeIndex() throws com.daffodilwoods.database.resource. 490 DException { 491 return ( (_IndexIteratorInfo) iterator).getBtreeIndex(); 492 } 493 494 public boolean locateKey(Object parm1, boolean parm2) throws com. 495 daffodilwoods.database.resource.DException { 496 if ( ( (_IndexIteratorInfo) iterator).locateKey(parm1, parm2)) 497 return conditionVariableValue.run().hashCode() != 0 ? 498 parm2 ? next() : previous() : 499 true; 500 return false; 501 } 502 503 public _Order getDefaultOrder() throws DException { 504 return iterator.getDefaultOrder(); 505 } 506 507 public void ensureRecordInMemory() throws com.daffodilwoods.database.resource. 508 DException { 509 ( (_IndexIteratorInfo) iterator).ensureRecordInMemory(); 510 } 511 512 public void moveOnActualKey(Object parm1) throws com.daffodilwoods.database. 513 resource.DException { 514 ( (_IndexIteratorInfo) iterator).moveOnActualKey(parm1); 515 } 516 517 public Object getActualKey() throws com.daffodilwoods.database.resource. 518 DException { 519 return ( (_IndexIteratorInfo) iterator).getActualKey(); 520 } 521 522 public Object getPhysicalAddress() throws com.daffodilwoods.database.resource. 523 DException { 524 return ( (_IndexIteratorInfo) iterator).getPhysicalAddress(); 525 } 526 527 public _Iterator getForeignKeyIterator() throws DException { 528 return iterator; 529 } 530 531 public boolean seekKeyAddress(Object parm1) throws com.daffodilwoods.database. 532 resource.DException { 533 throw new java.lang.UnsupportedOperationException ( 534 "Method seekKeyAddress() not yet implemented."); 535 } 536 537 public SuperComparator getComparator() { 538 return ( (_IndexIteratorInfo) iterator).getComparator(); 539 } 540 541 public SuperComparator getObjectComparator() throws DException { 542 return ( (_IndexIteratorInfo) backUpIterator).getObjectComparator(); 543 } 544 545 public byte[] getByteKey() throws DException { 546 return iterator.getByteKey(); 547 } 548 public void moveByteKey(byte[] key) throws DException { 549 iterator.moveByteKey(key); 550 state = VALIDSTATE; 551 } 552 public void deleteBlobClobRecord(_DatabaseUser user) throws com.daffodilwoods.database.resource.DException { 553 ( (_TableOperations) iterator).deleteBlobClobRecord(user) ; 554 } 555 556 557 } 558 | Popular Tags |