1 package com.daffodilwoods.daffodildb.server.sql99.dql.iterator.order; 2 3 4 import com.daffodilwoods.daffodildb.client.*; 5 import com.daffodilwoods.daffodildb.server.datasystem.btree.*; 6 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.*; 7 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 8 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record; 9 import com.daffodilwoods.daffodildb.server.serversystem.*; 10 import com.daffodilwoods.daffodildb.server.sql99.common.*; 11 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*; 12 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 13 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.orderbyclause.*; 14 import com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata.*; 15 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 16 import com.daffodilwoods.daffodildb.utils.comparator.*; 17 import com.daffodilwoods.daffodildb.utils.field.*; 18 import com.daffodilwoods.database.general.*; 19 import com.daffodilwoods.database.resource.*; 20 import com.daffodilwoods.database.sqlinitiator.*; 21 import com.daffodilwoods.database.utility.*; 22 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler; 23 import com.daffodilwoods.database.utility.P; 24 25 public class ReadOnlyTempIndexIterator extends BaseSingleIterator implements _TableOperations, _UserTableOperations, _IndexIteratorInfo { 26 27 _Index btree; 28 Object refershKey, deleteKey; 29 _ExpressionOrderValues order; 30 public int status; 31 Exception dumpStack; 32 private _KeyColumnInformation[] keyColumnInformation; 33 private _AllColumnRowReader rowReader; 34 35 BTreeNavigator navigator; 36 VersionHandler versionHandler; 37 38 39 public ReadOnlyTempIndexIterator(_Iterator iterator0, _ExpressionOrderValues order0,VersionHandler versionHandler0) throws DException { 40 super(iterator0); 41 order = order0; 42 status = -1; 43 versionHandler = versionHandler0; 44 } 45 46 public void setRowReader(_AllColumnRowReader rowReader0) throws DException { 47 rowReader = rowReader0; 48 } 49 50 public void setConditionVariableValue(_Reference[] references, Object [] values, int priority) throws DException { 51 if(underlyingRef!=null){ 52 references = GeneralPurposeStaticClass.getJointReferences(references,underlyingRef); 53 values = GeneralPurposeStaticClass.getJointValues(this, values,underlyingRef.length); 54 } 55 56 btree = null; 57 order.setIterator(iterator); 58 order.setConditionVariableValue(references, values, priority); 59 iterator.setConditionVariableValue(references, values, priority); 60 } 61 62 public Object getColumnValues(_Reference references) throws DException { 63 return ( (Object []) getColumnValues(new _Reference[] {references}))[0]; 64 } 65 66 public Object getColumnValues(_Reference[] references) throws DException { 67 if (status != 0) { 68 throw new DException("DSE2019", new Object [] {new Integer (status)}); 69 } 70 Object obj = navigator.getValue(); 71 iterator.move(obj); 72 Object o1 = iterator.getColumnValues(references); 73 return o1; 74 } 75 76 public void setKeyCount(Object [][] tableAndKeyCount) throws DException { 77 } 78 79 public boolean seekFromTop(_IndexPredicate[] condition) throws DException { 80 throw new UnsupportedOperationException ("METHOD NOT IMPLEMENTED"); 81 } 82 83 public boolean seekFromBottom(_IndexPredicate[] condition) throws DException { 84 throw new UnsupportedOperationException ("METHOD NOT IMPLEMENTED"); 85 } 86 87 public boolean first() throws DException { 88 if (btree == null) { 89 makeBTree(); 90 } 91 synchronized (btree) { 92 return navigator.first() ? setKeyAndStatus(0, true, "first") : setKeyAndStatus( -1, false, "first"); 93 } 94 } 95 96 public boolean last() throws DException { 97 if (btree == null) { 98 makeBTree(); 99 } 100 return navigator.last() ? setKeyAndStatus(0, true, "last") : setKeyAndStatus(1, false, "last"); 101 } 102 103 public boolean next() throws DException { 104 synchronized (btree) { 105 if (status != 0) { 106 return status == 1 ? false : first(); 107 } 108 boolean b = navigator.next() ? setKeyAndStatus(0, true, "next") : setKeyAndStatus(1, false, "next"); 109 return b; 110 } 111 } 112 113 public boolean previous() throws DException { 114 if (status != 0) { 115 return status == -1 ? false : last(); 116 } 117 return navigator.previous() ? setKeyAndStatus(0, true, "previous") : setKeyAndStatus( -1, false, "previous"); 118 } 119 120 public Object getKey() throws DException { 121 if (status != 0) { 122 throw new DException("DSE2019", new Object [] {new Integer (status)}); 123 } 124 return ( (BTreeKey) navigator.getCurrentKey()).getKey(); 125 } 126 127 public void move(Object key) throws DException { 128 dumpStack = new Exception (" ::::::::: MOVE CALLED ::::::::" + key); 129 try { 130 if (key instanceof BTreeKey) { 131 if ( ( (BTreeKey) key).getNode() == null) { 132 new Exception ("node is null").printStackTrace(); 133 } 134 BTreeKey bt = (BTreeKey) key; 135 navigator.move(bt); 136 Object obj = navigator.getValue(); iterator.move(obj); 138 status = 0; 139 } else { 140 if (!seek(key)) { 141 btree.showBTree(); 142 throw new DException("DSE5518", null); 143 } 144 } 145 } catch (ClassCastException cce) { 146 throw cce; 147 } 148 } 149 150 public Object getColumnValues(int[] columns) throws DException { 151 if (status != 0) { 152 throw new DException("DSE2019", new Object [] {new Integer (status)}); 153 } 154 Object obj = navigator.getValue(); iterator.move(obj); 156 return order.getOrderValues(null); } 158 159 public _Record getRecord() throws DException { 160 Object obj = navigator.getValue(); if (obj == null) { 162 return null; 163 } 164 iterator.move(obj); 165 return iterator.getRecord(); 166 } 167 168 public boolean seek(Object indexKey) throws DException { 169 Object key = null; 170 if (btree == null) { 171 makeBTree(); 172 } 173 try { 174 key = btree.seek(indexKey); 175 } catch (ClassCastException ex) { 176 throw ex; 177 } 178 if (key != null) { 179 navigator.move(key); 180 } 181 return key != null ? setKeyAndStatus(0, true, "SEEK") : false; 182 } 183 184 public _KeyColumnInformation[] getKeyColumnInformations() throws DException { 185 if (keyColumnInformation == null) { 186 boolean[] orders = order.getOrderOfColumns(); 187 ColumnDetails[] columnDetails = order.getKeyColumnDetails(); 188 int len = columnDetails.length; 189 keyColumnInformation = new _KeyColumnInformation[len]; 190 for (int i = 0; i < len; i++) { 191 keyColumnInformation[i] = new TableKeyColumnInformation(columnDetails[i], orders[i]); 192 TableDetails table = columnDetails[i].getTable(); 193 keyColumnInformation[i].setTableDetails(table); 194 } 195 } 196 return keyColumnInformation; 197 } 198 199 public Object [] getUniqueColumnReference() throws DException { 200 return null; } 202 203 public SuperComparator getComparator() { 204 return btree.getComparator(); 205 } 206 207 public TableDetails[] getTableDetails() throws DException { 208 return iterator.getTableDetails(); 209 } 210 211 public _Iterator getBaseIterator(ColumnDetails column) throws DException { 212 return this; 213 } 214 215 public _Iterator getBaseIteratorHasRecord(ColumnDetails columnDetails) throws DException { 216 return this; 217 } 218 219 public Object getColumnValues() throws DException { 220 if (status != 0) { 221 throw new DException("DSE2019", new Object [] {new Integer (status)}); 222 } 223 Object obj = navigator.getValue(); iterator.move(obj); 225 Object o = iterator.getColumnValues(); 226 return o; 227 } 228 229 public void setIterator(_Iterator iterator) throws DException { 230 231 throw new java.lang.UnsupportedOperationException ("Method setIterator() not yet implemented."); 232 } 233 234 public boolean seekFromBottomRelative(Object indexKey) throws DException { 235 if (btree == null) { 236 makeBTree(); 237 } 238 BTreeKey key = (BTreeKey) btree.seekFromBottomRelative(navigator.getCurrentKey(), indexKey); 239 if (key != null) { 240 move(key); 241 dumpStack = new Exception (" SEEK FROM TOP RELATIVE WITH INDEX KEY RETURNING TRUE"); 242 return true; 243 } 244 dumpStack = new Exception (" SEEK FROM TOP RELATIVE WITH INDEX KEY RETURNING FALSE"); 245 return false; 246 } 247 248 public boolean seekFromTopRelative(Object indexKey) throws DException { 249 if (btree == null) { 250 makeBTree(); 251 } 252 BTreeKey key = (BTreeKey) btree.seekFromTopRelative(navigator.getCurrentKey(), indexKey); 253 if (key != null) { 254 move(key); 255 dumpStack = new Exception (" SEEK FROM BOTTOM RELATIVE WITH INDEX KEY RETURNING TRUE"); 256 return true; 257 } 258 dumpStack = new Exception (" SEEK FROM BOTTOM RELATIVE WITH INDEX KEY RETURNING FALSE"); 259 return false; 260 } 261 262 public String toString() { 263 return "TemporaryIndexIterator[" + iterator + "][" + order + "]"; 264 } 265 266 public _Order getDefaultOrder() throws com.daffodilwoods.database.resource.DException { 267 return iterator.getDefaultOrder(); 268 } 269 270 public void insert(Object parm1) throws com.daffodilwoods.database.resource.DException { 271 ( (_TableOperations) iterator).insert(parm1); 272 } 273 274 public void update(Object parm1) throws com.daffodilwoods.database.resource.DException { 275 ( (_TableOperations) iterator).update(parm1); 276 } 277 278 public void update(int[] parm1, Object [] parm2) throws com.daffodilwoods.database.resource.DException { 279 ( (_TableOperations) iterator).update(parm1, parm2); 280 } 281 282 public void delete() throws com.daffodilwoods.database.resource.DException { 283 ( (_TableOperations) iterator).delete(); 284 } 285 286 public void insert(_DatabaseUser parm1, Object parm2) throws com.daffodilwoods.database.resource.DException { 287 ( (_UserTableOperations) iterator).insert(parm1, parm2); 288 } 289 290 public void ensureRecordInMemory() throws com.daffodilwoods.database.resource.DException { 291 ( (_IndexIteratorInfo) iterator).ensureRecordInMemory(); 292 } 293 294 public void moveOnActualKey(Object parm1) throws com.daffodilwoods.database.resource.DException { 295 ( (_IndexIteratorInfo) iterator).moveOnActualKey(parm1); 296 } 297 298 public Object getActualKey() throws com.daffodilwoods.database.resource.DException { 299 return ( (_IndexIteratorInfo) iterator).getActualKey(); 300 } 301 302 public void update(_DatabaseUser parm1, Object parm2) throws com.daffodilwoods.database.resource.DException { 303 ( (_UserTableOperations) iterator).update(parm1, parm2); 304 } 305 306 public void update(_DatabaseUser parm1, int[] parm2, Object [] parm3) throws com.daffodilwoods.database.resource.DException { 307 ( (_UserTableOperations) iterator).update(parm1, parm2, parm3); 308 } 309 310 public void delete(_DatabaseUser parm1) throws com.daffodilwoods.database.resource.DException { 311 ( (_UserTableOperations) iterator).delete(parm1); 312 } 313 314 public int getBtreeIndex() throws DException { 315 return ( (_IndexIteratorInfo) iterator).getBtreeIndex(); 316 } 317 318 public void setKeyColumnInformation(_KeyColumnInformation[] keyColumnInformation) { 319 this.keyColumnInformation = keyColumnInformation; } 321 322 public boolean locateKey(Object key1, boolean top) throws DException { 323 Object key = null; 324 try { 325 key = btree.locateKey(key1, top); 326 } catch (ClassCastException ex) { 327 throw ex; 328 } 329 return key != null ? setKeyAndStatus(0, true, "LOCATE KEY") : false; 330 } 331 332 public _ExecutionPlan getExecutionPlan() throws DException { 333 _ExecutionPlan cplan = iterator.getExecutionPlan(); 334 _ExecutionPlan cplans[] = cplan == null ? null : new _ExecutionPlan[] {cplan}; 335 _Index bt = btree; 336 if (bt == null) { 337 bt = new BTree(order.getComparator(), null, new MemoryNodeManager(null)); 338 bt.setIndexInformation(new IndexInformations( order.getColumns(),versionHandler)); 339 } 340 _IndexInformation iinf = bt.getIndexInformation(); 341 ExecutionPlan plan = new ExecutionPlan("TemporaryIndexIterator", cplans, null, null, getIndexName(iinf)); 342 return plan; 343 } 344 345 private void makeBTree() throws DException { 346 btree = new BTree(order.getComparator(), null, new MemoryNodeManager(null)); 347 btree.setIndexInformation(new IndexInformations(order.getColumns(),versionHandler)); 348 if (iterator.first()) { 349 do { 350 Object obj = order.getOrderValues(null); 351 Object value = iterator.getKey(); 352 try { 353 btree.insert(null, obj, value); 354 } catch (NullPointerException ex) { 355 Object [] o = (Object []) obj; 356 for (int i = 0; i < o.length; i++) { 357 ; } 359 360 361 GeneralPurposeStaticClass.convertintoObjects(obj); 362 throw ex; 363 } 364 } while (iterator.next()); 365 } 366 navigator = new BTreeNavigatorCurrent (btree); 367 368 369 370 } 371 372 public SuperComparator getObjectComparator() { 373 throw new UnsupportedOperationException ("Method not implemented"); 374 } 375 376 private String getIndexName(_IndexInformation indexInformation) throws DException { 377 String indexName = ""; 378 String [] columns = indexInformation.getColumns(); 379 boolean[] order = indexInformation.getOrderOfColumns(); 380 for (int i = 0, length = columns.length; i < length; i++) { 381 indexName += columns[i] + " " + (order[i] ? " ASC ," : " DESC ,"); 382 } 383 return indexName; 384 } 385 386 public void updateRow(_Iterator baseIterator, int[] columns, Object [] values) throws com.daffodilwoods.database.resource.DException { 387 388 408 btree = null; 409 makeBTree(); 410 411 } 412 413 public void insertRow(Object row) throws com.daffodilwoods.database.resource.DException { 414 420 btree = null; 421 makeBTree(); 422 } 423 424 public void deleteRow(_Iterator iterator) throws com.daffodilwoods.database.resource.DException { 425 426 441 btree = null; 442 makeBTree(); 443 } 444 445 public _Iterator getIterator(Object key) throws com.daffodilwoods.database.resource.DException { 446 if (btree == null) { 447 makeBTree(); 448 } 449 return new SingleRowIterator(iterator, key); 450 } 451 452 public _Iterator getPartialIterator(Object key) throws com.daffodilwoods.database.resource.DException { 453 if (btree == null) { 454 makeBTree(); 455 } 456 return new SingleRowIterator(iterator, key); 457 } 458 459 public static boolean test = false; 460 public void replaceRow(_Iterator iterator, Object row) throws com.daffodilwoods.database.resource.DException { 461 btree = null; 462 makeBTree(); 463 } 464 465 public boolean seekKeyAddress(Object parm1) throws com.daffodilwoods.database.resource.DException { 466 467 throw new java.lang.UnsupportedOperationException ("Method seekKeyAddress() not yet implemented."); 468 } 469 470 public Object getPhysicalAddress() throws com.daffodilwoods.database.resource.DException { 471 472 throw new java.lang.UnsupportedOperationException ("Method getPhysicalAddress() not yet implemented."); 473 } 474 475 public boolean isRefreshType() { 476 return true; 477 } 478 479 public void refreshDataSource() throws DException { 480 Object key = null; 481 if (status == 0) { 482 key = getKey(); 483 } 484 btree = null; 485 makeBTree(); 486 if (key != null) { 487 btree.seekFromTopRelative(null, key); 488 489 490 } 491 } 492 493 public Object getUpdatedEffect(_Reference[] references, Object [] values) throws DException { 494 495 throw new UnsupportedOperationException ("getUpdatedEffect() Not Supported"); 496 } 497 498 public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException { 499 ExecutionPlanForBrowser cplan = iterator.getExecutionPlanForBrowser(); 500 ExecutionPlanForBrowser cplans[] = cplan == null ? null : new ExecutionPlanForBrowser[] {cplan}; 501 _Index bt = btree; 502 if (bt == null) { 503 bt = new BTree(order.getComparator(), null, new MemoryNodeManager(null)); 504 bt.setIndexInformation(new IndexInformations(order.getColumns(),versionHandler)); 505 } 506 _IndexInformation iinf = bt.getIndexInformation(); 507 ExecutionPlanForBrowser plan = new ExecutionPlanForBrowser("Sorting", "TemporaryIndexIterator", cplans, null, null, getIndexName(iinf)); 508 return plan; 509 } 510 511 public Object [][] getFunctionalColumnMapping() throws DException { 512 return iterator.getFunctionalColumnMapping(); 513 } 514 515 public _IndexInformation[] getUniqueInformation() throws DException { 516 throw new UnsupportedOperationException ("getUniqueInformation"); 517 } 518 519 public _TableCharacteristics getTableCharacteristics() throws DException { 520 throw new UnsupportedOperationException ("getTableCharacteristics"); 521 522 } 523 524 public Object getColumnValues(int int0) throws DException { 525 throw new UnsupportedOperationException ("getColumnValues"); 526 } 527 528 public _OrderCount getOrderCounts() throws com.daffodilwoods.database.resource.DException { 529 _Order tempOrder = order.getOrder(); ColumnDetails[] cd = tempOrder.getKeyColumnDetails(); 531 boolean[] b = tempOrder.getOrderOfColumns(); 532 ColumnDetails[] result = new ColumnDetails[] {cd[0]}; 533 boolean[] orderType = new boolean[] {b[0]}; 534 int i = 1; 535 for (int length = cd.length; i < length; i++) { 536 if (cd[i].getAppropriateColumn().equalsIgnoreCase(SystemFields.systemFields[SystemFields.rowId])) { 537 break; 538 } else { 539 ColumnDetails[] temp = new ColumnDetails[i + 1]; 540 boolean[] tem = new boolean[i + 1]; 541 System.arraycopy(result, 0, temp, 0, i); 542 System.arraycopy(orderType, 0, tem, 0, i); 543 temp[i] = cd[i]; 544 tem[i] = b[i]; 545 result = temp; 546 orderType = tem; 547 } 548 } 549 return new OrderCount(i, new SelectOrder(result, orderType)); 550 } 551 552 protected boolean setKeyAndStatus(int num, boolean flag, String str) throws DException { 553 dumpStack = new Exception ("IN SETKEYSTATUS THROUGH METHOD :: " + str + " AND STATUS IS " + num + " AND FLAG IS " + flag + " HASHCODE " + hashCode()); 554 status = num; 555 return flag; 556 } 557 558 public FieldBase field(_Reference reference) throws com.daffodilwoods.database.resource.DException { 559 return ( (FieldBase[]) fields(new _Reference[] {reference}))[0]; 560 } 561 562 public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods.database.resource.DException { 563 if (status != 0) { 564 throw new DException("DSE2019", new Object [] {new Integer (status)}); 565 } 566 Object obj = navigator.getValue(); 567 iterator.move(obj); 568 FieldBase[] o1 = iterator.fields(references); 569 return o1; 570 } 571 572 public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database.resource.DException { 573 throw new java.lang.UnsupportedOperationException ("Method fields() not yet implemented."); 574 } 575 576 public FieldBase field(int column) throws DException { 577 578 throw new java.lang.UnsupportedOperationException ("Method field() not yet implemented."); 579 } 580 581 public void releaseResource() throws DException { 582 iterator.releaseResource(); 583 order.releaseResource(); 584 } 585 public _Iterator getUnderlyingIterator() throws DException{ 586 return iterator; 587 } 588 public void deleteBlobClobRecord(_DatabaseUser user) throws com.daffodilwoods.database.resource.DException { 589 ( (_TableOperations) iterator).deleteBlobClobRecord(user) ; 590 } 591 592 593 } 594 | Popular Tags |