| 1 package com.daffodilwoods.daffodildb.server.sql99.dql.iterator.table; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.client.*; 6 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 7 import com.daffodilwoods.daffodildb.server.serversystem.*; 8 import com.daffodilwoods.daffodildb.server.sql99.common.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.common.*; 10 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*; 11 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 12 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*; 13 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.queryspecification.*; 14 import com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata.*; 15 import com.daffodilwoods.daffodildb.server.sql99.dql.semanticchecker.*; 16 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 17 import com.daffodilwoods.daffodildb.utils.field.*; 18 import com.daffodilwoods.database.resource.*; 19 import com.daffodilwoods.database.sqlinitiator.*; 20 import com.daffodilwoods.database.utility.*; 21 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility; 22 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.subquery; 23 24 44 45 public class SelectedColumnIterator extends AbstractColumnIterator implements _SelectQueryIterator, TypeConstants, _FunctionalMapping { 46 47 50 private int[] selectedColumnMapping; 51 54 private int allColumnLength; 55 58 private ColumnDetails[] functionalColumns; 59 62 private Object [][] functionalColumnIteratorMapping; 63 66 protected Object [][] tableAndIteratorMapping; 67 70 private TableDetails[] viewTables; 71 75 private int iteratorType; 76 79 private queryspecification qs; 80 81 private _Reference[] underlyingReferences; 82 100 101 public SelectedColumnIterator(ColumnDetails[] selectListColumnDetails, _Iterator iterator0, _Reference[] selectReferences, TableDetails[] tableDetails, boolean isView, _Reference[] underlyingReferencesSolvableByCurrentIterator0, _ServerSession serverSession, queryspecification qs ,_Reference[] ref,_Iterator[] iter ) throws DException { 102 this.qs = qs; 103 init(iterator0, selectListColumnDetails, tableDetails, selectReferences, null, serverSession ,ref,iter); 104 keyColumns = iterator0.getKeyColumnInformations(); 105 selectedColumnMapping = groupColumnsAccToIterators(selectListColumnDetails, true); if (!isView) { 107 columnCharacteristics = new SelectColumnCharacteristics(selectListColumnDetails, tableDetailsCC, false); 108 rowReader = new SelectRowReader(columnCharacteristics, getColumnNamesToIndexesMapping(selectListColumnDetails)); 109 } 110 state = 2; 111 GeneralPurposeStaticClass.printProperties(iterator0, null, null, null, null); 112 underlyingReferencesSolvableByCurrentIterator = underlyingReferencesSolvableByCurrentIterator0; 113 keyColumns = iterator.getKeyColumnInformations(); 114 iteratorType = IteratorConstants.NONSCROLLABLE; 115 } 116 117 136 137 public SelectedColumnIterator(ColumnDetails[] selectListColumnDetails, _Iterator iterator0, _Reference[] selectReferences, TableDetails[] tableDetails, boolean isView, int iteratorType, _Reference[] underlyingReferencesSolvableByCurrentIterator0, _ServerSession serverSession, queryspecification qs ,_Reference[] ref,_Iterator[] iter) throws DException { 138 this.qs = qs; 139 init(iterator0, selectListColumnDetails, tableDetails, selectReferences, null, serverSession , ref, iter); 140 keyColumns = iterator.getKeyColumnInformations(); 141 selectedColumnMapping = groupColumnsAccToIterators(selectListColumnDetails, false); 143 selectListColumnDetails = SemanticChecker.addColumnDetails(selectListColumnDetails, getColumnDetails(keyColumns)); 144 145 int[] selectKeyMapping = groupColumnsAccToIterators(selectListColumnDetails, true); if (!isView) { 147 columnCharacteristics = new SelectColumnCharacteristics(selectColumnDetails, tableDetailsCC, false); 148 rowReader = getRowReaderScrollable(selectColumnDetails, selectKeyMapping); 149 } 150 state = 2; 151 underlyingReferencesSolvableByCurrentIterator = underlyingReferencesSolvableByCurrentIterator0; 152 iteratorType = IteratorConstants.SCROLLABLE; 153 } 154 155 private _RowReader getRowReaderScrollable(ColumnDetails[] selectColumnDetails, int[] selectKeyMapping) throws DException { 156 int[] selectRowMapping = new int[selectColumnDetails.length]; 157 int[] keyRowMapping = new int[keyColumns.length]; 158 int countSelect = 0, countKey = 0, count = 0; 159 for (int i = 0, length = groupMapping.length; i < length; i++) { 160 ColumnDetails[] columns = (ColumnDetails[]) groupMapping[i][1]; 161 for (int j = 0, length1 = columns.length; j < length1; j++) { 162 if (ifMatch(selectColumnDetails, columns[j])) { 163 selectRowMapping[countSelect++] = selectKeyMapping[count++]; 164 } else { 165 keyRowMapping[countKey++] = selectKeyMapping[count++]; 166 } 167 } 168 } 169 return new RowReaderScrollable(selectRowMapping, keyRowMapping, 170 getOrderSpecification(keyColumns)); 171 } 172 173 private boolean ifMatch(ColumnDetails[] columns, ColumnDetails column) throws DException { 174 for (int i = 0, length = columns.length; i < length; i++) { 175 if (columns[i] == column) { 176 return true; 177 } 178 } 179 return false; 180 } 181 182 private boolean[] getOrderSpecification(_KeyColumnInformation[] keyColumnInformation) throws DException { 183 int length = keyColumnInformation.length; 184 boolean[] result = new boolean[length]; 185 for (int i = 0; i < length; i++) { 186 result[i] = keyColumnInformation[i].getOrderSpecification(); 187 } 188 return result; 189 } 190 191 211 212 public SelectedColumnIterator(ColumnDetails[] selectListColumnDetails, _Iterator iterator0, _Reference[] selectReferences, TableDetails[] allTableDetails, TableDetails[] viewTables0, String [] groupByPrimaryColumns, boolean isView, _Reference[] underlyingReferencesSolvableByCurrentIterator0, _ServerSession serverSession, queryspecification qs ,_Reference[] ref,_Iterator[] iter) throws DException { 213 this.qs = qs; 214 init(iterator0, selectListColumnDetails, allTableDetails, selectReferences, viewTables0, serverSession , ref,iter); 215 keyColumns = iterator.getKeyColumnInformations(); 216 variableValues = getNewVariableValues(variableValues); 217 218 functionalColumns = getFunctionalColumns(selectListColumnDetails, keyColumns); 219 if (!isView) { 220 initializeSelectCCAndRowReader(groupByPrimaryColumns); 221 tableAndIteratorMapping = getTableAndIteratorMapping(allTableDetails); 222 } 223 224 selectedColumnMapping = groupColumnsAccToIterators(selectListColumnDetails, false); selectListColumnDetails = SemanticChecker.addColumnDetails(selectListColumnDetails, getColumnDetails(keyColumns)); 226 groupColumnsAccToIterators(selectListColumnDetails, true); underlyingReferencesSolvableByCurrentIterator = underlyingReferencesSolvableByCurrentIterator0; 228 iteratorType = IteratorConstants.UPDATABLE; 229 state = 2; 230 } 231 232 private _VariableValues getNewVariableValues(_VariableValues variableValues) throws DException { 233 ArrayList list = new ArrayList(5); 234 for (int i = 0, length = selectColumnDetails.length; i < length; i++) { 235 if (selectColumnDetails[i].getType() == HAS_RECORD) { 236 list.add(new Object [] {selectColumnDetails[i], iterator.getBaseIteratorHasRecord(selectColumnDetails[i])}); 237 } 238 } 239 if (list.isEmpty()) { 240 return variableValues; 241 } 242 HasRecordVariableValues has = new HasRecordVariableValues(variableValues, (Object [][]) list.toArray(new Object [list.size()][2])); 243 return has; 244 } 245 246 private void initializeSelectCCAndRowReader(String [] groupByPrimaryColumns) throws DException { 247 functionalColumnIteratorMapping = reArrangeFunctionalColumns(iterator.getFunctionalColumnMapping()); 248 Object [][] functionalKeyColumnMapping = getFunctionalKeyColumnMapping(); 249 columnCharacteristics = new SelectColumnCharacteristics(selectColumnDetails, tableDetailsCC, groupByPrimaryColumns, false, true); 250 ForeignKeyColumns[] fKeyColumns = getColumnNamesToIndexesMapping(selectColumnDetails); 251 rowReader = new AllColumnRowReader(selectColumnDetails, keyColumns, functionalKeyColumnMapping, tableDetailsCC, allColumnLength, columnCharacteristics, fKeyColumns, false); 252 ( (SelectColumnCharacteristics) columnCharacteristics).setRowReader(rowReader); 253 ( (SelectColumnCharacteristics) columnCharacteristics).setForeignKeyMapping(fKeyColumns); 254 } 255 256 265 266 private Object [][] reArrangeFunctionalColumns(Object [][] functionalColumns) throws DException { 267 if (functionalColumns == null) { 268 return null; 269 } 270 int finalLength = functionalColumns.length; 271 ArrayList list = new ArrayList(); 272 for (int i = 0, length = viewTables.length; i < length; i++) { 273 int j = 0; 274 for (; j < finalLength; j++) { 275 if (functionalColumns[j][0] == viewTables[i]) { 276 list.add(functionalColumns[j]); 277 break; 278 } 279 } 280 } 281 if (list.size() != finalLength) { 282 throw new DException("DSE3521", null); 283 } 284 return (Object [][]) list.toArray(new Object [list.size()][3]); 285 } 286 287 private ColumnDetails[] getColumnDetails(_KeyColumnInformation[] keyColumns) throws DException { 288 int length = keyColumns.length; 289 ColumnDetails[] columns = new ColumnDetails[length]; 290 for (int i = 0; i < length; i++) { 291 columns[i] = keyColumns[i].getColumnDetails(); 292 } 293 return columns; 294 } 295 296 299 public SelectedColumnIterator(_KeyColumnInformation[] orderKeyColumns0, _Iterator iterator0, TableDetails[] allTableDetails, _ServerSession serverSession, queryspecification qs ,_Reference[] ref,_Iterator[] iter) throws DException { 300 this.qs = qs; 301 init(iterator0, null, allTableDetails, null, null, serverSession , ref, iter); 302 keyColumns = addKeyColumns(orderKeyColumns0, iterator.getKeyColumnInformations()); 303 304 functionalColumns = getFunctionalColumns(null, keyColumns); 305 Object [][] functionalKeyColumnMapping = getFunctionalKeyColumnMapping(); 306 tableAndIteratorMapping = getTableAndIteratorMapping(allTableDetails); 307 308 columnCharacteristics = new ColCharacteristicsTempIndex(tableDetailsCC, false, 0, true); 309 rowReader = new AllColumnRowReaderTempIndex(keyColumns, functionalKeyColumnMapping, tableDetailsCC, allColumnLength, columnCharacteristics, false); 310 ( (ColCharacteristicsTempIndex) columnCharacteristics).setRowReader( (_AllColumnRowReader) rowReader); 311 iteratorType = IteratorConstants.UPDATABLE; 312 state = 2; 313 } 314 315 318 private _KeyColumnInformation[] addKeyColumns(_KeyColumnInformation[] orderKeyColumns0, _KeyColumnInformation[] keyColumnInformations) throws DException { 319 int length = orderKeyColumns0.length, length1 = keyColumnInformations.length, totalLength = length + length1; 320 _KeyColumnInformation[] keyColumns = new _KeyColumnInformation[totalLength]; 321 System.arraycopy(orderKeyColumns0, 0, keyColumns, 0, length); 322 System.arraycopy(keyColumnInformations, 0, keyColumns, length, length1); 323 return keyColumns; 324 } 325 326 337 private void init(_Iterator iterator0, ColumnDetails[] selectListColumnDetails, TableDetails[] allTableDetails, _Reference[] selectReferences, TableDetails[] viewTables0, _ServerSession serverSession ,_Reference[] ref, _Iterator[] iter) throws DException { 338 iterator = iterator0; 339 viewTables = viewTables0; 340 selectColumnDetails = selectListColumnDetails; 341 tableDetailsCC = getMappingOfTableCC(allTableDetails); 342 iterator.getTableDetails(); 343 344 variableValues = GeneralPurposeStaticClass.getVariableValues123(selectReferences, serverSession,ref,iter); 345 346 variableValues.setIterator(iterator); 348 349 350 359 360 } 361 362 369 370 private Object [][] getMappingOfTableCC(TableDetails[] allTableDetails) throws DException { 371 int length = allTableDetails.length; 372 Object [][] newMapping = new Object [length][3]; 373 int index = 1; 374 for (int i = 0; i < length; ++i) { 375 newMapping[i][0] = allTableDetails[i]; 376 _ColumnCharacteristics cc = allTableDetails[i].cc; 377 newMapping[i][1] = cc; 378 newMapping[i][2] = new Integer (index); 379 index = index + cc.getColumnCount(); 380 } 381 allColumnLength = index; 382 return newMapping; 383 } 384 385 private Object [][] getTableAndIteratorMapping(TableDetails[] allTableDetails) throws DException { 386 ArrayList list = new ArrayList(); 387 for (int i = 0, lengthOfTables = allTableDetails.length; i < lengthOfTables; i++) { 388 Object [] array = new Object [3]; 389 array[0] = allTableDetails[i]; 390 array[1] = getColumnDetails(allTableDetails[i]); 391 array[2] = iterator.getBaseIterator( ( (ColumnDetails[]) array[1])[0]); 392 list.add(array); 393 } 394 if (functionalColumnIteratorMapping != null) { 395 list.addAll(Arrays.asList(functionalColumnIteratorMapping)); 396 } 397 if (functionalColumns != null) { 398 Object [] array = new Object [3]; 399 array[0] = null; 400 array[1] = functionalColumns; 401 array[2] = this; 402 list.add(array); 403 } 404 return list.isEmpty() ? null : (Object [][]) list.toArray(new Object [list.size()][3]); 405 } 406 407 private ColumnDetails[] getColumnDetails(TableDetails tableDetails) throws DException { 408 _ColumnCharacteristics cc = tableDetails.cc; 409 String [] columnNames = cc.getColumnNames(); 410 int length1 = columnNames.length; 411 ColumnDetails[] columns = new ColumnDetails[length1]; 412 for (int j = 0; j < length1; ++j) { 413 ColumnDetails columnDetail = new ColumnDetails(); 414 String [] tableName = tableDetails.getTableName(); 415 String [] column = new String [4]; 416 System.arraycopy(tableName, 0, column, 0, tableName.length); 417 column[3] = columnNames[j]; 418 columnDetail.setColumnName(column); 419 columnDetail.setTableDetails(tableDetails); 420 columnDetail.setTableForDisplay(tableDetails); 421 int index = cc.getColumnIndex(columnNames[j]); 422 columnDetail.setDatatype(cc.getColumnType(index)); 423 columnDetail.setSize(cc.getSize(index)); 424 columnDetail.setType(REFERENCE); 425 columnDetail.setExpression(column[2] + "." + column[3]); 426 columns[j] = columnDetail; 427 } 428 return columns; 429 } 430 431 private Object [][] getFunctionalKeyColumnMapping() throws DException { 432 ArrayList list = new ArrayList(); 433 if (functionalColumnIteratorMapping != null) { 434 int length = functionalColumnIteratorMapping.length; 435 for (int i = 0; i < length; i++) { 436 ColumnDetails[] columns = (ColumnDetails[]) functionalColumnIteratorMapping[i][1]; 437 for (int j = 0, length1 = columns.length; j < length1; j++) { 438 list.add(new Object [] {columns[j], new Integer (allColumnLength++)}); 439 } 440 } 441 } 442 if (functionalColumns != null) { 443 for (int i = 0, length = functionalColumns.length; i < length; i++) { 444 list.add(new Object [] {functionalColumns[i], new Integer (allColumnLength++)}); 445 } 446 } 447 --allColumnLength; 448 return (Object [][]) list.toArray(new Object [list.size()][2]); 449 } 450 451 protected ColumnDetails[] getFunctionalColumns(ColumnDetails[] selectedColumns, _KeyColumnInformation[] keyColumns) throws DException { 452 ArrayList list = new ArrayList(); 453 for (int i = 0, length = selectedColumns.length; i < length; i++) { 454 TableDetails tableDetail = selectedColumns[i].getTableDetails(); 455 if (tableDetail == null || selectedColumns[i].getTableAliasArray() != null) { 456 list.add(selectedColumns[i]); 457 } 458 } 459 for (int i = 0, length = keyColumns.length; i < length; i++) { 460 ColumnDetails column = keyColumns[i].getColumnDetails(); 461 TableDetails tableDetail = column.getTableDetails(); 462 if (tableDetail == null || column.getTableAliasArray() != null) { 463 list.add(column); 464 } 465 } 466 return list.isEmpty() ? null : (ColumnDetails[]) list.toArray(new ColumnDetails[list.size()]); 467 } 468 469 477 private int[] groupColumnsAccToIterators(ColumnDetails[] columnDetails, boolean makeGroupMapping) throws DException { 478 479 int length = columnDetails.length; 480 ArrayList aList = new ArrayList(length); 481 for (int i = 0; i < length; i++) { 482 aList.add(new TableAndIndex(columnDetails[i].getTableDetails(), i + 1)); 483 } 484 TableDetails[] tableDetails = new TableDetails[length]; 485 int[] index = new int[length]; 486 TableAndIndex tableIndex = (TableAndIndex) aList.remove(0); 487 tableDetails[0] = tableIndex.getTableDetails(); 488 index[0] = tableIndex.getIndex(); 489 for (int i = 1; i < length; i++) { 490 for (int j = 0; j < aList.size(); j++) { 491 tableIndex = (TableAndIndex) aList.get(j); 492 if (tableDetails[i - 1] == tableIndex.getTableDetails()) { 493 aList.remove(j); 494 tableDetails[i] = tableIndex.getTableDetails(); 495 index[i] = tableIndex.getIndex(); 496 i++; 497 j--; 498 } 499 } 500 if (aList.size() != 0) { 501 tableIndex = (TableAndIndex) aList.remove(0); 502 tableDetails[i] = tableIndex.getTableDetails(); 503 index[i] = tableIndex.getIndex(); 504 } else { 505 break; 506 } 507 } 508 if (makeGroupMapping) { 509 initializeMapping(tableDetails, index, columnDetails); 510 } 511 int[] finalIndex = new int[length]; 512 for (int i = 0; i < length; i++) { 513 finalIndex[i] = getPositionFromArray(index, i + 1); 514 } 515 return finalIndex; 516 517 } 518 519 private int getPositionFromArray(int[] index, int toSearch) throws DException { 520 for (int i = 0, len = index.length; i < len; i++) { 521 if (index[i] == toSearch) { 522 return i + 1; 523 } 524 } 525 throw new DException("DSE3564", null); 526 } 527 528 536 537 public void initializeMapping(TableDetails[] tableDetails, int[] indexes, ColumnDetails[] selectColumnDetails) throws DException { 538 ArrayList mapping = new ArrayList(); 539 int length = tableDetails.length; 540 for (int i = 0; i < length; i++) { 541 ArrayList aList = new ArrayList(length); 542 aList.add(selectColumnDetails[indexes[i] - 1]); 543 for (int j = i + 1; j < length && tableDetails[i] != null; j++) { 544 if (tableDetails[i] == tableDetails[j]) { 545 aList.add(selectColumnDetails[indexes[j] - 1]); 546 i = j; 547 } else { break; 549 } 550 } 551 _Iterator baseLevelIterator = null; 552 if (tableDetails[i] == null || selectColumnDetails[indexes[i] - 1].getType() != REFERENCE) { 553 variableValues.setIterator(iterator); 554 } else { 555 baseLevelIterator = iterator.getBaseIterator(selectColumnDetails[indexes[i] - 1]); 556 } 557 558 mapping.add(new Object [] {baseLevelIterator, (ColumnDetails[]) aList.toArray(new ColumnDetails[0]), Utility.getBooleanValue(tableDetails[i] != null), tableDetails[i]}); 559 } 560 groupMapping = (Object [][]) mapping.toArray(new Object [0][]); 561 } 562 563 575 576 public Object getColumnValues() throws com.daffodilwoods.database.resource.DException { 577 switch (iteratorType) { 578 case IteratorConstants.NONSCROLLABLE: 579 return getNonSharableFieldSelColumnValues(); 580 case IteratorConstants.SCROLLABLE: 581 return getNonSharableFieldRow(); 582 case IteratorConstants.UPDATABLE: 583 return getNonSharableAllCOlumnValues(); 584 } 585 throw new DException("DSE3522", new Object [] {new Integer (iteratorType)}); 586 } 587 588 private Object [] getNonSharableFieldSelColumnValues() throws DException { 589 Object [] row = getNonSharableFieldRow(); 590 int length = selectColumnDetails.length; 591 Object [] result = new Object [length]; 592 for (int i = 0; i < length; i++) { 593 result[i] = getFieldObject(i + 1, row); 594 } 595 return result; 596 } 597 598 private Object [] getNonSharableFieldSelColumnValues(ArrayList alist) throws DException { 599 getNonSharableFieldRow(alist); 600 int length = selectColumnDetails.length; 601 Object [] result = new Object [length]; 602 for (int i = 0; i < length; i++) { 603 result[i] = alist.get(selectedColumnMapping[i] - 1); 604 } 605 return result; 606 } 607 608 private Object getFieldObject(int index, Object [] row) throws DException { 609 try { 610 return row[selectedColumnMapping[index - 1] - 1]; 611 } catch (ArrayIndexOutOfBoundsException ex) { 612 throw ex; 613 } 614 } 615 616 private Object [] getNonSharableAllCOlumnValues() throws DException { 617 try { 618 ArrayList list = new ArrayList(); 619 for (int i = 0, length = tableAndIteratorMapping.length; i < length; i++) { 620 Object [] values = (Object []) ( (_Iterator) tableAndIteratorMapping[i][2]).getColumnValues( (_Reference[]) tableAndIteratorMapping[i][1]); 621 list.addAll(Arrays.asList(values)); 622 } 623 return (Object []) list.toArray(new Object [list.size()]); 624 } catch (NullPointerException ex) { 625 throw new DException("DSE3523", null); 626 } 627 } 628 629 public Object getColumnValues(_Reference[] parm1) throws com.daffodilwoods.database.resource.DException { 630 int length = parm1.length; 631 Object [] result = new Object [length]; 632 for (int i = 0; i < length; i++) { 633 result[i] = getColumnValues(parm1[i]); 634 } 635 return result; 636 } 637 638 public Object getColumnValues(ArrayList alist) throws com.daffodilwoods.database.resource.DException { 639 switch (iteratorType) { 640 case IteratorConstants.NONSCROLLABLE: 641 return getNonSharableFieldSelColumnValues(alist); 642 case IteratorConstants.SCROLLABLE: 643 return getNonSharableFieldRow(alist); 644 case IteratorConstants.UPDATABLE: 645 return getNonSharableAllCOlumnValues(alist); 646 } 647 throw new DException("DSE3522", new Object [] {new Integer (iteratorType)}); 648 } 649 650 public Object getColumnValues(_Reference references) throws DException { 651 _Iterator iter = getIterator(references); 652 return iter != null ? iter.getColumnValues(references) : ( (ColumnDetails) references).run(variableValues); 653 } 654 655 public Object getObject() throws DException { 656 switch (iteratorType) { 657 case IteratorConstants.NONSCROLLABLE: 658 return getSelColumnValues(); 659 case IteratorConstants.SCROLLABLE: 660 return getValues(getRow()); 661 case IteratorConstants.UPDATABLE: 662 return getAllColumnValues(); 663 } 664 throw new DException("DSE3522", new Object [] {new Integer (iteratorType)}); 665 } 666 667 private Object getSelColumnValues() throws DException { 668 Object [] row = getRow(); 669 int length = selectColumnDetails.length; 670 Object [] result = new Object [length]; 671 for (int i = 0; i < length; i++) { 672 try { 673 result[i] = ( (FieldBase) getObject(i + 1, row)).getObject(); 674 } catch (NullPointerException ex) { 675 throw ex; 676 } 677 } 678 return result; 679 } 680 681 private Object getObject(int index, Object row) throws DException { 682 try { 683 return ( (Object []) row)[selectedColumnMapping[index - 1] - 1]; 684 } catch (ArrayIndexOutOfBoundsException ex) { 685 for (int i = 0; i < groupMapping.length; i++) { 686 ; } 688 throw ex; 689 } 690 } 691 692 private Object [] getValues(Object [] values) throws DException { 693 Object [] newValues = new Object [values.length]; 694 for (int i = 0; i < values.length; i++) { 695 newValues[i] = ( (FieldBase) values[i]).getObject(); 696 } 697 return newValues; 698 } 699 700 private Object getAllColumnValues() throws DException { 701 try { 702 ArrayList list = new ArrayList(); 703 for (int i = 0, length = tableAndIteratorMapping.length; i < length; i++) { 704 Object [] values = (Object []) ( (_Iterator) tableAndIteratorMapping[i][2]).getColumnValues( (_Reference[]) tableAndIteratorMapping[i][1]); 705 list.addAll(Arrays.asList(getValues(values))); 706 } 707 return list.toArray(new Object [list.size()]); 708 } catch (NullPointerException ex) { 709 throw new DException("DSE3523", null); 710 } 711 } 712 713 private FieldBase[] getFieldAllColumnValues() throws DException { 714 try { 715 ArrayList list = new ArrayList(); 716 for (int i = 0, length = tableAndIteratorMapping.length; i < length; i++) { 717 FieldBase[] values = ( (_Iterator) tableAndIteratorMapping[i][2]).fields( (_Reference[]) tableAndIteratorMapping[i][1]); 718 list.addAll(Arrays.asList(values)); 719 } 720 return (FieldBase[]) list.toArray(new FieldBase[list.size()]); 721 } catch (NullPointerException ex) { 722 throw new DException("DSE3523", null); 723 } 724 } 725 726 private FieldBase getFieldObject(int index, FieldBase[] row) throws DException { 727 try { 728 return row[selectedColumnMapping[index - 1] - 1]; 729 } catch (ArrayIndexOutOfBoundsException ex) { 730 throw ex; 731 } 732 } 733 734 public FieldBase field(_Reference references) throws com.daffodilwoods.database.resource.DException { 735 _Iterator iter = getIterator(references); 736 return iter != null ? iter.field(references) : (FieldBase) ( (ColumnDetails) references).run(variableValues); 737 } 738 739 public FieldBase[] fields(_Reference[] parm1) throws com.daffodilwoods.database.resource.DException { 740 int length = parm1.length; 741 FieldBase[] result = new FieldBase[length]; 742 for (int i = 0; i < length; i++) { 743 result[i] = field(parm1[i]); 744 } 745 return result; 746 } 747 748 public _ExecutionPlan getExecutionPlan() throws DException { 749 return new ExecutionPlan("SelectedColumnIterator", null, null, null, null); 750 } 751 752 public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException { 753 int length = 1; 754 ExecutionPlanForBrowser cplans[] = new ExecutionPlanForBrowser[length]; 755 cplans[0] = iterator.getExecutionPlanForBrowser(); 756 return new ExecutionPlanForBrowser("Select", "SELECT Column Iterator", cplans, null, null, null); 757 } 758 759 public Object [] getFunctionalColumnIteratorMapping() throws DException { 760 return functionalColumns != null ? new Object [] {functionalColumns, this} 761 : null; 762 } 763 764 public Object getSelectColumnValues() throws DException { 765 Object row = getNonSharableFieldSelColumnValues(); 766 return row; 767 } 768 769 public void flushInsertedRecord() throws DException { 770 } 771 772 public Object getColumnValueForReference(_Reference reference) throws DException { 773 _Iterator iter = getIterator(reference); 774 775 return iter != null ? getIterator(reference).getColumnValues(reference) : 776 ( (ColumnDetails) reference).run(variableValues); 777 778 } 779 780 public FieldBase getFieldValueForReference(_Reference reference) throws DException { 781 return getIterator(reference).field(reference); 782 } 783 784 protected _Iterator getIterator(_Reference reference) throws DException { 785 ColumnDetails column = (ColumnDetails) reference; 786 return getIteratorForGetIterator(column); 787 } 788 789 796 public boolean isUpdatable() throws DException { 797 return false; 798 } 799 800 806 public int[] getDataTypes() throws DException { 807 int length = selectColumnDetails.length; 808 int[] dataTypes = new int[length]; 809 for (int i = 0; i < length; i++) { 810 dataTypes[i] = selectColumnDetails[i].getDatatype(); 811 } 812 return dataTypes; 813 } 814 815 public Object getKey() throws com.daffodilwoods.database.resource.DException { 816 return iterator.getKey(); 817 } 818 819 public byte[] getByteKey() throws DException { 820 return iterator.getByteKey(); 821 } 822 823 public void moveByteKey(byte[] key) throws DException { 824 iterator.moveByteKey(key); 825 } 826 827 public Object getColumnValues(int[] parm1) throws com.daffodilwoods.database.resource.DException { 828 return iterator.getColumnValues(parm1); 829 } 830 831 public _Order getDefaultOrder() throws DException { 832 return iterator.getDefaultOrder(); 833 } 834 835 public Object [][] getFunctionalColumnMapping() throws DException { 836 return iterator.getFunctionalColumnMapping(); 837 } 838 839 public Object moveToInsertRow() throws DException { 840 throw new UnsupportedOperationException (); 841 } 842 843 public _QueryPlan getQueryPlan() throws DException { 844 throw new UnsupportedOperationException (); 845 } 846 847 public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database.resource.DException { 848 throw new java.lang.UnsupportedOperationException ("Method fields() not yet implemented."); 849 } 850 851 public Object insert(int[] columns, Object [] values) throws DException { 852 throw new UnsupportedOperationException ("Method does not return value"); 853 } 854 855 public void delete(Object key) throws DException { 856 throw new UnsupportedOperationException ("Method does not return value"); 857 } 858 859 public Object update(Object key, int[] columns, Object [] values, Object row) throws DException { 860 throw new UnsupportedOperationException ("Method does not return value"); 861 } 862 863 864 private void initializeRowReader(_ColumnCharacteristics columnCharacteristics, ForeignKeyColumns[] foreignColumns) throws DException { 865 rowReader = new SelectRowReader(columnCharacteristics, foreignColumns); 866 } 867 868 869 870 public String toString() { 871 return "SelectedColumnIterator[" + iterator + "]"; 872 } 873 874 875 private _Iterator getIteratorForGetIterator(ColumnDetails column) throws DException { 876 if (column.getTable() != null) { 877 for (int i = 0, length = groupMapping.length; i < length; i++) { 878 TableDetails mappingTable = (TableDetails) groupMapping[i][3]; 879 if (mappingTable == column.getTable()) { 880 return (_Iterator) groupMapping[i][0]; 881 } 882 } 883 return iterator; 884 } 885 886 for (int i = 0, length = groupMapping.length; i < length; i++) { 887 ColumnDetails mappingColumn = ( (ColumnDetails[]) groupMapping[i][1])[0]; 888 if (column.getAppropriateColumn().equalsIgnoreCase(mappingColumn.getAppropriateColumn())) { 889 return (_Iterator) groupMapping[i][0]; 890 } 891 } 892 return iterator; 893 894 } 895 private Object [] getNonSharableAllCOlumnValues(ArrayList alist) throws DException { 896 try { 897 for (int i = 0, length = tableAndIteratorMapping.length; i < length; i++) { 898 Object [] values = (Object []) ( (_Iterator) tableAndIteratorMapping[i][2]).getColumnValues( (_Reference[]) tableAndIteratorMapping[i][1]); 899 alist.addAll(Arrays.asList(values)); 900 } 901 return (Object []) alist.toArray(new Object [alist.size()]); 902 } catch (NullPointerException ex) { 903 throw new DException("DSE3523", null); 904 } 905 } 906 907 908 909 910 } 911 | Popular Tags |