| 1 package com.daffodilwoods.daffodildb.server.sql99.dql.iterator.set; 2 3 import com.daffodilwoods.daffodildb.client.*; 4 import com.daffodilwoods.daffodildb.server.sql99.common.*; 5 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 7 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 8 import com.daffodilwoods.daffodildb.utils.comparator.*; 9 import com.daffodilwoods.daffodildb.utils.field.*; 10 import com.daffodilwoods.database.resource.*; 11 import com.daffodilwoods.database.utility.*; 12 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem. 13 TableKeyColumnInformation; 14 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs; 15 16 39 40 public class UnionAllOrderedIterator 41 extends BaseJoinIterator 42 implements SimpleConstants { 43 44 47 protected _Reference[] leftColumnReferences; 49 52 protected _Reference[] rightColumnReferences; 54 57 protected _Reference[] orderLeftCD; 58 59 62 protected _Reference[] orderRightCD; 63 64 68 protected SuperComparator comparator; 69 70 74 protected int direction; 76 79 protected int[] appropriateDataTypes; 80 81 84 protected int[] appropriateSizes; 85 86 90 private boolean[] leftConversion; 91 92 96 private boolean[] rightConversion; 97 98 public UnionAllOrderedIterator(_Iterator leftIterator, 99 _Iterator rightIterator, 100 _Reference[] leftColumnReferences0, 101 _Reference[] rightColumnReferences0, 102 int[] appropriateDataTypes0, 103 int[] appropriateSizes0, 104 _Reference[] orderLeftCD0, 105 _Reference[] orderRightCD0) throws DException { 106 super(leftIterator, rightIterator); 107 leftColumnReferences = leftColumnReferences0; 108 rightColumnReferences = rightColumnReferences0; 109 appropriateDataTypes = appropriateDataTypes0; 110 appropriateSizes = appropriateSizes0; 111 orderLeftCD = orderLeftCD0; 112 orderRightCD = orderRightCD0; 113 } 114 115 143 public UnionAllOrderedIterator(_Iterator leftIterator, 144 _Iterator rightIterator, 145 _Reference[] leftColumnReferences0, 146 _Reference[] rightColumnReferences0, 147 SuperComparator comparator0, 148 int[] appropriateDataTypes0, 149 int[] appropriateSizes0, 150 _Reference[] orderLeftCD0, 151 _Reference[] orderRightCD0) throws DException { 152 super(leftIterator, rightIterator); 153 leftColumnReferences = leftColumnReferences0; 154 rightColumnReferences = rightColumnReferences0; 155 comparator = comparator0; 156 appropriateDataTypes = appropriateDataTypes0; 157 appropriateSizes = appropriateSizes0; 158 orderLeftCD = orderLeftCD0; 159 orderRightCD = orderRightCD0; 160 } 161 162 boolean flag = false; 163 164 190 public boolean first() throws DException { 191 direction = FORWARD; 192 boolean leftFlag = leftIterator.first(); 193 boolean rightFlag = rightIterator.first(); 194 state = leftFlag ? rightFlag ? 195 compare(leftIterator.getColumnValues(orderLeftCD), 196 rightIterator.getColumnValues(orderRightCD)) <= 0 ? 197 FIRSTISCURRENT : SECONDISCURRENT 198 : ONLYFIRSTHAVEDATA 199 : rightFlag ? ONLYSECONDHAVEDATA 200 : AFTERLAST; 201 return state != AFTERLAST; 202 } 203 204 227 public boolean last() throws DException { 228 direction = BACKWARD; 229 boolean leftFlag = leftIterator.last(); 230 boolean rightFlag = rightIterator.last(); 231 state = leftFlag ? rightFlag ? 232 compare(leftIterator.getColumnValues(orderLeftCD), 233 rightIterator.getColumnValues(orderRightCD)) <= 0 ? 234 SECONDISCURRENT : FIRSTISCURRENT 235 : ONLYFIRSTHAVEDATA 236 : rightFlag ? ONLYSECONDHAVEDATA 237 : BEFOREFIRST; 238 return state != BEFOREFIRST; 239 } 240 241 306 public boolean next() throws DException { 307 switch (state) { 308 case INVALIDSTATE: 309 throw new DException("DSE4116", null); 310 case BEFOREFIRST: 311 return first(); 312 case AFTERLAST: 313 return false; 314 case ONLYFIRSTHAVEDATA: 315 if (direction == BACKWARD) { 316 return iteratePositiveAfterNegativeWhenOneHasData(leftIterator, 317 rightIterator, orderLeftCD, orderRightCD); 318 } 319 direction = FORWARD; 320 boolean flag = leftIterator.next(); 321 state = flag ? state : AFTERLAST; 322 return flag; 323 case ONLYSECONDHAVEDATA: 324 if (direction == BACKWARD) { 325 return iteratePositiveAfterNegativeWhenOneHasData(rightIterator, 326 leftIterator, orderRightCD, orderLeftCD); 327 } 328 direction = FORWARD; 329 boolean b = rightIterator.next(); 330 state = b ? state : AFTERLAST; 331 return b; 332 case FIRSTISCURRENT: 333 if (direction == BACKWARD) { 334 return iteratePositiveAfterNegativeWhenOneIsCurrent(leftIterator, 335 rightIterator, orderLeftCD, orderRightCD); 336 } 337 return iteratePositive(leftIterator, rightIterator, 1, orderLeftCD, 338 orderRightCD); 339 case SECONDISCURRENT: 340 if (direction == BACKWARD) { 341 return iteratePositiveAfterNegativeWhenOneIsCurrent(rightIterator, 342 leftIterator, orderRightCD, orderLeftCD); 343 } 344 return iteratePositive(rightIterator, leftIterator, -1, orderRightCD, 345 orderLeftCD); 346 } 347 return false; 348 } 349 350 382 private boolean iteratePositive(_Iterator currentIterator, 383 _Iterator otherIterator, int reverse, 384 _Reference[] currentReferences, 385 _Reference[] otherReferences) throws 386 DException { 387 direction = FORWARD; 388 Object toCompare = currentIterator.getColumnValues(currentReferences); 389 boolean flag = currentIterator.next(); 390 if (!flag) { 391 state = reverse == 1 ? ONLYSECONDHAVEDATA : ONLYFIRSTHAVEDATA; 392 return true; 393 } 394 Object first = currentIterator.getColumnValues(currentReferences); 395 Object second = otherIterator.getColumnValues(otherReferences); 396 state = reverse == 1 ? compare(first, second) <= 0 ? FIRSTISCURRENT : 397 SECONDISCURRENT 398 : compare(second, first) <= 0 ? FIRSTISCURRENT : SECONDISCURRENT; 399 return true; 400 401 } 402 403 436 private boolean iteratePositiveAfterNegativeWhenOneIsCurrent(_Iterator 437 currentIterator, _Iterator otherIterator, _Reference[] currentReferences, 438 _Reference[] otherReferences) throws DException { 439 boolean currentNext = currentIterator.next(); 440 boolean otherNext = otherIterator.next(); 441 if (currentNext && otherNext) { 442 Object currentObject = currentIterator.getColumnValues(currentReferences); 443 Object otherObject = otherIterator.getColumnValues(otherReferences); 444 int cmp = compare(currentObject, otherObject); 445 if (cmp == 0) { 446 cmp = state; } if (cmp > 0) { 449 state = -state; 450 currentIterator.previous(); 451 } 452 else { 453 otherIterator.previous(); 454 } 455 } 456 else if (currentNext) { 457 otherIterator.last(); 458 } 459 else if (otherNext) { 460 currentIterator.last(); 461 state = -state; 462 } 463 else { 464 state = AFTERLAST; 465 return false; 466 } 467 return true; 468 } 469 470 508 private boolean iteratePositiveAfterNegativeWhenOneHasData(_Iterator 509 currentIterator, _Iterator otherIterator, _Reference[] currentReferences, 510 _Reference[] otherReferences) throws DException { 511 boolean currentNext = currentIterator.next(); 512 boolean otherFirst = otherIterator.first(); 513 if (currentNext && otherFirst) { 514 Object currentObject = currentIterator.getColumnValues(currentReferences); 515 Object otherObject = otherIterator.getColumnValues(otherReferences); 516 int cmp = compare(currentObject, otherObject); 517 if (cmp == 0) { 518 cmp = state; } if (cmp > 0) { 521 state = state == ONLYSECONDHAVEDATA ? FIRSTISCURRENT 522 : state == ONLYFIRSTHAVEDATA ? SECONDISCURRENT : state; 523 currentIterator.previous(); 524 } 525 else { 526 otherIterator.previous(); 527 } 528 } 529 else if (currentNext) { 530 } 531 else if (otherFirst) { 532 currentIterator.last(); 533 state = state == ONLYSECONDHAVEDATA ? FIRSTISCURRENT 534 : state == ONLYFIRSTHAVEDATA ? SECONDISCURRENT : state; 535 } 536 else { 537 state = AFTERLAST; 538 return false; 539 } 540 return true; 541 } 542 543 593 public boolean previous() throws com.daffodilwoods.database.resource. 594 DException { 595 switch (state) { 596 case INVALIDSTATE: 597 throw new DException("DSE4117", null); 598 case BEFOREFIRST: 599 return false; 600 case AFTERLAST: 601 return last(); 602 case ONLYFIRSTHAVEDATA: 603 if (direction == FORWARD) { 604 return iterateNegativeAfterPositiveWhenOneHasData(leftIterator, 605 rightIterator, orderLeftCD, orderRightCD); 606 } 607 direction = BACKWARD; 608 boolean flag = leftIterator.previous(); 609 state = flag ? state : BEFOREFIRST; 610 return flag; 611 case ONLYSECONDHAVEDATA: 612 if (direction == FORWARD) { 613 return iterateNegativeAfterPositiveWhenOneHasData(rightIterator, 614 leftIterator, orderRightCD, orderLeftCD); 615 } 616 direction = BACKWARD; 617 boolean b = rightIterator.previous(); 618 state = b ? state : BEFOREFIRST; 619 return b; 620 case FIRSTISCURRENT: 621 if (direction == FORWARD) { 622 return iterateNegativeAfterPositiveWhenOneIsCurrent(leftIterator, 623 rightIterator, orderLeftCD, orderRightCD); 624 } 625 return iterateNegative(leftIterator, rightIterator, 1, orderLeftCD, 626 orderRightCD); 627 case SECONDISCURRENT: 628 if (direction == FORWARD) { 629 return iterateNegativeAfterPositiveWhenOneIsCurrent(rightIterator, 630 leftIterator, orderRightCD, orderLeftCD); 631 } 632 return iterateNegative(rightIterator, leftIterator, -1, orderRightCD, 633 orderLeftCD); 634 } 635 return false; 636 } 637 638 676 private boolean iterateNegativeAfterPositiveWhenOneHasData(_Iterator 677 currentIterator, _Iterator otherIterator, _Reference[] currentReferences, 678 _Reference[] otherReferences) throws DException { 679 boolean currentPrevious = currentIterator.previous(); 680 boolean otherLast = otherIterator.last(); 681 if (currentPrevious && otherLast) { 682 Object currentObject = currentIterator.getColumnValues(currentReferences); 683 Object otherObject = otherIterator.getColumnValues(otherReferences); 684 int cmp = compare(currentObject, otherObject); 685 if (cmp == 0) { 686 cmp = state; } if (cmp < 0) { 689 state = state == ONLYSECONDHAVEDATA ? FIRSTISCURRENT 690 : state == ONLYFIRSTHAVEDATA ? SECONDISCURRENT : state; 691 currentIterator.next(); 692 } 693 else { 694 otherIterator.next(); 695 } 696 } 697 else if (currentPrevious) { 698 } 699 else if (otherLast) { 700 currentIterator.first(); 701 state = state == ONLYSECONDHAVEDATA ? FIRSTISCURRENT 702 : state == ONLYFIRSTHAVEDATA ? SECONDISCURRENT : state; 703 } 704 else { 705 state = BEFOREFIRST; 706 return false; 707 } 708 return true; 709 } 710 711 745 private boolean iterateNegativeAfterPositiveWhenOneIsCurrent(_Iterator 746 currentIterator, _Iterator otherIterator, _Reference[] currentReferences, 747 _Reference[] otherReferences) throws DException { 748 boolean currentPrevious = currentIterator.previous(); 749 boolean otherPrevious = otherIterator.previous(); 750 if (currentPrevious && otherPrevious) { 751 Object currentObject = currentIterator.getColumnValues(currentReferences); 752 Object otherObject = otherIterator.getColumnValues(otherReferences); 753 int cmp = compare(currentObject, otherObject); 754 if (cmp == 0) { 755 cmp = state; } if (cmp < 0) { 758 state = -state; 759 currentIterator.next(); 760 } 761 else { 762 otherIterator.next(); 763 } 764 } 765 else if (currentPrevious) { 766 otherIterator.first(); 767 } 768 else if (otherPrevious) { 769 currentIterator.first(); 770 state = -state; 771 } 772 else { 773 state = BEFOREFIRST; 774 return false; 775 } 776 return true; 777 } 778 779 807 private boolean iterateNegative(_Iterator firstIterator, 808 _Iterator secondIterator, int reverse, 809 _Reference[] firstReferences, 810 _Reference[] secondReferences) throws 811 DException { 812 direction = BACKWARD; 813 Object toCompare = firstIterator.getColumnValues(firstReferences); 814 int cmp = -1; 815 boolean flag = firstIterator.previous(); 817 if (!flag) { 818 state = reverse == 1 ? ONLYSECONDHAVEDATA : ONLYFIRSTHAVEDATA; 819 return true; 820 } 821 Object first = firstIterator.getColumnValues(firstReferences); 822 Object second = secondIterator.getColumnValues(secondReferences); 823 824 825 state = reverse == 1 ? compare(first, second) <= 0 ? SECONDISCURRENT : 826 FIRSTISCURRENT 827 : compare(second, first) <= 0 ? SECONDISCURRENT : FIRSTISCURRENT; 828 return true; 829 } 830 831 839 public Object getKey() throws DException { 840 switch (state) { 841 case INVALIDSTATE: 842 case BEFOREFIRST: 843 case AFTERLAST: 844 throw new DException("DSE4116", null); 845 case ONLYFIRSTHAVEDATA: 846 return new Object [] { 847 new SetOperatorKey(new Object [] {leftIterator.getKey(), null} 848 , state, direction)}; 849 case ONLYSECONDHAVEDATA: 850 return new Object [] { 851 new SetOperatorKey(new Object [] {null, rightIterator.getKey()} 852 , state, direction)}; 853 case FIRSTISCURRENT: 854 case SECONDISCURRENT: 855 case BOTHHAVESAMEDATA: 856 return new Object [] { 857 new SetOperatorKey(new Object [] {leftIterator.getKey(), 858 rightIterator.getKey()} 859 , state, direction)}; 860 } 861 throw new DException("DSE0", new Object [] {"INVALID STATE : " + state}); 862 } 863 864 875 public void move(Object keys) throws DException { 876 SetOperatorKey setKey = (SetOperatorKey) ( (Object []) keys)[0]; 877 state = setKey.getState(); 878 direction = setKey.getDirection(); 879 Object [] underlyingKeys = setKey.getKeys(); 880 Object leftKeys = underlyingKeys[0]; 881 Object rightKeys = underlyingKeys[1]; 882 if (leftKeys == null) { 883 moveWhenKeyIsNull(leftIterator, direction); 884 } 885 else { 886 leftIterator.move(leftKeys); 887 } 888 if (rightKeys == null) { 889 moveWhenKeyIsNull(rightIterator, direction); 890 } 891 else { 892 rightIterator.move(rightKeys); 893 } 894 } 895 896 897 906 private void moveWhenKeyIsNull(_Iterator iterator, int direction) throws 907 DException { 908 if (direction == FORWARD) { 909 if (iterator.last()) { 910 iterator.next(); 911 } 912 } 913 else if (direction == BACKWARD) { 914 if (iterator.first()) { 915 iterator.previous(); 916 917 } 918 } 919 } 920 921 929 938 public Object getColumnValues(_Reference references) throws DException { 939 int index = -9; 940 Object result = null; 941 try { 942 index = GeneralPurposeStaticClass.getSelectedColumnIndex(references, 943 leftColumnReferences); 944 if (state <= 0) { 945 return result = leftConversion != null ? 946 convertToAppDataTypes(leftIterator.getColumnValues(references), 947 index, leftConversion) : 948 leftIterator.getColumnValues(references); 949 } 950 if (index == -1) { return result = rightConversion != null ? 952 convertToAppDataTypes(rightIterator.getColumnValues(references), 953 index, rightConversion) : 954 rightIterator.getColumnValues(references); 955 } 956 957 return result = rightConversion != null ? 958 convertToAppDataTypes( 959 rightIterator.getColumnValues(rightColumnReferences[index]), index, 960 rightConversion) : 961 rightIterator.getColumnValues(rightColumnReferences[index]); 962 } 963 finally { 964 965 } 966 967 } 968 969 977 public Object getColumnValues() throws DException { 978 if (state <= 0) { 979 return leftConversion != null ? 980 convertToAppDataTypes( (Object []) 981 leftIterator.getColumnValues(leftColumnReferences), 982 leftConversion) : 983 leftIterator.getColumnValues(leftColumnReferences); 984 } 985 return rightConversion != null ? 986 convertToAppDataTypes( (Object []) 987 rightIterator.getColumnValues(rightColumnReferences), 988 rightConversion) : 989 rightIterator.getColumnValues(rightColumnReferences); 990 } 991 992 1001 public Object getColumnValues(_Reference[] references) throws DException { 1002 1003 Object result = null; 1004 int indexes[] = GeneralPurposeStaticClass.getSelectedIndexes(references, 1005 leftColumnReferences); 1006 if (state <= 0) { 1007 return result = leftConversion != null ? 1008 convertToAppDataTypes( (Object []) 1009 leftIterator.getColumnValues(references), 1010 indexes, leftConversion) : 1011 leftIterator.getColumnValues(references); 1012 } 1013 _Reference[] rightReferences = GeneralPurposeStaticClass. 1014 getReferencesToIndex(indexes, rightColumnReferences); 1015 result = rightConversion != null ? 1016 convertToAppDataTypes( (Object []) 1017 rightIterator.getColumnValues(rightReferences), 1018 indexes, rightConversion) : 1019 rightIterator.getColumnValues(rightReferences); 1020 return result; 1021 } 1022 1023 1031 public FieldBase field(_Reference references) throws com.daffodilwoods. 1032 database.resource.DException { 1033 int index = GeneralPurposeStaticClass.getSelectedColumnIndex(references, 1034 leftColumnReferences); 1035 if (state <= 0) { 1036 return leftConversion != null ? 1037 (FieldBase) convertToAppDataTypes(leftIterator.field(references), 1038 index, leftConversion) : 1039 leftIterator.field(references); 1040 } 1041 if (index == -1) { 1042 return rightConversion != null ? 1043 (FieldBase) convertToAppDataTypes(rightIterator.field(references), 1044 index, rightConversion) : 1045 rightIterator.field(references); 1046 } 1047 return rightConversion != null ? 1048 (FieldBase) convertToAppDataTypes( 1049 rightIterator.field(rightColumnReferences[index]), index, 1050 rightConversion) : rightIterator.field(rightColumnReferences[index]); 1051 1052 } 1053 1054 1062 public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods. 1063 database.resource.DException { 1064 if (state <= 0) { 1065 return leftIterator.fields(references); 1066 } 1067 int indexes[] = GeneralPurposeStaticClass.getSelectedIndexes(references, 1068 leftColumnReferences); 1069 _Reference[] rightReferences = GeneralPurposeStaticClass. 1070 getReferencesToIndex(indexes, rightColumnReferences); 1071 return rightIterator.fields(rightReferences); 1072 } 1073 1074 1083 public Object convertToAppDataTypes(Object [] source, boolean[] conversion) throws 1084 DException { 1085 int length = source.length; 1086 Object [] result = new Object [length]; 1087 for (int i = 0; i < result.length; i++) { 1088 result[i] = convertToAppDataTypes(source[i], i, conversion); 1089 } 1090 return result; 1091 } 1092 1093 public Object convertToAppDataTypes(Object [] source, int[] indexes, 1094 boolean[] conversion) throws DException { 1095 int length = source.length; 1096 Object [] result = new Object [length]; 1097 for (int i = 0; i < result.length; i++) { 1098 try { 1099 result[i] = convertToAppDataTypes(source[i], indexes[i], conversion); 1100 } 1101 catch (ArrayIndexOutOfBoundsException ex) { 1102 throw ex; 1103 } 1104 } 1105 return result; 1106 } 1107 1108 1109 public Object convertToAppDataTypes(Object source, int index, 1110 boolean[] conversion) throws DException { 1111 Object obj = index != -1 && conversion[index] ? 1112 GeneralPurposeStaticClass. 1113 convertToAppropriateType( (FieldBase) source, 1114 appropriateDataTypes[index], 1115 appropriateSizes[index], null) 1116 : source; 1117 return obj; 1118 } 1119 1120 1121 1132 protected int compare(Object object1, Object object2) throws DException { 1133 try { 1134 int cmp = comparator.compare(object1, object2); 1135 return cmp; 1136 } 1137 catch (ArrayIndexOutOfBoundsException ex) { 1138 throw ex; 1139 } 1140 } 1141 1142 1148 public _Iterator getBaseIterator(ColumnDetails column) throws com. 1149 daffodilwoods.database.resource.DException { 1150 return this; 1151 } 1152 1153 1158 public _ExecutionPlan getExecutionPlan() throws DException { 1159 _ExecutionPlan cplans[] = new _ExecutionPlan[2]; 1160 cplans[0] = leftIterator.getExecutionPlan(); 1161 cplans[1] = rightIterator.getExecutionPlan(); 1162 return new ExecutionPlan("UnionAllOrderedIterator", cplans, null, null, null); 1163 } 1164 1165 1170 public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException { 1171 ExecutionPlanForBrowser cplans[] = new ExecutionPlanForBrowser[2]; 1172 cplans[0] = leftIterator.getExecutionPlanForBrowser(); 1173 cplans[1] = rightIterator.getExecutionPlanForBrowser(); 1174 return new ExecutionPlanForBrowser("Union All Ordered", 1175 "Union All Ordered Iterator", cplans, null, null, null); 1176 } 1177 1178 1182 1188 public TableDetails[] getTableDetails() throws com.daffodilwoods.database. 1189 resource.DException { 1190 rightIterator.getTableDetails(); 1191 TableDetails[] array = leftIterator.getTableDetails(); 1192 return array; 1193 } 1194 1195 1200 public _KeyColumnInformation[] getKeyColumnInformations() throws DException { 1201 return leftIterator.getKeyColumnInformations(); 1202 } 1203 1204 public Object [] getUniqueColumnReference() throws DException { 1205 return leftIterator.getUniqueColumnReference(); 1206 } 1207 1208 public boolean seek(Object indexKey) throws DException { 1209 return GeneralPurposeStaticClass.seek(indexKey, leftIterator, rightIterator); 1210 } 1211 1212 public _OrderCount getOrderCounts() throws com.daffodilwoods.database. 1213 resource.DException { 1214 rightIterator.getOrderCounts(); return (orderCount = leftIterator.getOrderCounts()); 1216 } 1217 1218 public void setOriginalColumnDetails(ColumnDetails[] leftOriginal0, 1219 ColumnDetails[] rightOriginal0) throws 1220 DException { 1221 setTableDetailsIfNotMatched(leftOriginal0, rightOriginal0); leftConversion = getConversionArray(leftOriginal0); 1223 rightConversion = getConversionArray(rightOriginal0); 1224 } 1225 1226 private boolean[] getConversionArray(ColumnDetails[] cd) throws DException { 1227 int length = cd.length; 1228 boolean[] result = new boolean[length]; 1229 boolean noNeedOfConversion = true; 1230 for (int i = 0; i < length; i++) { 1231 result[i] = cd[i].getDatatype() != appropriateDataTypes[i] || 1232 cd[i].getSize() != appropriateSizes[i]; 1233 if (result[i]) { 1234 noNeedOfConversion = false; 1235 } 1236 } 1237 return noNeedOfConversion ? null : result; 1238 } 1239 1240 public byte[] getByteKey() throws DException { 1241 switch (state) { 1242 case INVALIDSTATE: 1243 case BEFOREFIRST: 1244 case AFTERLAST: 1245 throw new DException("DSE4116", null); 1246 case ONLYFIRSTHAVEDATA: 1247 return getDataWhenOnlyHaveData(true, leftIterator); 1248 case ONLYSECONDHAVEDATA: 1249 return getDataWhenOnlyHaveData(false, rightIterator); 1250 case FIRSTISCURRENT: 1251 case SECONDISCURRENT: 1252 case BOTHHAVESAMEDATA: 1253 return getDataWhenBothHaveData(leftIterator, rightIterator); 1254 } 1255 throw new DException("DSE0", new Object [] {"INVALID STATE : " + state}); 1256 } 1257 1258 public void moveByteKey(byte[] key) throws DException { 1259 state = key[0]; 1260 direction = key[1]; 1261 byte[] leftKeys = new byte[CCzufDpowfsufs.getShortValue(key, 2)]; 1262 System.arraycopy(key, 4, leftKeys, 0, leftKeys.length); 1263 byte[] rightKeys = new byte[CCzufDpowfsufs.getShortValue(key, 1264 leftKeys.length + 4)]; 1265 System.arraycopy(key, leftKeys.length + 6, rightKeys, 0, rightKeys.length); 1266 if (leftKeys.length == 0) 1267 moveWhenKeyIsNull(leftIterator, direction); 1268 else 1269 leftIterator.moveByteKey(leftKeys); 1270 if (rightKeys.length == 0) 1271 moveWhenKeyIsNull(rightIterator, direction); 1272 else 1273 rightIterator.moveByteKey(rightKeys); 1274 } 1275 1276 private byte[] getDataWhenBothHaveData(_Iterator leftIterator, 1277 _Iterator rightIterator) throws 1278 DException { 1279 byte[] leftKeys = leftIterator.getByteKey(); 1280 byte[] rightKeys = rightIterator.getByteKey(); 1281 byte[] resultantKeys = new byte[leftKeys.length + rightKeys.length + 2 + 4]; resultantKeys[0] = (byte) state; 1283 resultantKeys[1] = (byte) direction; 1284 short leftLen = (short) leftKeys.length; 1285 short rightLen = (short) rightKeys.length; 1286 System.arraycopy(CCzufDpowfsufs.getBytes(leftLen), 0, resultantKeys, 2, 2); 1287 System.arraycopy(leftKeys, 0, resultantKeys, 4, leftKeys.length); 1288 System.arraycopy(CCzufDpowfsufs.getBytes(rightLen), 0, resultantKeys, 1289 4 + leftLen, 2); 1290 System.arraycopy(rightKeys, 0, resultantKeys, leftKeys.length + 6, 1291 rightKeys.length); 1292 return resultantKeys; 1293 } 1294 1295 public byte[] getDataWhenOnlyHaveData(boolean flag, _Iterator iterator) throws 1296 DException { 1297 byte[] keys = iterator.getByteKey(); 1298 byte[] resultantKeys = new byte[keys.length + 2 + 2 + 2]; resultantKeys[0] = (byte) state; 1300 resultantKeys[1] = (byte) direction; 1301 if (flag) { 1302 System.arraycopy(CCzufDpowfsufs.getBytes( (short) keys.length), 0, 1303 resultantKeys, 2, 2); 1304 System.arraycopy(keys, 0, resultantKeys, 4, keys.length); 1305 System.arraycopy(CCzufDpowfsufs.getBytes( (short) 0), 0, resultantKeys, 1306 keys.length + 4, 2); 1307 } 1308 else { 1309 System.arraycopy(CCzufDpowfsufs.getBytes( (short) 0), 0, resultantKeys, 2, 1310 2); 1311 System.arraycopy(CCzufDpowfsufs.getBytes( (short) keys.length), 0, 1312 resultantKeys, 4, 2); 1313 System.arraycopy(keys, 0, resultantKeys, 6, keys.length); 1314 } 1315 return resultantKeys; 1316 } 1317 1318 public void setSpecificUnderlyingReferences(_Reference[] 1319 specificUnderlyingReferences) throws 1320 DException { 1321 throw new java.lang.UnsupportedOperationException ( 1322 "Method setSpecificUnderlyingReferences(_Reference[]) not yet implemented."); 1323 } 1324 1325 public String toString() { 1326 return "UnionAllOrderedIterator[" + leftIterator + "]\n\n[" + rightIterator + 1327 "]"; 1328 } 1329 1330 1367 1368 1369 public void setTableDetailsIfNotMatched(ColumnDetails[] leftOriginal, 1370 ColumnDetails[] rightOriginal) throws 1371 DException { 1372 for (int i = 0; i < leftOriginal.length; i++) { 1373 if ( ( (ColumnDetails) leftColumnReferences[i]).getTable() != 1374 leftOriginal[i].getTable()) { 1375 ( (ColumnDetails) leftColumnReferences[i]).setTableDetails(leftOriginal[ 1376 i].getTable()); 1377 } 1378 } 1379 for (int i = 0; i < orderLeftCD.length; i++) { 1380 for (int j = 0; j < leftOriginal.length; j++) { 1381 if (orderLeftCD[i] == leftOriginal[j]) { 1382 if ( ( (ColumnDetails) orderLeftCD[i]).getTable() != 1383 leftOriginal[j].getTable()) { 1384 ( (ColumnDetails) orderLeftCD[i]).setTableDetails(leftOriginal[j]. 1385 getTable()); 1386 } 1387 break; 1388 } 1389 } 1390 } 1391 for (int i = 0; i < rightOriginal.length; i++) { 1392 if ( ( (ColumnDetails) rightColumnReferences[i]).getTable() != 1393 rightOriginal[i].getTable()) { 1394 ( (ColumnDetails) rightColumnReferences[i]).setTableDetails( 1395 rightOriginal[i].getTable()); 1396 } 1397 } 1398 1399 for (int i = 0; i < orderRightCD.length; i++) { 1400 for (int j = 0; j < rightOriginal.length; j++) { 1401 if (orderRightCD[i] == rightOriginal[j]) { 1402 if ( ( (ColumnDetails) orderRightCD[i]).getTable() != 1403 rightOriginal[j].getTable()) { 1404 ( (ColumnDetails) orderRightCD[i]).setTableDetails(rightOriginal[j]. 1405 getTable()); 1406 } 1407 break; 1408 } 1409 } 1410 } 1411 } 1412} 1413 1414 | Popular Tags |