1 package com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression. 2 queryspecification; 3 4 import java.util.*; 5 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.listenerevents.*; 12 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.*; 13 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*; 14 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*; 15 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.*; 16 import com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata.*; 17 import com.daffodilwoods.daffodildb.server.sql99.dql.semanticchecker.*; 18 import com.daffodilwoods.daffodildb.server.sql99.dql.tableexpression.*; 19 import com.daffodilwoods.daffodildb.server.sql99.expression. 20 booleanvalueexpression.*; 21 import com.daffodilwoods.daffodildb.server.sql99.token.*; 22 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 23 import com.daffodilwoods.daffodildb.utils.parser.*; 24 import com.daffodilwoods.database.resource.*; 25 import com.daffodilwoods.database.sqlinitiator.*; 26 import com.daffodilwoods.database.utility.P; 27 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.order._OrderPlan; 28 29 48 49 public class queryspecification 50 implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter, 51 simpletable, TypeConstants { 52 53 57 58 public tableexpression _tableexpression0; 59 60 63 64 public selectlist _selectlist1; 65 66 69 70 public topfunction _Opttopfunction2; 71 72 76 77 public setquantifier _Optsetquantifier3; 78 79 82 83 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439224; 84 85 88 89 private ColumnDetails[] selectListColumnDetails; 90 91 94 95 private SemanticChecker semanticChecker; 96 97 100 101 private boolean isDistinct; 102 103 107 108 private _Reference[] underlyingReferencesSolvableByCurrentIterator; 109 110 113 114 private _OrderByClause orderByClause; 115 116 124 125 private _QueryColumns initializeQueryColumns(ColumnDetails[] 126 cdsWithActualTableDetails) throws 127 DException { 128 HashMap mappingOfTableColumns = semanticChecker. 129 getMappingOfTableDetailsAndColumnsBelonging(); 130 addColumnsInHashMap(cdsWithActualTableDetails, mappingOfTableColumns); 131 132 133 addUnderLyingRefInHashMap(mappingOfTableColumns); 134 135 136 QueryColumns queryColumns = new QueryColumns(mappingOfTableColumns); 137 queryColumns.setHasRecordMapping(semanticChecker.getHasRecordMapping()); 138 return queryColumns; 139 } 140 141 150 151 private _TablePlan getPlan(_TablePlan tableExpressionTablePlan, 152 _ServerSession session, _Order order) throws 153 DException { 154 155 TableDetails[] tableDetails = getTableDetails(); 156 _Reference[] selectReferences = _selectlist1.getReferences(tableDetails); 157 tableExpressionTablePlan = createGroupByPlan(tableExpressionTablePlan, 158 session); 159 QuerySpecificationPlan plan = new QuerySpecificationPlan(createDistinctPlan( 160 tableExpressionTablePlan, selectReferences), selectListColumnDetails, 161 semanticChecker, selectReferences, _Opttopfunction2, _tableexpression0, null, this); 162 plan.setOrder(order); 163 return plan; 164 } 165 166 176 177 public void getColumnsIncluded(ArrayList aList) throws DException { 178 _selectlist1.getColumnsIncluded(aList); 179 _tableexpression0.getColumnsIncluded(aList); 180 } 181 182 192 193 public void getTablesIncluded(ArrayList aList) throws DException { 194 _tableexpression0.getTablesIncluded(aList); 195 } 196 197 public ColumnDetails[] getColumnDetails() throws DException { 198 return semanticChecker.getDerivedColumnDetails(); 199 } 200 201 211 212 public ParameterInfo[] getParameterInfo() throws DException { 213 ParameterInfo[] pi = _tableexpression0.getParameterInfo(); 214 ParameterInfo[] arr = _selectlist1.getParameterInfo(); 215 216 if (pi == null && arr == null) 217 return null; 218 int j = 0; 219 ArrayList aList = new ArrayList(5); 220 221 if (arr != null) { 222 for (int i = 0; i < arr.length; i++) { 223 if (arr[i].getQuestionMark()) { 224 if (arr[i].getName() == null) { 225 arr[i].setName("Expr" + j++); 226 } 227 aList.add(arr[i]); 228 } 229 else if (arr[i].getSubQuery()) { 230 GeneralPurposeStaticClass.addRecursivelyParameterInfoOfSubquery(aList,arr[i].getParameterInfoArray(),j); 231 } 232 233 } 234 } 235 236 if (pi != null) { 237 for (int i = 0; i < pi.length; i++) { 238 if (pi[i].getQuestionMark()) { 239 if (pi[i].getName() == null) { 240 pi[i].setName("Expr" + j++); 241 } 242 aList.add(pi[i]); 243 } 244 } 245 } 246 247 return aList.size() == 0 ? null : 248 (ParameterInfo[]) aList.toArray(new ParameterInfo[0]); 249 } 250 251 257 258 public Object [] getParameters(Object object) throws DException { 259 Object [] obj1 = _selectlist1.getParameters(object); 260 Object [] obj2 = _tableexpression0.getParameters(object); 261 return GeneralPurposeStaticClass.getCombinedArray(obj1,obj2); 262 } 263 264 265 272 273 public String [] getGroupByPrimaryColumns() throws DException { 274 ArrayList list = new ArrayList(); 275 semanticChecker.getGroupByPrimaryColumns(list); 276 String [] groupByprimaryColumns = null; 277 if (!list.isEmpty()) { 278 groupByprimaryColumns = (String []) list.toArray(new String [list.size()]); 279 } 280 return groupByprimaryColumns; 281 } 282 283 290 public _ColumnCharacteristics getColumnCharacteristics(Object object) throws 291 DException { 292 switch ( ( (_ServerSession) object).getType()) { 293 case IteratorConstants.UPDATABLE: 294 return new SelectColumnCharacteristics(selectListColumnDetails, 295 addColumnInitialIndex( 296 getAllTableDetails()), getGroupByPrimaryColumns(), 297 isDistinct || 298 _tableexpression0. 299 _Optgroupbyclause1 != null, 300 ( (_ServerSession) object). 301 getType() == 302 IteratorConstants.UPDATABLE); 303 case IteratorConstants.NONSCROLLABLE: 304 return new SelectColumnCharacteristics(selectListColumnDetails, 305 addColumnInitialIndex( 306 getAllTableDetails()), false); 307 } 308 throw new DException("DSE3522", 309 new Object [] {new Integer ( ( (_ServerSession) object). 310 getType())}); 311 } 312 313 320 321 private Object [][] addColumnInitialIndex(TableDetails[] tableDetails) throws 322 DException { 323 int length = tableDetails.length; 324 Object [][] newMapping = new Object [length][3]; 325 int index = 1; 326 for (int i = 0; i < length; ++i) { 327 newMapping[i][0] = tableDetails[i]; 328 newMapping[i][1] = tableDetails[i].cc; 329 newMapping[i][2] = new Integer (index); 330 index = index + tableDetails[i].cc.getColumnCount(); 331 } 332 return newMapping; 333 } 334 335 350 351 public _Reference[] checkSemantic(_ServerSession session, 352 _OrderByClause orderClause, 353 boolean checkUserRight, 354 boolean checkSetOperatorPresent) throws 355 DException { 356 isDistinct = isDistinct(); 357 orderByClause = orderClause; 358 semanticChecker = getSemanticChecker(session, orderClause); 360 361 362 363 364 if (checkSetOperatorPresent) { 365 if (semanticChecker.containsClauseFlag) 366 throw new DException("DSE0", 367 new Object [] {"Contains Not allowed in Set Query "}); 368 } 369 370 ColumnDetails[] queryColumns = semanticChecker.getAllColumnsInvolvedInQuery(); 371 372 semanticChecker.setTableDetails(_tableexpression0.getTableDetails(session, 373 queryColumns)); semanticChecker.check(session); 375 selectListColumnDetails = semanticChecker.getDerivedColumnDetails(); 376 377 _Reference[] references = GeneralPurposeStaticClass.getJointReferences( 378 _selectlist1.checkSemantic(session), 379 _tableexpression0.checkSemantic(session, queryColumns, checkUserRight)); ColumnDetails[] unResolvedReferences = changeReferencesToColumns(references); 381 _Reference[] underLyingReferences = semanticChecker. 382 checkForUnderLyingReferences(unResolvedReferences); 383 underLyingReferences = GeneralPurposeStaticClass.getJointReferences( 384 underLyingReferences, extractQuestionMarcks(references)); 385 getUnderlyingReferencesSolvableByCurrentIterator( (_Reference[]) 386 unResolvedReferences, underLyingReferences); 387 _Reference[] re = getUnderlyingReferences(underLyingReferences); 388 389 390 return re; 391 } 392 393 398 399 private boolean isDistinct() throws DException { 400 if (_Optsetquantifier3 != null) { 401 if ( ( (String ) _Optsetquantifier3.run(null)).equalsIgnoreCase("DISTINCT")) { 402 return true; 403 } 404 } 405 return false; 406 } 407 408 414 415 private _Reference[] getUnderlyingReferences(_Reference[] 416 underLyingReferences) throws 417 DException { 418 _Reference[] underLyingReferences1 = semanticChecker. 419 getUnderLyingReferences(); 420 underLyingReferences = GeneralPurposeStaticClass.getJointReferences( 421 underLyingReferences, underLyingReferences1); 422 underLyingReferences = GeneralPurposeStaticClass.getJointReferences( 423 underLyingReferences, _tableexpression0.getUnderlyingReferences()); 424 return underLyingReferences; 425 } 426 427 434 435 private _Reference[] extractQuestionMarcks(_Reference[] references) throws 436 DException { 437 if (references == null) { 438 return null; 439 } 440 ArrayList aList = new ArrayList(5); 441 for (int i = 0; i < references.length; i++) { 442 if (references[i] instanceof variablecolumn) { 443 aList.add(references[i]); 444 } 445 } 446 int size = aList.size(); 447 return size == 0 ? null : (_Reference[]) aList.toArray(new _Reference[size]); 448 } 449 450 457 private ColumnDetails[] changeReferencesToColumns(_Reference[] references) throws 458 DException { 459 if (references == null) { 460 return null; 461 } 462 ArrayList aList = new ArrayList(5); 463 for (int i = 0; i < references.length; i++) { 464 if (references[i] instanceof ColumnDetails) { 465 aList.add(references[i]); 466 } 467 } 468 return (ColumnDetails[]) aList.toArray(new ColumnDetails[0]); 469 } 470 471 486 private SemanticChecker getSemanticChecker(_ServerSession session, 487 _OrderByClause orderByClause) throws 488 DException { 489 ColumnDetails[] selectCD = _selectlist1.getColumnDetails(); 490 ColumnDetails[] fromCD = _tableexpression0.getFromClauseColumnDetails(); 491 ColumnDetails[] whereCD = _tableexpression0.getWhereClauseColumnDetails(); 492 ColumnDetails[] groupCD = _tableexpression0.getGroupByColumnDetails(); 493 ColumnDetails[] havingCD = _tableexpression0.getHavingClauseColumnDetails(); 494 ColumnDetails[] orderCD = orderByClause != null ? 495 orderByClause.getColumnDetails() 496 : null; 497 ColumnDetails[] orderKeyCD = orderByClause != null ? 498 orderByClause.getKeyColumnDetails() 499 : null; 500 return new SemanticChecker(session, whereCD, groupCD, havingCD, orderCD, 501 selectCD, fromCD, _selectlist1, orderKeyCD, 502 isDistinct); 503 } 504 505 510 511 public ColumnDetails[] getSelectedColumns() throws DException { 512 return selectListColumnDetails; 513 } 514 515 522 523 public _Reference[] checkSemantic(com.daffodilwoods.daffodildb.server. 524 serversystem._ServerSession parent, 525 boolean userRightCheck) throws DException { 526 throw new UnsupportedOperationException ("Method not Supported"); 527 } 528 529 537 private void addColumnsInHashMap(ColumnDetails[] columnDetails, 538 HashMap mappingOfTableColumns) throws 539 DException { 540 if (columnDetails == null) { 541 return; 542 } 543 for (int i = 0, length = columnDetails.length; i < length; i++) { 544 TableDetails td = columnDetails[i].getTableDetails(); 545 ColumnDetails[] existing = (ColumnDetails[]) mappingOfTableColumns.get(td); 546 ColumnDetails[] result = addInArray(existing, columnDetails[i]); 547 mappingOfTableColumns.put(td, result); 548 } 549 } 550 551 558 559 private ColumnDetails[] addInArray(ColumnDetails[] source, 560 ColumnDetails toAdd) throws DException { 561 if (source == null) { 562 return new ColumnDetails[] { 563 toAdd}; 564 } 565 int length = source.length; 566 ColumnDetails[] result = new ColumnDetails[length + 1]; 567 System.arraycopy(source, 0, result, 0, length); 568 result[length] = toAdd; 569 return result; 570 } 571 572 573 645 646 public _TablePlan getExecutionPlan(_ServerSession session, 647 booleanvalueexpression bve, 648 _DatedFramework datedCondition, 649 _Order order, 650 ColumnDetails[] cdsWithActualTableDetails, 651 ConditionArray conditionArray) throws 652 DException { 653 _QueryColumns queryColumns = initializeQueryColumns( 654 cdsWithActualTableDetails); 655 if (checkForDistinctRedundant(session)) { 656 isDistinct = false; 657 semanticChecker.setDistinctRedundant(); 658 } 659 660 _Order[] adjustedOrder = isDistinct ? 661 getAdjustedQuerySpecificationOrderAndTEOrder(order) 662 : new _Order[] { 663 order, null}; 664 665 if( order != null){ 666 _OrderPlan orderPlan = order.getOrderPlan(session); 667 if( orderPlan.getQueryLevelOrderPlans()!= null ) 668 { 669 adjustedOrder[1] = adjustedOrder[0]; 670 adjustedOrder[0] = null; 671 } 672 } 673 674 _TablePlan tablePlan = _tableexpression0.getExecutionPlan(session, bve, 675 datedCondition, queryColumns, adjustedOrder[0], conditionArray); 676 return getPlan(tablePlan, session, adjustedOrder[1]); 677 678 679 } 680 681 682 690 691 private boolean handleAggregateForIndex(TableExpressionPlan tablePlan, 692 _ServerSession session) throws 693 DException { 694 TableDetails[] tables = semanticChecker.getTableDetails(); 695 if (tables.length == 1 && tables[0].getTableType() != TypeConstants.VIEW && 696 _tableexpression0.getWhereClause() == null 697 && _tableexpression0.getGroupByClause() == null) { 698 ColumnDetails[] aggregateColumnsForINdexing = 699 getAggregateColumnForIndexing(); 700 if (aggregateColumnsForINdexing != null && 701 tablePlan. 702 setAggregateColumnsForIndexing(aggregateColumnsForINdexing, session)) { 703 return true; 704 } 705 } 706 return false; 707 } 708 709 720 private ColumnDetails[] getAggregateColumnForIndexing() throws DException { 721 ColumnDetails[] aggregateColumns = semanticChecker.getAllAggregateColumns(); 722 int length = aggregateColumns.length; 723 ColumnDetails column = aggregateColumns[0]; 724 String functionType = column.getFunctionType(); 725 String quantifier = column.getQuantifier(); 726 ColumnDetails[] childs = column.getExistingColumnDetails(); 727 if ( (functionType.equalsIgnoreCase("Max") || 728 functionType.equalsIgnoreCase("Min")) && childs.length == 1 && 729 childs[0].getType() == REFERENCE) { 730 if (length > 1) { 731 String columnName = childs[0].getAppropriateColumn(); 732 for (int i = 1; i < length; i++) { 733 ColumnDetails column1 = aggregateColumns[i]; 734 ColumnDetails[] childs1 = column1.getExistingColumnDetails(); 735 if (childs1.length != 1 || childs1[0].getType() != REFERENCE || 736 !column1.getFunctionType().equalsIgnoreCase(functionType) || 737 !column1.getQuantifier().equalsIgnoreCase(quantifier) || 738 !childs1[0].getAppropriateColumn().equalsIgnoreCase(columnName)) { 739 return null; 740 } 741 } 742 } 743 return aggregateColumns; 744 } 745 return null; 746 } 747 748 753 public void setFKeyColumnDetails(ColumnDetails[] fKeyColumns) throws 754 DException { 755 int existingLength = selectListColumnDetails.length, 756 passedLength = fKeyColumns.length; 757 ColumnDetails[] newColumns = new ColumnDetails[existingLength + 758 passedLength]; 759 System.arraycopy(selectListColumnDetails, 0, newColumns, 0, existingLength); 760 System.arraycopy(fKeyColumns, 0, newColumns, existingLength, passedLength); 761 selectListColumnDetails = newColumns; 762 } 763 764 769 770 public QueryProperty getStrings() throws DException { 771 QueryProperty queryProperty = new QueryProperty(); 772 queryProperty.setFromClause(_tableexpression0.getfromClause()); 773 queryProperty.setWhereClause(_tableexpression0.getWhereClause()); 774 queryProperty.setGroupByClause(_tableexpression0.getGroupByClause()); 775 queryProperty.setHavingClause(_tableexpression0.getHavingClause()); 776 queryProperty.setColumnList(_selectlist1.toString()); 777 return queryProperty; 778 } 779 780 794 795 private _TablePlan createGroupByPlan(_TablePlan finalPlan, 796 _ServerSession session) throws 797 DException { 798 GroupByCondition groupCondition = null; 799 if (_tableexpression0._Optgroupbyclause1 != null) { 800 TableDetails[] td = getTableDetails(); 801 groupCondition = new GroupByCondition(_tableexpression0. 802 _Optgroupbyclause1, null, td); 803 } 804 ColumnDetails[] aggregateColumns = semanticChecker.getAllAggregateColumns(); 805 boolean indexUsedInAggregate = false; 806 if (aggregateColumns != null) { 807 indexUsedInAggregate = handleAggregateForIndex( (TableExpressionPlan) 808 finalPlan, session); 809 } 810 811 if (aggregateColumns != null || groupCondition != null) { 812 _Reference[] havingClauseUnderlyingReferences = null; 813 if (_tableexpression0._Opthavingclause0 != null) { 814 havingClauseUnderlyingReferences = _tableexpression0._Opthavingclause0. 815 getReferences(_tableexpression0.getTableDetails()); 816 havingClauseUnderlyingReferences = GeneralPurposeStaticClass. 817 getUnderLyingReferencesOnly(havingClauseUnderlyingReferences, 818 _tableexpression0.getTableDetails()); 819 } 820 finalPlan = new GroupByPlan(finalPlan, groupCondition, 821 _tableexpression0.getGroupByLevelOrder(), 822 aggregateColumns, 823 _tableexpression0.getAggregateCondition(), 824 indexUsedInAggregate, 825 havingClauseUnderlyingReferences); 826 } 827 828 return finalPlan; 829 } 830 831 841 private _TablePlan createDistinctPlan(_TablePlan finalPlan, 842 _Reference[] selectReferences) throws 843 DException { 844 return isDistinct ? 845 new DistinctPlan(finalPlan, null, selectListColumnDetails, 846 selectReferences) 847 : finalPlan; 848 } 849 850 860 private _Order[] createOrdersWhenNoOrderByButDistinctPresent(ColumnDetails[] 861 appSelectedColumn) throws DException { 862 return new _Order[] { 863 new SelectOrder(appSelectedColumn), null}; 864 } 865 866 874 private _Order[] createOrderWhenOrderByColsIsNotPresentInSelectedCols(_Order 875 order, ColumnDetails[] appSelectedColumn) throws DException { 876 SelectOrder distinctOrder = new SelectOrder(appSelectedColumn); 877 return new _Order[] { 878 distinctOrder, order}; 879 } 880 881 889 private _Order[] createOrderWhenOrderByColsIsPresentInSelectedCols(Object [] 890 adjustedIndexesAndOrder, ColumnDetails[] appSelectedColumn) throws 891 DException { 892 ColumnDetails[] adjustedColumnDetails = GeneralPurposeStaticClass. 893 getColumnDetailsAccToIndexes( (int[]) adjustedIndexesAndOrder[0], 894 appSelectedColumn); 895 SelectOrder distinctOrder = new SelectOrder(adjustedColumnDetails, 896 (boolean[]) 897 adjustedIndexesAndOrder[ 898 1]); 899 return new _Order[] { 900 distinctOrder, null}; 901 } 902 903 913 914 private _Order[] getAdjustedQuerySpecificationOrderAndTEOrder(_Order order) throws 915 DException { 916 ColumnDetails[] appSelectedColumns = semanticChecker. 917 getAppropriateUserDefinedColumns(); 918 if (order == null) { 919 return createOrdersWhenNoOrderByButDistinctPresent(appSelectedColumns); 920 } 921 Object [] adjustedIndexesAndOrder = 922 GeneralPurposeStaticClass. 923 getColumnIndexesAndBooleanOrderOfAdjustedOrder(order, appSelectedColumns,true); 924 925 if (adjustedIndexesAndOrder == null) { 926 return createOrderWhenOrderByColsIsNotPresentInSelectedCols(order, 927 appSelectedColumns); 928 } 929 return createOrderWhenOrderByColsIsPresentInSelectedCols( 930 adjustedIndexesAndOrder, appSelectedColumns); 931 } 932 933 939 private void getUnderlyingReferencesSolvableByCurrentIterator(_Reference[] 940 allUnderlyingRef, _Reference[] underLyingRefNotSolvableByCurrentLevel) throws 941 DException { 942 if (allUnderlyingRef == null) { 943 return; 944 } 945 if (underLyingRefNotSolvableByCurrentLevel == null) { 946 underlyingReferencesSolvableByCurrentIterator = allUnderlyingRef; 947 return; 948 } 949 ArrayList aList = new ArrayList(); 950 boolean found = false; 951 for (int i = 0, length = allUnderlyingRef.length; i < length; i++) { 952 found = false; 953 for (int j = 0, len = underLyingRefNotSolvableByCurrentLevel.length; 954 j < len; j++) { 955 if (allUnderlyingRef[i] == underLyingRefNotSolvableByCurrentLevel[j]) { 956 found = true; 957 break; 958 } 959 } 960 if (!found) { 961 aList.add(allUnderlyingRef[i]); 962 } 963 } 964 underlyingReferencesSolvableByCurrentIterator = (_Reference[]) aList. 965 toArray(new _Reference[0]); 966 } 967 968 public String toString() { 969 StringBuffer sb = new StringBuffer (); 970 sb.append(" "); 971 sb.append(_SRESERVEDWORD12065439224); 972 sb.append(" "); 973 if (_Optsetquantifier3 != null) { 974 sb.append(_Optsetquantifier3); 975 } 976 sb.append(" "); 977 if (_Opttopfunction2 != null) { 978 sb.append(_Opttopfunction2); 979 } 980 sb.append(" "); 981 sb.append(_selectlist1); 982 sb.append(" "); 983 sb.append(_tableexpression0); 984 return sb.toString(); 985 } 986 987 public Object clone() throws CloneNotSupportedException { 988 queryspecification tempClass = new queryspecification(); 989 tempClass._tableexpression0 = (tableexpression) _tableexpression0.clone(); 990 tempClass._selectlist1 = (selectlist) _selectlist1.clone(); 991 if (_Opttopfunction2 != null) { 992 tempClass._Opttopfunction2 = (topfunction) _Opttopfunction2.clone(); 993 } 994 if (_Optsetquantifier3 != null) { 995 tempClass._Optsetquantifier3 = (setquantifier) _Optsetquantifier3.clone(); 996 } 997 tempClass._SRESERVEDWORD12065439224 = (SRESERVEDWORD1206543922) 998 _SRESERVEDWORD12065439224.clone(); 999 return tempClass; 1000 } 1001 1002 1013 1014 public boolean isViewOptimizationPossible() throws DException { 1015 1016 1017 if (_Opttopfunction2 != null || _tableexpression0._Optgroupbyclause1 != null || 1018 semanticChecker.getAllAggregateColumns() != null || isDistinct || 1019 checkForFunctionalColInSelectList() || 1020 (underlyingReferencesSolvableByCurrentIterator != null 1021 && underlyingReferencesSolvableByCurrentIterator.length != 0)) { 1022 return false; 1023 } 1024 return true; 1025 } 1026 1027 1032 1033 private boolean checkForFunctionalColInSelectList() throws DException { 1034 ColumnDetails[] columns = _selectlist1.getDerivedColumnDetails(); 1035 for (int i = 0; i < columns.length; i++) { 1036 if (columns[i].getTable() == null) { 1037 return true; 1038 } 1039 } 1040 return false; 1041 } 1042 1043 1056 1057 1070 1071 public _TablePlan[] getTablePlans(_ServerSession session, 1072 booleanvalueexpression condition, 1073 _Order order, 1074 ColumnDetails[] cdsWithActualTableDetails, 1075 ConditionArray conditionArray) throws 1076 DException { 1077 _QueryColumns queryColumns = initializeQueryColumns( 1078 cdsWithActualTableDetails); 1079 _TablePlan[] tablePlans = _tableexpression0.getTablePlans(session, 1080 condition, order, queryColumns, conditionArray); 1081 return tablePlans.length == 1 && 1082 tablePlans[0] instanceof TableExpressionPlan ? new _TablePlan[] { 1083 getPlan(tablePlans[0], session, null)} 1084 : tablePlans; 1085 } 1086 1087 1094 1095 public _BVEPlan getBveExecutionPlan() throws DException { 1096 return _tableexpression0.getBveExecutionPlan(); 1097 } 1098 1099 1115 private boolean checkForDistinctRedundant(_ServerSession session) throws 1116 DException { 1117 if (!isDistinct) { 1118 return false; 1119 } 1120 TableDetails[] td = _tableexpression0.getTableDetails(session, null); 1121 return td.length == 1 && td[0].getTableType() == TypeConstants.TABLE 1122 && checkForPk(session, td[0]) ? true : checkDistinctWithGroupBy(); 1123 } 1124 1125 1146 private boolean checkForPk(_ServerSession session, TableDetails tableDetails) throws 1147 DException { 1148 String [] pks = ( (_ServerSession) session).getUniqueInformation( 1149 tableDetails.getQualifiedIdentifier()); 1150 if (pks == null) { 1151 return false; 1152 } 1153 ColumnDetails[] selectedColumns = semanticChecker.getDerivedColumnDetails(); 1154 for (int i = 0; i < pks.length; i++) { 1155 int j = 0; 1156 for (; j < selectedColumns.length; j++) { 1157 if (selectedColumns[j].getType() == REFERENCE) { 1158 if (pks[i].equalsIgnoreCase(selectedColumns[j].getAppropriateColumn())) { 1159 break; 1160 } 1161 } 1162 } 1163 if (j == selectedColumns.length) { 1164 return false; 1165 } 1166 } 1167 return true; 1168 } 1169 1170 1187 private boolean checkDistinctWithGroupBy() throws DException { 1188 ColumnDetails[] groupColumns = _tableexpression0.getGroupByColumnDetails(); 1189 if (groupColumns == null) { 1190 return false; 1191 } 1192 ColumnDetails[] selectedColumns = semanticChecker.getDerivedColumnDetails(); 1193 for (int i = 0; i < groupColumns.length; i++) { 1194 String column = groupColumns[i].getAppropriateColumn(); 1195 int j = 0; 1196 for (; j < selectedColumns.length; j++) { 1197 if (column.equalsIgnoreCase(selectedColumns[j].getAppropriateColumn())) { 1198 break; 1199 } 1200 } 1201 if (j == selectedColumns.length) { 1202 return false; 1203 } 1204 } 1205 return true; 1206 } 1207 1208 public Object run(Object object) throws DException { 1209 throw new UnsupportedOperationException ("Method not supported"); 1210 } 1211 1212 1217 public void setDefaultValues(_VariableValueOperations variableValueOperation) throws 1218 DException { 1219 _tableexpression0.setDefaultValues(variableValueOperation); 1220 } 1221 1222 public _Reference[] getReferences(TableDetails[] tableDetails) throws 1223 DException { 1224 return GeneralPurposeStaticClass.getJointReferences(_selectlist1. 1225 getReferences(getTableDetails()), 1226 _tableexpression0.getReferences(getTableDetails())); 1227 } 1228 1229 public void setTablesForInsertion(ColumnMappingHandler parm1, 1230 _VariableValueOperations vv) throws com. 1231 daffodilwoods.database.resource.DException { 1232 _tableexpression0.setTablesForInsertion(parm1, vv); 1233 } 1234 1235 public TableDetails[] getTablesForBlankInsert() throws com.daffodilwoods. 1236 database.resource.DException { 1237 return _tableexpression0._fromclause3.getTablesForBlankInsert(); 1238 } 1239 1240 public TableDetails[] getAllTableDetails() throws DException { 1241 return _tableexpression0.getAllTableDetails(); 1242 } 1243 1244 public TableDetails[] getTableDetails() throws DException { 1245 return _tableexpression0.getTableDetails(); 1246 } 1247 1248 public void verifyValues(_VariableValueOperations vv) throws DException { 1249 _tableexpression0.verifyValues(vv); 1250 } 1251 1252 public TableDetails[] getViewTableDetails() throws DException { 1253 return _tableexpression0.getViewTableDetails(); 1254 } 1255 1256 public boolean isSimpleQuery(_ServerSession serverSession) throws DException { 1257 boolean refType = true; 1258 ColumnDetails[] cds = _selectlist1.getDerivedColumnDetails(); 1259 for (int i = 0; cds != null && i < cds.length; i++) { 1260 if (cds[i].getType() == ColumnDetails.SCALARSUBQUERY || cds[i].getType() == ColumnDetails.GROUPING) { 1261 refType = false; 1262 break; 1263 } 1264 } 1265 return refType && !isDistinct && orderByClause == null && 1266 _tableexpression0.isSimpleQuery(serverSession); 1267 } 1268 1269 public void checkSemanticForUpdate() throws DException { 1270 _tableexpression0.checkSemanticForUpdate(); 1271 if (semanticChecker.getAllAggregateColumns() != null || isDistinct) { 1272 throw new DException("DSE0", null); 1273 } 1274 } 1275 1276 public boolean hasConstantSelectedColumn(booleanvalueexpression bve) throws 1277 DException { 1278 if (bve != null) { 1279 ColumnDetails cds[] = bve.getColumnDetails(); 1280 ArrayList arr = new ArrayList(cds.length); 1281 GeneralPurposeStaticClass.addRecursively(cds,arr); 1282 for (int i = 0,length = arr.size(); i < length; i++) { 1283 ColumnDetails cd = (ColumnDetails)arr.get(i); 1284 if(cd.getType() == REFERENCE){ 1285 for (int j = 0; j < selectListColumnDetails.length; j++) { 1286 if( cd.getAppropriateColumn().equalsIgnoreCase(selectListColumnDetails[j].getAppropriateColumn())){ 1287 if( selectListColumnDetails[j].getType() != REFERENCE ) 1288 return true; 1289 break ; 1290 } 1291 } 1292 } 1293 } 1294 } 1295 return false; 1296 } 1297 1298 1299 private void addUnderLyingRefInHashMap(HashMap mappingOfTableColumns) throws 1300 DException { 1301 if (underlyingReferencesSolvableByCurrentIterator != null) { 1302 for (int i = 0, 1303 length = underlyingReferencesSolvableByCurrentIterator.length; 1304 i < length; i++) { 1305 ColumnDetails cd = (ColumnDetails) 1306 underlyingReferencesSolvableByCurrentIterator[i]; 1307 TableDetails td = cd.getTable(); 1308 ColumnDetails[] existing = (ColumnDetails[]) mappingOfTableColumns.get( 1309 td); 1310 ColumnDetails[] result = addInArray(existing, cd); 1311 mappingOfTableColumns.put(td, result); 1312 } 1313 } 1314 } 1315 1316 public void showMap(String message, Map map) { 1317 Set set = map.entrySet(); 1318 Iterator iter = set.iterator(); 1319 while (iter.hasNext()) { 1320 Map.Entry me = (Map.Entry) iter.next(); 1321 } 1322 1323 } 1324} 1325 | Popular Tags |