1 21 22 package org.apache.derbyTesting.unitTests.store; 23 24 import org.apache.derbyTesting.unitTests.harness.T_Generic; 26 import org.apache.derbyTesting.unitTests.harness.T_Fail; 27 28 import org.apache.derby.iapi.store.access.*; 29 30 import org.apache.derby.iapi.services.context.ContextService; 31 32 import org.apache.derby.iapi.services.monitor.Monitor; 33 import org.apache.derby.iapi.services.io.Storable; 34 35 import org.apache.derby.iapi.error.StandardException; 36 37 import org.apache.derby.iapi.types.DataValueDescriptor; 38 39 import org.apache.derby.iapi.reference.Property; 40 41 import org.apache.derby.iapi.services.i18n.MessageService; 42 43 import org.apache.derby.iapi.reference.SQLState; 44 45 import org.apache.derby.iapi.types.SQLInteger; 46 47 import java.security.AccessController ; 48 import java.security.PrivilegedAction ; 49 import java.util.Properties ; 50 import java.util.Vector ; 51 import java.util.StringTokenizer ; 52 import java.io.File ; 53 54 59 60 public class T_SortController extends T_Generic 61 { 62 private static final String testService = "sortTest"; 63 64 66 protected boolean verbose = false; 67 68 public String getModuleToTestProtocolName() { 69 return AccessFactory.MODULE; 70 } 71 72 private void setSortBufferSize(final String buf_length) { 73 AccessController.doPrivileged(new PrivilegedAction () { 74 public Object run() { 75 System.setProperty("derby.storage.sortBufferMax", buf_length); 76 return null; 77 } 78 }); 79 } 80 81 84 85 88 protected void runTests() throws T_Fail 89 { 90 int failcount = 0; 91 92 94 if (startParams == null) { 96 startParams = new Properties (); 97 } 98 startParams.put(Property.NO_AUTO_BOOT, Boolean.TRUE.toString()); 99 startParams.put(Property.DELETE_ON_CREATE, Boolean.TRUE.toString()); 101 102 startParams = T_Util.setEncryptionParam(startParams); 104 105 try { 106 REPORT("(unitTestMain) Testing " + "sortTest with default sort buffer size 1024"); 107 AccessFactory store1024 = null; 108 failcount = runEachTest(store1024, "1024"); 109 110 setSortBufferSize("4"); 111 REPORT("(unitTestMain) Testing " + "sortTest with minimum sort buffer size 4"); 112 AccessFactory store4 = null; 113 failcount += runEachTest(store4, "4"); 114 } 115 catch (StandardException e) 116 { 117 String msg = e.getMessage(); 118 if (msg == null) 119 msg = e.getClass().getName(); 120 REPORT("(unitTestMain) unexpected exception: " + msg); 121 throw T_Fail.exceptionFail(e); 122 } 123 124 if (failcount != 0) 125 throw T_Fail.testFailMsg("(unitTestMain)" + failcount + " cases failed."); 126 127 REPORT("(unitTestMain) succeeded"); 128 } 129 130 protected int runEachTest(AccessFactory store, String tail) throws T_Fail, StandardException { 131 132 TransactionController tc = null; 133 int failcount = 0; 134 135 try { 136 store = (AccessFactory) Monitor.createPersistentService(getModuleToTestProtocolName(), 137 testService + tail, startParams); 138 } catch (StandardException mse) { 139 throw T_Fail.exceptionFail(mse); 140 } 141 if (store == null) { 142 throw T_Fail.testFailMsg(getModuleToTestProtocolName() + " service not started."); 143 } 144 145 tc = store.getTransaction( 146 ContextService.getFactory().getCurrentContextManager()); 147 148 if (!sortExample(tc)) 149 failcount++; 150 if (!sortBufferCoverage(tc)) 151 failcount++; 152 if (!sortBoundaries(tc)) 153 failcount++; 154 if (!sortAllDuplicates(tc)) 155 failcount++; 156 if (!sortDescending(tc)) 157 failcount++; 158 159 tc.commit(); 160 tc.destroy(); 161 162 return failcount; 163 } 164 165 169 boolean sortExample(TransactionController tc) 170 throws StandardException 171 { 172 REPORT("(sortExample)"); 173 174 T_AccessRow row[] = new T_AccessRow[4]; 176 row[0] = new T_AccessRow(18, 1, 2); 177 row[1] = new T_AccessRow( 6, 1, 18); 178 row[2] = new T_AccessRow(18, 1, 2); 179 row[3] = new T_AccessRow( 8, 14, 3); 180 181 Properties implParameters = null; 187 188 T_AccessRow template = row[0]; 194 195 ColumnOrdering order[] = new ColumnOrdering[2]; 199 order[0] = new T_ColumnOrderingImpl(1, true); order[1] = new T_ColumnOrderingImpl(2, true); 202 boolean alreadyInOrder = false; 204 205 long estimatedRows = 10; 211 212 int estimatedRowSize = 12; 218 219 long sortid = tc.createSort(implParameters, template.getRowArray(), 221 order, new T_DuplicateEliminator(template), alreadyInOrder, estimatedRows, 222 estimatedRowSize); 223 224 T_AccessRow expectedRow[] = new T_AccessRow[3]; 227 expectedRow[0] = new T_AccessRow(18, 1, 2); 228 expectedRow[1] = new T_AccessRow( 6, 1, 18); 229 expectedRow[2] = new T_AccessRow( 8, 14, 3); 230 231 return testSort(tc, row, expectedRow, sortid); 232 } 233 234 240 boolean sortBufferCoverage(TransactionController tc) 241 throws StandardException 242 { 243 REPORT("(sortBufferCoverage)"); 244 245 T_AccessRow row[] = new T_AccessRow[16]; 251 row[0] = new T_AccessRow(2, 0, 0); row[1] = new T_AccessRow(2, 0, 0); 253 254 row[2] = new T_AccessRow(4, 0, 0); row[3] = new T_AccessRow(4, 0, 0); 256 257 row[4] = new T_AccessRow(1, 0, 0); row[5] = new T_AccessRow(1, 0, 0); 259 260 row[6] = new T_AccessRow(7, 0, 0); row[7] = new T_AccessRow(7, 0, 0); 262 263 row[8] = new T_AccessRow(8, 0, 0); row[9] = new T_AccessRow(8, 0, 0); 266 267 row[10] = new T_AccessRow(3, 0, 0); row[11] = new T_AccessRow(3, 0, 0); 270 271 row[12] = new T_AccessRow(5, 0, 0); row[13] = new T_AccessRow(5, 0, 0); 273 274 row[14] = new T_AccessRow(6, 0, 0); row[15] = new T_AccessRow(6, 0, 0); 276 277 Properties implParameters = null; 279 280 T_AccessRow template = row[0]; 281 282 ColumnOrdering order[] = new ColumnOrdering[1]; 284 order[0] = new T_ColumnOrderingImpl(0, true); 286 boolean alreadyInOrder = false; 288 289 long estimatedRows = 20; 290 int estimatedRowSize = 12; 291 292 long sortid = tc.createSort(implParameters, template.getRowArray(), 294 order, new T_DummySortObserver(template), alreadyInOrder, estimatedRows, 295 estimatedRowSize); 296 297 T_AccessRow expectedRow[] = new T_AccessRow[16]; 299 expectedRow[0] = new T_AccessRow(1, 0, 0); 300 expectedRow[1] = new T_AccessRow(1, 0, 0); 301 expectedRow[2] = new T_AccessRow(2, 0, 0); 302 expectedRow[3] = new T_AccessRow(2, 0, 0); 303 expectedRow[4] = new T_AccessRow(3, 0, 0); 304 expectedRow[5] = new T_AccessRow(3, 0, 0); 305 expectedRow[6] = new T_AccessRow(4, 0, 0); 306 expectedRow[7] = new T_AccessRow(4, 0, 0); 307 expectedRow[8] = new T_AccessRow(5, 0, 0); 308 expectedRow[9] = new T_AccessRow(5, 0, 0); 309 expectedRow[10] = new T_AccessRow(6, 0, 0); 310 expectedRow[11] = new T_AccessRow(6, 0, 0); 311 expectedRow[12] = new T_AccessRow(7, 0, 0); 312 expectedRow[13] = new T_AccessRow(7, 0, 0); 313 expectedRow[14] = new T_AccessRow(8, 0, 0); 314 expectedRow[15] = new T_AccessRow(8, 0, 0); 315 316 return testSort(tc, row, expectedRow, sortid); 317 } 318 319 320 323 boolean sortBoundaries(TransactionController tc) 324 throws StandardException 325 { 326 int failcount = 0; 327 long sortid; 328 Properties implParameters; 329 T_AccessRow template; 330 ColumnOrdering order[]; 331 boolean alreadyInOrder; 332 long estimatedRows; 333 int estimatedRowSize; 334 T_AccessRow input[]; 335 T_AccessRow expected[]; 336 337 341 342 implParameters = null; 343 template = new T_AccessRow(1, 1, 1); 344 order = new ColumnOrdering[1]; 345 order[0] = new T_ColumnOrderingImpl(0, true); estimatedRows = 10; 347 estimatedRowSize = 12; 348 349 352 353 REPORT("(sortBoundaries) Sorting no rows"); 354 355 input = new T_AccessRow[0]; expected = new T_AccessRow[0]; alreadyInOrder = false; 358 359 sortid = tc.createSort(implParameters, template.getRowArray(), 360 order, new T_DummySortObserver(template), alreadyInOrder, estimatedRows, 361 estimatedRowSize); 362 363 if (!testSort(tc, input, expected, sortid)) 364 failcount++; 365 366 369 370 REPORT("(sortBoundaries) Sorting no rows - \"already in order\""); 371 372 input = new T_AccessRow[0]; expected = new T_AccessRow[0]; alreadyInOrder = true; 375 376 sortid = tc.createSort(implParameters, template.getRowArray(), 377 order, new T_DummySortObserver(template), alreadyInOrder, estimatedRows, 378 estimatedRowSize); 379 380 if (!testSort(tc, input, expected, sortid)) 381 failcount++; 382 383 386 387 REPORT("(sortBoundaries) Sorting a single row"); 388 389 input = new T_AccessRow[1]; 390 input[0] = new T_AccessRow(99, 88, 77); 391 expected = new T_AccessRow[1]; 392 expected[0] = new T_AccessRow(99, 88, 77); 393 alreadyInOrder = false; 394 395 sortid = tc.createSort(implParameters, template.getRowArray(), 396 order, new T_DummySortObserver(template), alreadyInOrder, estimatedRows, 397 estimatedRowSize); 398 399 if (!testSort(tc, input, expected, sortid)) 400 failcount++; 401 402 405 406 REPORT("(sortBoundaries) Sorting a single row - \"already in order\""); 407 408 input = new T_AccessRow[1]; 409 input[0] = new T_AccessRow(99, 88, 77); 410 expected = new T_AccessRow[1]; 411 expected[0] = new T_AccessRow(99, 88, 77); 412 alreadyInOrder = true; 413 414 sortid = tc.createSort(implParameters, template.getRowArray(), 415 order, new T_DummySortObserver(template), alreadyInOrder, estimatedRows, 416 estimatedRowSize); 417 418 if (!testSort(tc, input, expected, sortid)) 419 failcount++; 420 421 424 425 REPORT("(sortBoundaries) Sorting a single row - \"eliminate duplicates\""); 426 427 input = new T_AccessRow[1]; 428 input[0] = new T_AccessRow(99, 88, 77); 429 expected = new T_AccessRow[1]; 430 expected[0] = new T_AccessRow(99, 88, 77); 431 alreadyInOrder = false; 432 433 sortid = tc.createSort(implParameters, template.getRowArray(), 434 order, new T_DuplicateEliminator(template), alreadyInOrder, estimatedRows, 435 estimatedRowSize); 436 437 if (!testSort(tc, input, expected, sortid)) 438 failcount++; 439 440 return failcount == 0; 441 } 442 443 446 boolean sortAllDuplicates(TransactionController tc) 447 throws StandardException 448 { 449 int failcount = 0; 450 long sortid; 451 Properties implParameters; 452 T_AccessRow template; 453 ColumnOrdering order[]; 454 boolean alreadyInOrder; 455 long estimatedRows; 456 int estimatedRowSize; 457 T_AccessRow input[]; 458 T_AccessRow expected[]; 459 460 464 465 implParameters = null; 466 template = new T_AccessRow(1, 1, 1); 467 468 order = new ColumnOrdering[2]; 470 order[0] = new T_ColumnOrderingImpl(0, true); order[1] = new T_ColumnOrderingImpl(1, true); 473 alreadyInOrder = false; 474 estimatedRows = 10; 475 estimatedRowSize = 12; 476 477 input = new T_AccessRow[5]; 478 input[0] = new T_AccessRow(1, 1, 1); 479 input[1] = new T_AccessRow(1, 1, 1); 480 input[2] = new T_AccessRow(1, 1, 1); 481 input[3] = new T_AccessRow(1, 1, 1); 482 input[4] = new T_AccessRow(1, 1, 1); 483 484 488 489 REPORT("(sortAllDuplicates) no aggregation"); 490 491 expected = new T_AccessRow[5]; 492 expected[0] = new T_AccessRow(1, 1, 1); 493 expected[1] = new T_AccessRow(1, 1, 1); 494 expected[2] = new T_AccessRow(1, 1, 1); 495 expected[3] = new T_AccessRow(1, 1, 1); 496 expected[4] = new T_AccessRow(1, 1, 1); 497 498 sortid = tc.createSort(implParameters, template.getRowArray(), 499 order, new T_DummySortObserver(template), alreadyInOrder, estimatedRows, 500 estimatedRowSize); 501 502 if (!testSort(tc, input, expected, sortid)) 503 failcount++; 504 505 509 510 REPORT("(sortAllDuplicates) eliminate duplicates"); 511 512 expected = new T_AccessRow[1]; 513 expected[0] = new T_AccessRow(1, 1, 1); 514 515 sortid = tc.createSort(implParameters, template.getRowArray(), 516 order, new T_DuplicateEliminator(template), alreadyInOrder, estimatedRows, 517 estimatedRowSize); 518 519 if (!testSort(tc, input, expected, sortid)) 520 failcount++; 521 522 526 527 REPORT("(sortAllDuplicates) sum aggregate"); 528 529 expected = new T_AccessRow[1]; 530 expected[0] = new T_AccessRow(1, 1, 5); 531 532 sortid = tc.createSort(implParameters, template.getRowArray(), 533 order, new T_SumForIntCol(2), alreadyInOrder, estimatedRows, 534 estimatedRowSize); 535 536 if (!testSort(tc, input, expected, sortid)) 537 failcount++; 538 539 return failcount == 0; 540 } 541 542 545 boolean sortDescending(TransactionController tc) 546 throws StandardException 547 { 548 int failcount = 0; 549 long sortid; 550 Properties implParameters; 551 T_AccessRow template; 552 ColumnOrdering order[]; 553 boolean alreadyInOrder; 554 long estimatedRows; 555 int estimatedRowSize; 556 T_AccessRow expected[]; 557 558 562 563 implParameters = null; 564 template = new T_AccessRow(1, 1, 1); 565 566 alreadyInOrder = false; 567 estimatedRows = 10; 568 estimatedRowSize = 12; 569 570 573 574 REPORT("(sortDescending) no aggregation"); 575 576 order = new ColumnOrdering[2]; 577 order[0] = new T_ColumnOrderingImpl(0, false); order[1] = new T_ColumnOrderingImpl(1, false); 580 expected = new T_AccessRow[10]; 581 expected[0] = new T_AccessRow(8, 1, 1); 582 expected[1] = new T_AccessRow(4, 8, 1); 583 expected[2] = new T_AccessRow(4, 2, 1); 584 expected[3] = new T_AccessRow(4, 1, 1); 585 expected[4] = new T_AccessRow(3, 8, 1); 586 expected[5] = new T_AccessRow(3, 5, 1); 587 expected[6] = new T_AccessRow(3, 3, 1); 588 expected[7] = new T_AccessRow(3, 3, 1); 589 expected[8] = new T_AccessRow(3, 3, 1); 590 expected[9] = new T_AccessRow(1, 1, 1); 591 592 sortid = tc.createSort(implParameters, template.getRowArray(), 593 order, new T_DummySortObserver(template), alreadyInOrder, estimatedRows, 594 estimatedRowSize); 595 596 if (!testSort(tc, getSortDescendingInput(), expected, sortid)) 597 failcount++; 598 599 602 603 REPORT("(sortDescending) eliminate duplicates"); 604 605 order = new ColumnOrdering[2]; 606 order[0] = new T_ColumnOrderingImpl(0, false); order[1] = new T_ColumnOrderingImpl(1, false); 609 expected = new T_AccessRow[8]; 610 expected[0] = new T_AccessRow(8, 1, 1); 611 expected[1] = new T_AccessRow(4, 8, 1); 612 expected[2] = new T_AccessRow(4, 2, 1); 613 expected[3] = new T_AccessRow(4, 1, 1); 614 expected[4] = new T_AccessRow(3, 8, 1); 615 expected[5] = new T_AccessRow(3, 5, 1); 616 expected[6] = new T_AccessRow(3, 3, 1); 617 expected[7] = new T_AccessRow(1, 1, 1); 618 619 sortid = tc.createSort(implParameters, template.getRowArray(), 620 order, new T_DuplicateEliminator(template), alreadyInOrder, estimatedRows, 621 estimatedRowSize); 622 623 if (!testSort(tc, getSortDescendingInput(), expected, sortid)) 624 failcount++; 625 626 629 630 REPORT("(sortDescending) descending/ascending - eliminate duplicates"); 631 632 order = new ColumnOrdering[2]; 633 order[0] = new T_ColumnOrderingImpl(0, false); order[1] = new T_ColumnOrderingImpl(1, true); 636 expected = new T_AccessRow[8]; 637 expected[0] = new T_AccessRow(8, 1, 1); 638 expected[1] = new T_AccessRow(4, 1, 1); 639 expected[2] = new T_AccessRow(4, 2, 1); 640 expected[3] = new T_AccessRow(4, 8, 1); 641 expected[4] = new T_AccessRow(3, 3, 1); 642 expected[5] = new T_AccessRow(3, 5, 1); 643 expected[6] = new T_AccessRow(3, 8, 1); 644 expected[7] = new T_AccessRow(1, 1, 1); 645 646 sortid = tc.createSort(implParameters, template.getRowArray(), 647 order, new T_DuplicateEliminator(template), alreadyInOrder, estimatedRows, 648 estimatedRowSize); 649 650 if (!testSort(tc, getSortDescendingInput(), expected, sortid)) 651 failcount++; 652 653 654 return failcount == 0; 655 } 656 657 private T_AccessRow[] getSortDescendingInput() 658 { 659 T_AccessRow[] input; 660 661 input = new T_AccessRow[10]; 662 input[0] = new T_AccessRow(8, 1, 1); 663 input[1] = new T_AccessRow(1, 1, 1); 664 input[2] = new T_AccessRow(3, 5, 1); 665 input[3] = new T_AccessRow(4, 1, 1); 666 input[4] = new T_AccessRow(3, 3, 1); 667 input[5] = new T_AccessRow(3, 8, 1); 668 input[6] = new T_AccessRow(3, 3, 1); 669 input[7] = new T_AccessRow(3, 3, 1); 670 input[8] = new T_AccessRow(4, 2, 1); 671 input[9] = new T_AccessRow(4, 8, 1); 672 673 return input; 674 } 675 676 677 681 boolean testSort(TransactionController tc, T_AccessRow in[], T_AccessRow outrow[], long sortid) 682 throws StandardException 683 { 684 SortController sort = tc.openSort(sortid); 686 687 for (int i = 0; i < in.length; i++) 689 { 690 if (verbose) 691 REPORT("(testSort) in: " + in[i]); 692 sort.insert(in[i].getRowArray()); 693 } 694 695 sort.close(); 699 700 SortInfo sort_info = sort.getSortInfo(); 702 Properties sortprop = sort_info.getAllSortInfo(null); 703 704 String sortType = sortprop.getProperty( 705 MessageService.getTextMessage(SQLState.STORE_RTS_SORT_TYPE)); 706 int numRowsInput = Integer.parseInt(sortprop.getProperty( 707 MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_INPUT))); 708 int numRowsOutput = Integer.parseInt(sortprop.getProperty( 709 MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_OUTPUT))); 710 711 String external = 712 MessageService.getTextMessage(SQLState.STORE_RTS_EXTERNAL); 713 String internal = 714 MessageService.getTextMessage(SQLState.STORE_RTS_INTERNAL); 715 if (sortType.compareTo(internal) != 0 && 716 sortType.compareTo(external) != 0) 717 FAIL("(testSort) unknown sortType. Expected internal or external, got " + sortType); 718 719 if (numRowsInput != in.length) 720 FAIL("(testSort) SortInfo.numRowsInput (value: " + numRowsInput + 721 ") is not equal to in.length (value: " + in.length + ")"); 722 723 if (numRowsOutput != outrow.length) 724 FAIL("(testSort) SortInfo.numRowsOutput (value: " + 725 numRowsOutput + ") is not equal to outrow.length (value: " + outrow.length + ")"); 726 727 if (sortType.equals(external)) 728 { 729 int numMergeRuns = Integer.parseInt(sortprop.getProperty( 730 MessageService.getTextMessage(SQLState.STORE_RTS_NUM_MERGE_RUNS))); 731 Vector mergeRuns = new Vector (); 732 StringTokenizer st = new StringTokenizer (sortprop.getProperty( 733 MessageService.getTextMessage(SQLState.STORE_RTS_MERGE_RUNS_SIZE)), 734 "[],",false); 735 while (st.hasMoreTokens()) 736 mergeRuns.addElement(Integer.valueOf(st.nextToken().trim())); 737 738 if (mergeRuns.size() != numMergeRuns) 739 FAIL("(testSort) the number of elements in vector SortInfo.mergeRunsSize (value: " + 740 mergeRuns.size() + " ) is not equal to SortInfo.numMergeRuns (value: " + 741 numMergeRuns + " )"); 742 743 int totRunSize = 0; 744 for (int i = 0; i < mergeRuns.size(); i++) 745 totRunSize += ((Integer ) mergeRuns.elementAt(i)).intValue(); 746 if (totRunSize != numRowsInput) 747 FAIL("(testSort) the sum of the elements of the vector SortInfo.mergeRunsSize (value: " + 748 totRunSize + " ) is not equal to SortInfo.numRowsInput (value: " + 749 numRowsInput + " )"); 750 } 751 752 sort = null; 753 754 ScanController scan = tc.openSortScan(sortid, false); 756 757 boolean mismatch = false; 759 boolean toofew = false; 760 boolean toomany = false; 761 762 T_AccessRow result = new T_AccessRow(3); 765 for (int i = 0; i < outrow.length; i++) 766 { 767 if (scan.next() == false) 768 { 769 toofew = true; 772 FAIL("(testSort) Too few rows in sort output"); 773 break; 774 } 775 776 scan.fetch(result.getRowArray()); 777 if (verbose) 778 REPORT("(testSort) out: " + result); 779 780 if (!result.equals(outrow[i])) 781 { 782 mismatch = true; 785 FAIL("(testSort) row " + result + " != " + outrow[i]); 786 } 787 } 788 789 while (scan.next() == true) 792 { 793 scan.fetch(result.getRowArray()); 794 if (verbose) 795 REPORT("(testSort) out: " + result); 796 toomany = true; 797 FAIL("(testSort) Extra row"); 798 } 799 800 ScanInfo scan_info = scan.getScanInfo(); 802 Properties prop = scan_info.getAllScanInfo(null); 803 804 if (prop.getProperty( 805 MessageService.getTextMessage(SQLState.STORE_RTS_SCAN_TYPE) 806 ).compareTo( 807 MessageService.getTextMessage(SQLState.STORE_RTS_SORT)) != 0) 808 { 809 FAIL("(testSort) wrong scanType. Expected sort, got " + 810 prop.getProperty( 811 MessageService.getTextMessage( 812 SQLState.STORE_RTS_SCAN_TYPE))); 813 } 814 815 if (tc.countOpens(TransactionController.OPEN_CREATED_SORTS) != 1) 816 { 817 FAIL("(testSort) sort count before close is wrong: " + 818 tc.countOpens(TransactionController.OPEN_CREATED_SORTS)); 819 } 820 821 scan.close(); 823 scan = null; 824 825 if (tc.countOpens(TransactionController.OPEN_CREATED_SORTS) != 1) 826 { 827 FAIL("(testSort) sort count after close is wrong: " + 828 tc.countOpens(TransactionController.OPEN_CREATED_SORTS)); 829 } 830 831 tc.dropSort(sortid); 832 833 if (tc.countOpens(TransactionController.OPEN_CREATED_SORTS) > 0) 834 { 835 FAIL("(testSort) a sort is still open."); 836 } 837 838 return (!mismatch && !toofew && !toomany); 839 } 840 } 841 842 843 class T_DummySortObserver implements SortObserver 844 { 845 T_AccessRow template; 846 Vector vector; 847 848 T_DummySortObserver(T_AccessRow template) 849 { 850 this.template = template; 851 vector = new Vector (); 852 } 853 854 857 public DataValueDescriptor[] insertNonDuplicateKey( 858 DataValueDescriptor[] insertRow) 859 { 860 return insertRow; 861 } 862 863 public DataValueDescriptor[] insertDuplicateKey( 864 DataValueDescriptor[] insertRow, 865 DataValueDescriptor[] existingRow) 866 { 867 return insertRow; 868 } 869 870 public void addToFreeList( 871 DataValueDescriptor[] objectArray, 872 int maxFreeListSize) 873 { 874 if (vector.size() < maxFreeListSize) 875 { 876 vector.addElement(objectArray); 877 } 878 } 879 880 public DataValueDescriptor[] getArrayClone() 881 throws StandardException 882 { 883 int lastElement = vector.size(); 884 885 if (lastElement > 0) 886 { 887 DataValueDescriptor[] retval = 888 (DataValueDescriptor[]) vector.elementAt(lastElement - 1); 889 vector.removeElementAt(lastElement - 1); 890 return retval; 891 } 892 return template.getRowArrayClone(); 893 } 894 } 895 896 class T_DuplicateEliminator extends T_DummySortObserver 897 { 898 899 T_DuplicateEliminator(T_AccessRow template) 900 { 901 super(template); 902 } 903 906 public DataValueDescriptor[] insertNonDuplicateKey( 907 DataValueDescriptor[] insertRow) 908 { 909 return insertRow; 910 } 911 912 public DataValueDescriptor[] insertDuplicateKey( 913 DataValueDescriptor[] insertRow, 914 DataValueDescriptor[] existingRow) 915 { 916 return null; 917 } 918 } 919 920 class T_SumForIntCol implements SortObserver 921 { 922 private int columnId; 923 924 T_SumForIntCol(int columnId) 925 { 926 this.columnId = columnId; 927 } 928 929 932 933 public DataValueDescriptor[] insertNonDuplicateKey( 934 DataValueDescriptor[] insertRow) 935 { 936 return insertRow; 937 } 938 939 public DataValueDescriptor[] insertDuplicateKey( 940 DataValueDescriptor[] insertRow, 941 DataValueDescriptor[] existingRow) 942 throws StandardException 943 { 944 945 SQLInteger increment = (SQLInteger) insertRow[columnId]; 949 SQLInteger sum = (SQLInteger) existingRow[columnId]; 950 951 sum.plus(sum, increment, sum); 953 954 return null; 955 } 956 957 public void addToFreeList( 958 DataValueDescriptor[] objectArray, 959 int maxFreeListSize) 960 { 961 } 962 963 public DataValueDescriptor[] getArrayClone() 964 throws StandardException 965 { 966 return null; 967 } 968 } 969 970 | Popular Tags |