1 package com.daffodilwoods.daffodildb.server.datasystem.indexsystem; 2 3 4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 5 import com.daffodilwoods.daffodildb.server.datasystem.utility.*; 6 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record; 7 import com.daffodilwoods.daffodildb.server.sql99.common.*; 8 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 9 import com.daffodilwoods.daffodildb.utils.*; 10 import com.daffodilwoods.daffodildb.utils.comparator.*; 11 import com.daffodilwoods.daffodildb.utils.field.*; 12 import com.daffodilwoods.database.general.*; 13 import com.daffodilwoods.database.resource.*; 14 import com.daffodilwoods.daffodildb.server.datasystem.btree.TableScanKey; 15 16 24 25 public class TableScanIterator implements _IndexIterator,_UserTableOperations,_TableOperations, _SingleIterator, _IndexIteratorInfo, _UniqueIterator{ 26 27 30 31 private _IndexTableList indexTable; 32 private IndexTableIterator indexTableIterator; 33 34 37 38 41 42 private _TableIterator iterator; 43 44 45 48 49 50 51 52 57 58 private int status; 59 60 61 62 63 64 public TableScanIterator(IndexTableIterator indexTableIterator0 ,_TableIterator iterator0,_IndexTableList indexTable0) { 65 iterator = iterator0; 66 indexTable = indexTable0; 67 indexTableIterator = indexTableIterator0; 68 status = -1; 69 } 70 public TableScanIterator(IndexTableIterator indexTableIterator0 ) { 71 indexTableIterator = indexTableIterator0; 72 iterator = indexTableIterator.getUnderlyingIterator() ; 73 indexTable = indexTableIterator.getIndexTable() ; 74 75 status = -1; 76 } 77 78 79 84 85 public boolean first() throws DException { 86 return iterator.first() ? setKeyAndStatus(0,true,"first") : setKeyAndStatus(-1,false,"first"); 87 93 } 94 95 100 101 public boolean last() throws DException { 102 return iterator.last() ? setKeyAndStatus(0,true,"last") : setKeyAndStatus(1,false,"last"); 103 110 } 111 112 118 119 public boolean next() throws DException { 120 121 if(status != 0) return status == 1 ? false : first(); 122 boolean next = iterator.next() ; 123 return next ? setKeyAndStatus(0,true,"next") : setKeyAndStatus(1,false,"next"); 124 131 } 132 133 139 140 public boolean previous() throws DException { 141 if(status != 0) return status == -1 ? false : last(); 142 return iterator.previous() ? setKeyAndStatus(0,true,"previous") : setKeyAndStatus(-1,false,"previous"); 143 150 } 151 152 158 159 public void insert(Object value) throws DException { 160 indexTableIterator.insert(value); 161 iterator.move( indexTableIterator.getPhysicalAddress() ); 162 163 } 164 165 166 171 172 public void update(Object value) throws DException { 173 if(indexTableIterator.seek(getColumnValues(SystemFields.rowId ) ) ) 174 indexTableIterator.update(value ); 175 186 } 187 188 194 195 public void update(int[] columns, Object [] value) throws DException { 196 if(indexTableIterator.seek(getColumnValues(SystemFields.rowId ) ) ) 197 indexTableIterator.update(columns,value); 198 213 } 214 215 219 220 public void delete() throws DException { 221 if(indexTableIterator.seek(getColumnValues(SystemFields.rowId ) ) ) 222 indexTableIterator.delete() ; 223 233 } 234 235 240 241 242 public Object getKey() throws DException { 243 if(status != 0){ 244 return null; 245 } 246 247 TableScanKey tskey = new TableScanKey(getColumnValues(SystemFields.rowId )); 248 return tskey; 249 } 250 251 257 public Object getColumnValues(int[] columns) throws DException { 258 try { 259 if(status != 0){ 260 throw new DException("DSE2019", new Object [] {new Integer (status)}); 261 } 262 BufferRange[] buff = columns == null ? (BufferRange[])iterator.getColumnValues() : (BufferRange[])iterator.getColumnValues(columns); 263 FieldBase[] array = new FieldBase[buff.length]; 264 _TableCharacteristics tc = indexTable.getTableCharacteristics(); 265 boolean flag = columns == null; 266 for (int i = 0; i < buff.length; i++) { 267 array[i] = (FieldBase)tc.getObject(flag ? i : columns[i],buff[i]); 268 } 269 return array; 270 } 271 catch (DException ex) { 272 if(!ex.getDseCode().equals("DSE2045")) 273 throw ex; 274 } 275 return null; 276 288 } 289 290 public boolean seekFromTop(_IndexPredicate[] condition ) throws DException { 291 return indexTableIterator.seekFromTop(condition); 292 305 } 306 307 public boolean seekFromBottom(_IndexPredicate[] condition ) throws DException { 308 return indexTableIterator.seekFromBottom(condition); 309 321 } 322 323 public Object [] show(boolean flag) throws DException{ 324 return null; 339 } 340 341 348 349 public void insert(_DatabaseUser user, Object value) throws DException { 350 indexTableIterator.insert(user,value); 351 iterator.move( indexTableIterator.getPhysicalAddress() ); 352 353 360 } 361 362 368 369 public void update(_DatabaseUser user, Object value) throws DException { 370 if(indexTableIterator.seek(getColumnValues(SystemFields.rowId ) ) ) 371 indexTableIterator.update(user,value); 372 384 } 385 386 393 394 public void update(_DatabaseUser user, int[] columns, Object [] value) throws DException { 395 if(indexTableIterator.seek(getColumnValues(SystemFields.rowId ) ) ) 396 indexTableIterator.update(user,columns,value ); 397 411 } 412 413 418 419 public void delete(_DatabaseUser user) throws DException { 420 if(indexTableIterator.seek(getColumnValues(SystemFields.rowId ) ) ) 421 indexTableIterator.delete(user); 422 432 } 433 434 public _Record getRecord() throws DException { 435 _Record record = new Record(indexTable.getTableCharacteristics(),null); 436 record.setObject((Object [])getColumnValues()); 437 return record; 438 } 439 440 public Object getColumnValues(_Reference[] references) throws DException { 441 if(status != 0){ 442 throw new DException("DSE2019",new Object [] {new Integer (status)}); 443 } 444 int[] columns = new int[references.length]; 445 _TableCharacteristics tc = indexTable.getTableCharacteristics(); 446 for (int i = 0; i < references.length; i++) 447 columns[i] = getColumn(references[i],tc); 448 return getColumnValues(columns); 449 467 } 468 469 public boolean seek(Object indexKey ) throws DException { 470 if(indexTableIterator.seek(indexKey)) { 471 iterator.move( indexTableIterator.getPhysicalAddress() ); 472 setKeyAndStatus(0,true,"seek"); 473 } 474 return false; 486 } 487 488 public _KeyColumnInformation[] getKeyColumnInformations() throws DException { 489 return indexTableIterator.getKeyColumnInformations() ; 490 509 } 510 511 512 public Object [] getUniqueColumnReference() throws DException{ 513 return indexTableIterator.getUniqueColumnReference(); 514 } 515 516 public int getBtreeIndex() throws DException{ 517 return indexTableIterator.getBtreeIndex() ; 518 } 519 520 public SuperComparator getComparator() { 521 return indexTableIterator.getComparator(); 522 } 523 524 public boolean readjust(Object updatedKey,Object secondKey) throws DException { 525 return indexTableIterator.readjust(updatedKey,secondKey); 526 534 } 535 536 public boolean seekFromTopRelative(Object indexKey) throws com.daffodilwoods.database.resource.DException { 537 return false; 555 } 556 557 public boolean seekFromBottomRelative(Object indexKey) throws com.daffodilwoods.database.resource.DException { 558 return false; 576 } 577 578 public _TableCharacteristics getTableCharacteristics() throws DException{ 579 return indexTable.getTableCharacteristics(); 580 } 581 582 public _IndexInformation[] getUniqueInformation() throws DException{ 583 return indexTable.getIndexInformations(); 584 } 585 586 protected boolean setKeyAndStatus(int num,boolean flag,String str) throws DException{ 587 status = num; 588 return flag; 589 } 590 591 public boolean locateKey(Object indexKey,boolean flag) throws com.daffodilwoods.database.resource.DException { 592 return false; 607 } 608 609 public Object getColumnValues(int column) throws DException { 610 return ((Object [])getColumnValues(new int[]{column}))[0]; 611 629 } 630 631 public Object getColumnValues() throws DException { 632 try { 633 if(status != 0) 634 throw new DException("DSE2019",new Object [] {new Integer (status)}); 635 BufferRange[] buff = (BufferRange[])iterator.getColumnValues() ; 636 FieldBase[] array = new FieldBase[buff.length]; 637 _TableCharacteristics tc = indexTable.getTableCharacteristics(); 638 for (int i = 0; i < buff.length; i++) { 639 array[i] = (FieldBase)tc.getObject(i,buff[i]); 640 } 641 return array; 642 } 643 catch (DException ex) { 644 if(!ex.getDseCode().equals("DSE2045")) 645 throw ex; 646 } 647 return null; 648 649 658 } 659 660 661 662 public Object getColumnValues(_Reference references) throws com.daffodilwoods.database.resource.DException { 663 return getColumnValues(new _Reference[]{references}); 664 685 } 686 687 public SuperComparator getObjectComparator() throws DException{ 688 return indexTableIterator.getComparator(); 689 } 690 691 public boolean seekKeyAddress(Object parm1) throws com.daffodilwoods.database.resource.DException { 692 iterator.move(parm1); 693 Object seekKey = iterator.getColumnValues((int[])getUniqueColumnReference()[0]); 694 return seek(seekKey); 695 } 696 697 public Object getPhysicalAddress() throws com.daffodilwoods.database.resource.DException { 698 return indexTableIterator.getPhysicalAddress(); 699 } 700 701 public void ensureRecordInMemory() throws com.daffodilwoods.database.resource.DException { 702 703 throw new java.lang.UnsupportedOperationException ("Method ensureRecordInMemory() not yet implemented."); 704 } 705 706 public void moveOnActualKey(Object parm1) throws com.daffodilwoods.database.resource.DException { 707 708 throw new java.lang.UnsupportedOperationException ("Method moveOnActualKey() not yet implemented."); 709 } 710 711 public Object getActualKey() throws com.daffodilwoods.database.resource.DException { 712 713 throw new java.lang.UnsupportedOperationException ("Method getActualKey() not yet implemented."); 714 } 715 716 717 718 private int getColumn(_Reference references,_TableCharacteristics tc )throws DException{ 719 int column = -1; 720 try{ 721 column = references.getIndex(); 722 } 723 catch(DException de) { 724 if(!de.getDseCode().equalsIgnoreCase("DSE565")) 725 throw de; 726 column = tc.getIndexForColumnName(references.getColumn()); 727 references.setIndex(column); 728 } 729 return column; 730 } 731 732 public void move(Object value)throws DException{ 733 indexTableIterator.seek(value); 734 iterator.move( indexTableIterator.getPhysicalAddress() ); 735 status = 0; 736 737 } 738 739 public FieldBase field(_Reference reference) throws com.daffodilwoods.database.resource.DException { 740 if(status != 0){ 741 throw new DException("DSE2019",new Object [] {new Integer (status)}); 742 } 743 return field(getColumn(reference,indexTable.getTableCharacteristics())); 744 745 746 } 747 748 public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods.database.resource.DException { 749 int[] columns = new int[references.length]; 750 _TableCharacteristics tc = indexTable.getTableCharacteristics(); 751 for (int i = 0; i < references.length; i++) 752 columns[i] = getColumn(references[i],tc); 753 return fields(columns); 754 } 755 756 public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database.resource.DException { 757 return (FieldBase[])getColumnValues(columns); 758 } 759 760 public FieldBase field(int column) throws DException { 761 return (FieldBase)getColumnValues(column); 762 } 763 764 public void setFieldsValue(int[] columns, FieldBase[] values) throws DException { 765 indexTableIterator.setFieldsValue(columns,values); 766 782 } 783 784 public void setFieldValue(int column, FieldBase value) throws DException { 785 indexTableIterator.setFieldValue(column ,value); 786 805 } 806 807 public _Index getBtree(){ 808 return indexTableIterator.getBtree() ; 809 } 810 811 public byte[] getByteKey() throws DException{ 812 throw new java.lang.UnsupportedOperationException ( 813 "Method getByteKey() not yet implemented."); 814 } 815 public void moveByteKey(byte[] key) throws DException{ 816 throw new java.lang.UnsupportedOperationException ( 817 "Method moveByteKey() not yet implemented."); 818 } 819 820 public boolean hasAnyRecords() throws DException { 821 return iterator.first() ? setKeyAndStatus(0,true,"first") : setKeyAndStatus(-1,false,"first"); 822 } 823 public void deleteBlobClobRecord(_DatabaseUser user) throws DException { 824 indexTableIterator.deleteBlobClobRecord(user); 825 836 } 837 838 839 } 840 | Popular Tags |