| 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 import java.util.*; 10 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.*; 11 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 12 import com.daffodilwoods.daffodildb.server.datasystem.utility.*; 13 import com.daffodilwoods.daffodildb.server.sql99.common.*; 14 15 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 16 import com.daffodilwoods.database.resource.*; 17 import com.daffodilwoods.database.utility.*; 18 import com.daffodilwoods.database.sqlinitiator._Order; 19 import com.daffodilwoods.daffodildb.client._ExecutionPlan; 20 import com.daffodilwoods.daffodildb.client.ExecutionPlan; 21 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 22 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator; 23 24 29 public class RepetableIterator implements _Iterator, _TableOperations, _UserTableOperations, _IndexIteratorInfo { 30 _Iterator[] iterators; 31 34 35 protected Object currentKey; 36 SuperComparator comparator; 37 protected int status ; 38 39 40 45 protected HashMap exMap; 46 47 BitSet currentIteratorSet; 48 49 50 public RepetableIterator(_Iterator[] iterators0, SuperComparator comparator0) { 51 iterators = iterators0; 52 comparator = comparator0; 53 status = -1; 54 exMap = new HashMap(); 55 currentIteratorSet = new BitSet(); 56 } 57 58 59 public void setKeyCount(Object [][] tableAndKeyCount) throws DException { 60 61 throw new java.lang.UnsupportedOperationException ("Method setKeyCount() not yet implemented."); 62 } 63 64 68 69 70 public boolean first() throws DException{ 71 72 int hasFirst = 0; 73 _Key[] keys = new _Key[iterators.length]; 74 for(int i = 0 ; i < iterators.length ; i++){ 75 if(iterators[i] != null && iterators[i].first()){ 76 hasFirst += 1; 77 keys[i] = (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey(); 78 } 79 80 } 81 if( hasFirst == 0) 82 return false; 83 getLowestKey(keys); 84 return true; 85 } 86 87 91 92 public boolean last() throws DException{ 93 int hasLast = 0; 94 _Key[] keys = new _Key[iterators.length]; 95 for(int i = 0 ; i < iterators.length ; i++){ 96 if(iterators[i] != null && iterators[i].last()){ 97 hasLast += 1; 98 keys[i] = (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey(); 99 } 100 } 101 if(hasLast == 0 ) 102 return false; 103 getHighestKey(keys); 104 return true; 105 } 106 107 108 112 113 public boolean next() throws DException{ 114 int hasNext = 0; 115 _Key[] keys = new _Key[iterators.length]; 116 for(int i = 0 ; i < iterators.length ; i++){ 117 if(currentIteratorSet.get(i)){ 118 if(iterators[i].next()){ 119 hasNext++; 120 keys[i] = (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey(); 121 } 122 } 123 else{ 124 hasNext += (keys[i] = (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey()) == null ? 0 : 1; 125 } 126 } 127 if(hasNext == 0){ 128 ; return false; 130 } 131 getLowestKey(keys); 132 return true; 133 } 134 135 136 137 141 142 public boolean previous() throws DException{ 143 int hasPrevious = 0; 144 _Key[] keys = new _Key[iterators.length]; 145 for(int i = 0 ; i < iterators.length ; i++){ 146 if(iterators[i] == null) 147 continue; 148 if(currentIteratorSet.get(i) ){ 149 if(iterators[i].previous()){ 150 hasPrevious += 1; 151 keys[i] = (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey(); 152 } 153 } 154 else{ 155 keys[i] = (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey(); 156 hasPrevious += keys[i] == null ? 0 : 1; 157 } 158 } 159 if(hasPrevious == 0) 160 return false; 161 getHighestKey(keys); 162 return true; 163 } 164 165 public Object getKey() throws DException{ 166 for(int i = 0 ; i < iterators.length ; i++) 167 if(currentIteratorSet.get(i)) 168 return iterators[i].getKey(); 169 return null; 170 } 171 172 173 178 179 public void move(Object key) throws DException{ 180 if(key == null) 181 return; 182 for(int i = 0 ; i < iterators.length ; i++) 183 if(iterators[i] != null){ 184 iterators[i].move(key); 185 } 186 } 187 188 193 194 public Object getColumnValues(int[] columns) throws DException { 195 for(int i = 0 ; i < iterators.length ; i++){ 196 if(currentIteratorSet.get(i)){ 197 return iterators[i].getColumnValues(columns); 198 } 199 } 200 return null; 201 } 202 203 public void show(boolean flag) throws DException{ 204 ArrayList list = new ArrayList(); 205 if(first()){ 206 do{ 207 Object obj = getColumnValues((int[])null); 208 if(flag) 209 list.add(obj); 210 }while(next()); 211 } 212 else 213 ; } 215 216 217 222 223 224 public _KeyColumnInformation[] getKeyColumnInformations() throws DException { 225 return iterators[0].getKeyColumnInformations(); 226 } 227 228 public Object [] getUniqueColumnReference() throws DException { 229 return iterators[0].getUniqueColumnReference(); 230 } 231 232 public SuperComparator getComparator() { 233 return comparator; 234 } 235 236 237 public Object getColumnValues(_Reference[] parm1) throws com.daffodilwoods.database.resource.DException { 238 for(int i = 0 ; i < iterators.length ; i++) 239 if(currentIteratorSet.get(i)) 240 return iterators[i].getColumnValues(parm1); 241 return null; 242 } 243 244 public Object getColumnValues() throws com.daffodilwoods.database.resource.DException { 245 for(int i = 0 ; i < iterators.length ; i++) 246 if(currentIteratorSet.get(i)) 247 return iterators[i].getColumnValues(); 248 return null; 249 } 250 251 252 protected void getLowestKey(Object [] values) throws DException{ 253 BitSet flag = new BitSet(); 254 if(values[0] == null){ 255 flag.set(1); 256 currentIteratorSet = flag; 257 return; 258 } 259 else if (values[1] == null){ 260 flag.set(0); 261 currentIteratorSet = flag; 262 return; 263 } 264 265 Object keyValues0 = ((_Key)values[0]).getKeyValue(); 266 Object keyValues1 = ((_Key)values[1]).getKeyValue(); 267 268 int cmp = comparator.compare(keyValues0,keyValues1); 269 if(cmp == 0){ 270 flag.set(1); 271 flag.set(0); 272 currentIteratorSet = flag; 273 } 274 else if(cmp < 0){ 275 flag.set(0); 276 currentIteratorSet = flag; 277 } 278 else{ 279 flag.set(1); 280 currentIteratorSet = flag; 281 } 282 } 283 284 protected void getHighestKey(Object [] values) throws DException{ 285 286 BitSet flag = new BitSet(); 287 if(values[0] == null){ 288 flag.set(1); 289 currentIteratorSet = flag; 290 return; 291 } 292 else if (values[1] == null){ 293 flag.set(0); 294 currentIteratorSet = flag; 295 return; 296 } 297 Object keyValues0 = ((_Key)values[0]).getKeyValue(); 298 Object keyValues1 = ((_Key)values[1]).getKeyValue(); 299 int cmp = comparator.compare(keyValues0,keyValues1); 300 if(cmp == 0){ 301 flag.set(0); 302 flag.set(1); 303 currentIteratorSet = flag; 304 } 305 else if(cmp > 0){ 306 flag.set(0); 307 currentIteratorSet = flag; 308 } 309 else{ 310 flag.set(1); 311 currentIteratorSet = flag; 312 } 313 } 314 315 public boolean seek(Object indexKey) throws DException { 316 if(!iterators[0].seek(indexKey)){ 317 boolean flagOfSecondIterator = iterators[1] != null ? iterators[1].seek(indexKey) : false; 318 if(!flagOfSecondIterator) 319 return false; 320 iterators[0].seek(indexKey); 321 } 322 else if(iterators[1] != null) 323 iterators[1].seek(indexKey); 324 setLowestKey(); 325 status = 0; 326 return true; 327 } 328 329 public boolean seekFromBottomRelative(Object indexKey) throws DException { 330 int length = iterators.length; 331 _Key[] keys = new _Key[length]; 332 int num = 0; 333 for (int i = 0; i < length; i++) { 334 boolean flag = iterators[i] != null ? iterators[i].seekFromBottomRelative(indexKey) : false; 335 if(flag){ 336 keys[i] = (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey(); 337 num++; 338 } 339 } 340 if(num == 0) 341 return false; 342 getHighestKey(keys); 343 return true; 344 345 } 346 347 public boolean seekFromTopRelative(Object indexKey) throws DException { 348 int length = iterators.length; 349 _Key[] keys = new _Key[length]; 350 int num = 0; 351 for (int i = 0; i < length; i++) { 352 boolean flag = iterators[i] != null ? iterators[i].seekFromTopRelative(indexKey) : false; 353 if(flag){ 354 keys[i] = (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey(); 355 num++; 356 } 357 } 358 if(num == 0 ) 359 return false; 360 getLowestKey(keys); 361 return true; 362 } 363 364 public boolean seekFromTop(_IndexPredicate[] condition) throws DException { 365 if(!iterators[0].seekFromTop(condition)){ 366 boolean flagOfSecondIterator = iterators[1] != null ? iterators[1].seekFromTop(condition) : false; 367 if(!flagOfSecondIterator) 368 return false; 369 ((_IndexIteratorInfo)iterators[0]).locateKey(((_Key)((_IndexIteratorInfo)iterators[1]).getActualKey()).getKeyValue(),true); 370 } 371 else if(iterators[1] != null) 372 ((_IndexIteratorInfo)iterators[1]).locateKey(((_Key)((_IndexIteratorInfo)iterators[0]).getActualKey()).getKeyValue(),true); 373 setLowestKey(); 374 status = 0; 375 return true; 376 } 377 378 public boolean seekFromBottom(_IndexPredicate[] condition) throws DException { 379 if(!iterators[0].seekFromBottom(condition)){ 380 boolean flagOfSecondIterator = iterators[1] != null ? iterators[1].seekFromBottom(condition) : false; 381 if(!flagOfSecondIterator) 382 return false; 383 ((_IndexIteratorInfo)iterators[0]).locateKey(((_Key)((_IndexIteratorInfo)iterators[1]).getActualKey()).getKeyValue(),false); 384 } 385 else if(iterators[1] != null) 386 ((_IndexIteratorInfo)iterators[1]).locateKey(((_Key)((_IndexIteratorInfo)iterators[0]).getActualKey()).getKeyValue(),false); 387 setHighestKey(); 388 status = 0; 389 return true; 390 } 391 392 393 394 395 396 397 private void setLowestKey() throws DException{ 398 int length = iterators.length; 399 _Key[] keys = new _Key[length]; 400 for (int i = 0; i < length; i++) { 401 keys[i] = iterators[i] != null ? (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey() : null; 402 } 403 getLowestKey(keys); 404 } 405 406 private void setHighestKey() throws DException{ 407 int length = iterators.length; 408 _Key[] keys = new _Key[length]; 409 for (int i = 0; i < length; i++) { 410 keys[i] = iterators[i] != null ? (_Key)((_IndexIteratorInfo)iterators[i]).getActualKey() : null; 411 } 412 getHighestKey(keys); 413 } 414 415 416 417 public void delete(_DatabaseUser user) throws DException { 418 if (currentIteratorSet.get(0)) 419 ( (_TableOperations) iterators[0]).delete(); 420 else 421 if (currentIteratorSet.get(1)) 422 ( (_TableOperations) iterators[1]).delete(); 423 } 424 425 public void delete() throws DException { 426 if (currentIteratorSet.get(0)) 427 ( (_TableOperations) iterators[0]).delete(); 428 else 429 if (currentIteratorSet.get(1)) 430 ( (_TableOperations) iterators[1]).delete(); 431 432 } 433 434 public void insert(_DatabaseUser user,Object values) throws DException { 435 if (currentIteratorSet.get(0)) 436 ((_UserTableOperations)iterators[0]).insert(user,values); 437 else 438 if (currentIteratorSet.get(1)) 439 ((_UserTableOperations)iterators[1]).insert(user,values); 440 441 } 442 443 public void insert(Object values) throws DException { 444 if (currentIteratorSet.get(0)) 445 ((_TableOperations)iterators[0]).insert(values); 446 else 447 if (currentIteratorSet.get(1)) 448 ( (_TableOperations) iterators[1]).insert(values); 449 450 } 451 452 public void update(Object values) throws DException { 453 if(currentIteratorSet.get(0)) 454 ((_TableOperations)iterators[0]).update(values); 455 else if(currentIteratorSet.get(1)) 456 ((_TableOperations)iterators[1]).update(values); 457 458 } 459 460 public void update(_DatabaseUser user,Object values) throws DException { 461 if(currentIteratorSet.get(0)) 462 ((_UserTableOperations)iterators[0]).update(user,values); 463 else if(currentIteratorSet.get(1)) 464 ((_UserTableOperations)iterators[1]).update(user,values); 465 466 } 467 468 public void update(int [] columns,Object [] values) throws DException { 469 if(currentIteratorSet.get(0)) 470 ((_TableOperations)iterators[0]).update(columns,values); 471 else if(currentIteratorSet.get(1)) 472 ((_TableOperations)iterators[1]).update(columns,values); 473 474 } 475 476 public void update(_DatabaseUser user,int [] columns,Object [] values) throws DException { 477 if(currentIteratorSet.get(0)) 478 ((_UserTableOperations)iterators[0]).update(user,columns,values); 479 else if(currentIteratorSet.get(1)) 480 ((_UserTableOperations)iterators[1]).update(user,columns,values); 481 482 } 483 484 485 486 487 public _OrderCount getOrderCounts() throws com.daffodilwoods.database.resource.DException { 488 489 throw new java.lang.UnsupportedOperationException ("Method getOrderCounts() not yet implemented."); 490 } 491 public TableDetails[] getTableDetails() throws com.daffodilwoods.database.resource.DException { 492 493 throw new java.lang.UnsupportedOperationException ("Method getTableDetails() not yet implemented."); 494 } 495 public _Iterator getBaseIterator(ColumnDetails column) throws com.daffodilwoods.database.resource.DException { 496 497 throw new java.lang.UnsupportedOperationException ("Method getBaseIterator() not yet implemented."); 498 } 499 public _Iterator getBaseIteratorHasRecord(ColumnDetails parm1) throws com.daffodilwoods.database.resource.DException { 500 501 throw new java.lang.UnsupportedOperationException ("Method getBaseIterator() not yet implemented."); 502 } 503 public void setConditionVariableValue(_Reference[] parm1, Object [] parm2, int parm3) throws com.daffodilwoods.database.resource.DException { 504 for (int i = 0; i < iterators.length; i++) { 505 iterators[i].setConditionVariableValue(parm1,parm2,parm3); 506 } 507 508 } 509 public Object getColumnValues(_Reference parm1) throws com.daffodilwoods.database.resource.DException { 510 for(int i = 0 ; i < iterators.length ; i++) 511 if(currentIteratorSet.get(i)) 512 return iterators[i].getColumnValues(parm1); 513 return null; 514 } 515 public void setIterator(_Iterator parm1) throws com.daffodilwoods.database.resource.DException { 516 517 throw new java.lang.UnsupportedOperationException ("Method setIterator() not yet implemented."); 518 } 519 public void addReferences(_Reference[] parm1) throws com.daffodilwoods.database.resource.DException { 520 521 throw new java.lang.UnsupportedOperationException ("Method addReferences() not yet implemented."); 522 } 523 public Object [][] getReferenceAndValuePair() throws com.daffodilwoods.database.resource.DException { 524 525 throw new java.lang.UnsupportedOperationException ("Method getReferenceAndValuePair() not yet implemented."); 526 } 527 public _Record getRecord() throws com.daffodilwoods.database.resource.DException { 528 for(int i = 0 ; i < iterators.length ; i++) 529 if(currentIteratorSet.get(i)) 530 return iterators[i].getRecord(); 531 return null; 532 } 533 public _Order getDefaultOrder() throws com.daffodilwoods.database.resource.DException { 534 535 throw new java.lang.UnsupportedOperationException ("Method getDefaultOrder() not yet implemented."); 536 } 537 public int getBtreeIndex() throws com.daffodilwoods.database.resource.DException { 538 539 throw new java.lang.UnsupportedOperationException ("Method getBtreeIndex() not yet implemented."); 540 } 541 public boolean locateKey(Object parm1, boolean parm2) throws com.daffodilwoods.database.resource.DException { 542 543 throw new java.lang.UnsupportedOperationException ("Method locateKey() not yet implemented."); 544 } 545 546 public void ensureRecordInMemory() throws com.daffodilwoods.database.resource.DException { 547 if (currentIteratorSet.get(1)) 548 ((_IndexIteratorInfo)iterators[1]).ensureRecordInMemory(); 549 else 550 ((_IndexIteratorInfo)iterators[0]).ensureRecordInMemory(); 551 } 552 public void moveOnActualKey(Object parm1) throws com.daffodilwoods.database.resource.DException { 553 554 throw new java.lang.UnsupportedOperationException ("Method moveOnActualKey() not yet implemented."); 555 } 556 public Object getActualKey() throws com.daffodilwoods.database.resource.DException { 557 558 throw new java.lang.UnsupportedOperationException ("Method getActualKey() not yet implemented."); 559 } 560 public _ExecutionPlan getExecutionPlan() throws DException{ 561 int length = iterators.length; 562 _ExecutionPlan cplans[] = new _ExecutionPlan[length]; 563 for (int i = 0; i < length; i++) { 564 cplans[i] = iterators[i].getExecutionPlan(); 565 } 566 return new ExecutionPlan("RepetableIterator",cplans,null,null,null); 567 } 568 public boolean seekKeyAddress(Object parm1) throws com.daffodilwoods.database.resource.DException { 569 570 throw new java.lang.UnsupportedOperationException ("Method seekKeyAddress() not yet implemented."); 571 } 572 public Object getPhysicalAddress() throws com.daffodilwoods.database.resource.DException { 573 574 throw new java.lang.UnsupportedOperationException ("Method getPhysicalAddress() not yet implemented."); 575 } 576 577 public Object [][] getFunctionalColumnMapping() throws DException { 578 579 throw new UnsupportedOperationException ("getFunctionalColumnMapping() Not Supported"); 580 } 581 582 public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException { 583 throw new UnsupportedOperationException ("Method Not Supported"); 584 } 585 public SuperComparator getObjectComparator() throws com.daffodilwoods.database.resource.DException { 586 return comparator; 587 } 588 public FieldBase field(_Reference reference) throws com.daffodilwoods.database.resource.DException { 589 for(int i = 0 ; i < iterators.length ; i++) 590 if(currentIteratorSet.get(i)) 591 return iterators[i].field(reference); 592 return null; 593 } 594 public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods.database.resource.DException { 595 for(int i = 0 ; i < iterators.length ; i++) 596 if(currentIteratorSet.get(i)) 597 return iterators[i].fields(references); 598 return null; 599 } 600 public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database.resource.DException { 601 for(int i = 0 ; i < iterators.length ; i++){ 602 if(currentIteratorSet.get(i)){ 603 return iterators[i].fields(columns); 604 } 605 } 606 return null; 607 } 608 public void releaseResource() throws DException { 609 610 } 611 612 public String toString(){ 613 String abc = "REPEATABLE "; 614 for (int i = 0; i < iterators.length; i++) { 615 abc += iterators[i].toString(); 616 } 617 return abc; 618 } 619 public byte[] getByteKey() throws DException{ 620 throw new java.lang.UnsupportedOperationException ( 621 "Method getByteKey() not yet implemented."); 622 } 623 public void moveByteKey(byte[] key) throws DException{ 624 throw new java.lang.UnsupportedOperationException ( 625 "Method moveByteKey() not yet implemented."); 626 } 627 628 public void setSpecificUnderlyingReferences(_Reference[] specificUnderlyingReferences) throws DException{ 629 throw new java.lang.UnsupportedOperationException ( 630 "Method not yet implemented."); 631 } 632 633 public void deleteBlobClobRecord( _DatabaseUser user) throws DException { 634 if (currentIteratorSet.get(0)) 635 ( (_TableOperations) iterators[0]).deleteBlobClobRecord(user) ; 636 else 637 if (currentIteratorSet.get(1)) 638 ( (_TableOperations) iterators[1]).deleteBlobClobRecord(user) ; 639 640 } 641 642 643 } 644 | Popular Tags |