1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
|
/**
* Derby - org.apache.derbyTesting.functionTests.tests.jdbc4.UnsupportedVetter
*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*
*/
package org.apache.derbyTesting.functionTests.tests.jdbc4;
import java.io.*;
import java.sql.*;
import javax.sql.*;
import java.lang.reflect.*;
import java.util.*;
import junit.framework.*;
import java.net.URL;
import org.apache.derbyTesting.functionTests.util.TestUtil;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.J2EEDataSource;
import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.JDBCDataSource;
import org.apache.derbyTesting.junit.TestConfiguration;
/**
* JUnit test which checks that only expected methods throw
* SQLFeatureNotSupporteException. As currently compiled, this class
* does not object to a handful of mandatory LOB-supporting methods which Derby
* does not implement. You can expose these methods by setting
* the STRICT_ENFORCEMENT constant to true.
*
*/
public class UnsupportedVetter extends BaseJDBCTestCase
{
/////////////////////////////////////////////////////////////
//
// CONSTANTS
//
/////////////////////////////////////////////////////////////
public static final String SQL_PACKAGE_NAME = "java.sql";
private static final boolean STRICT_ENFORCEMENT = false;
/////////////////////////////////////////////////////////////
//
// STATE
//
/////////////////////////////////////////////////////////////
//
// Table of methods which are allowed to raise
// SQLFeatureNotSupportedException. Derived from the 1.6 Javadoc.
//
private static Exclusions[] rawExcludables = new Exclusions[]
{
new Exclusions
(
java.sql.Connection.class,
new MD[]
{
new MD( "createArrayOf", new Class[] { String.class, Object[].class } ),
new MD( "createNClob", new Class[] { } ),
new MD( "createSQLXML", new Class[] { } ),
new MD( "createStruct", new Class[] { String.class, Object[].class } ),
new MD( "getNetworkTimeout", new Class[] { }, JDBC.vmSupportsJDBC41() ),
new MD( "getTypeMap", new Class[] { } ),
new MD( "prepareStatement", new Class[] { String.class, int[].class } ),
new MD( "prepareStatement", new Class[] { String.class, String[].class } ),
new MD( "setNetworkTimeout", new Class[] { java.util.concurrent.Executor.class, int.class }, JDBC.vmSupportsJDBC41() ),
new MD( "setTypeMap", new Class[] { Map.class } ),
} ),
new Exclusions
(
java.sql.Statement.class,
new MD[]
{
new MD( "cancel", new Class[] { } ),
new MD( "execute", new Class[] { String.class, int[].class } ),
new MD( "execute", new Class[] { String.class, String[].class } ),
new MD( "executeUpdate", new Class[] { String.class, int[].class } ),
new MD( "executeUpdate", new Class[] { String.class, String[].class } )
} )
,
new Exclusions
(
java.sql.PreparedStatement.class,
new MD[]
{
new MD( "setArray", new Class[] { int.class, java.sql.Array.class } ),
new MD( "setNCharacterStream", new Class[] { int.class, java.io.Reader.class } ),
new MD( "setNCharacterStream", new Class[] { int.class, java.io.Reader.class, long.class } ),
new MD( "setNClob", new Class[] { int.class, NClob.class } ),
new MD( "setNClob", new Class[] { int.class, java.io.Reader.class } ),
new MD( "setNClob", new Class[] { int.class, java.io.Reader.class, long.class } ),
new MD( "setNString", new Class[] { int.class, String.class } ),
new MD( "setRef", new Class[] { int.class, Ref.class } ),
new MD( "setRowId", new Class[] { int.class, RowId.class } ),
new MD( "setSQLXML", new Class[] { int.class, SQLXML.class } ),
new MD( "setURL", new Class[] { int.class, URL.class } ),
new MD( "setNull", new Class[] { int.class, int.class, String.class } ),
new MD( "setUnicodeStream", new Class[] { int.class, InputStream.class, int.class } ),
} ),
new Exclusions
(
java.sql.CallableStatement.class,
new MD[]
{
//
// THE FOLLOWING METHODS ARE MANDATORY ACCORDING TO THE
// JDBC SPEC. HOWEVER, DERBY DOES NOT IMPLEMENT THEM IN ONE
// OR THE OTHER OF OUR CLIENTS.
//
new FD( "getBlob", new Class[] { int.class } ),
new FD( "getClob", new Class[] { int.class } ),
//
// According to the JDBC4 spec and javadoc, the following
// methods are optional and do not have to be implemented.
//
new MD( "getArray", new Class[] { int.class } ),
new MD( "getArray", new Class[] { String.class } ),
new MD( "getBigDecimal", new Class[] { String.class } ),
new MD( "getBoolean", new Class[] { String.class } ),
new MD( "getBlob", new Class[] { String.class } ),
new MD( "getBoolean", new Class[] { String.class } ),
new MD( "getByte", new Class[] { String.class } ),
new MD( "getBytes", new Class[] { String.class } ),
new MD( "getCharacterStream", new Class[] { String.class } ),
new MD( "getClob", new Class[] { String.class } ),
new MD( "getDate", new Class[] { String.class } ),
new MD( "getDate", new Class[] { String.class, Calendar.class } ),
new MD( "getDouble", new Class[] { String.class } ),
new MD( "getFloat", new Class[] { String.class } ),
new MD( "getInt", new Class[] { String.class } ),
new MD( "getLong", new Class[] { String.class } ),
new MD( "getNCharacterStream", new Class[] { int.class } ),
new MD( "getNCharacterStream", new Class[] { String.class } ),
new MD( "getNClob", new Class[] { int.class } ),
new MD( "getNClob", new Class[] { String.class } ),
new MD( "getNString", new Class[] { int.class } ),
new MD( "getNString", new Class[] { String.class } ),
new MD( "getObject", new Class[] { String.class } ),
new MD( "getObject", new Class[] { String.class, Class.class }, JDBC.vmSupportsJDBC41() ),
new MD( "getRef", new Class[] { int.class } ),
new MD( "getRef", new Class[] { String.class } ),
new MD( "getRowId", new Class[] { int.class } ),
new MD( "getRowId", new Class[] { String.class } ),
new MD( "getShort", new Class[] { String.class } ),
new MD( "getSQLXML", new Class[] { int.class } ),
new MD( "getSQLXML", new Class[] { String.class } ),
new MD( "getString", new Class[] { String.class } ),
new MD( "getTime", new Class[] { String.class } ),
new MD( "getTime", new Class[] { String.class, java.util.Calendar.class } ),
new MD( "getTimestamp", new Class[] { String.class } ),
new MD( "getTimestamp", new Class[] { String.class, java.util.Calendar.class } ),
new MD( "getURL", new Class[] { int.class } ),
new MD( "getURL", new Class[] { String.class } ),
new MD( "registerOutParameter", new Class[] { String.class, int.class } ),
new MD( "registerOutParameter", new Class[] { String.class, int.class, int.class } ),
new MD( "registerOutParameter", new Class[] { String.class, int.class, String.class } ),
new MD( "registerOutParameter", new Class[] { int.class, int.class, String.class } ),
makeMD( "registerOutParameter", new String[] { "java.lang.String", "java.sql.SQLType" }, JDBC.vmSupportsJDBC42() ),
makeMD( "registerOutParameter", new String[] { "java.lang.String", "java.sql.SQLType", "int" }, JDBC.vmSupportsJDBC42() ),
makeMD( "registerOutParameter", new String[] { "java.lang.String", "java.sql.SQLType", "java.lang.String" }, JDBC.vmSupportsJDBC42() ),
new MD( "setArray", new Class[] { int.class, java.sql.Array.class } ),
new MD( "setAsciiStream", new Class[] { String.class, java.io.InputStream.class } ),
new MD( "setAsciiStream", new Class[] { String.class, java.io.InputStream.class, int.class } ),
new MD( "setAsciiStream", new Class[] { String.class, java.io.InputStream.class, long.class } ),
new MD( "setBigDecimal", new Class[] { String.class, java.math.BigDecimal.class } ),
new MD( "setBinaryStream", new Class[] { String.class, java.io.InputStream.class } ),
new MD( "setBinaryStream", new Class[] { String.class, java.io.InputStream.class, int.class } ),
new MD( "setBinaryStream", new Class[] { String.class, java.io.InputStream.class, long.class } ),
new MD( "setBlob", new Class[] { String.class, java.io.InputStream.class } ),
new MD( "setBlob", new Class[] { String.class, java.io.InputStream.class, long.class } ),
new MD( "setBlob", new Class[] { String.class, Blob.class } ),
new MD( "setBoolean", new Class[] { String.class, boolean.class } ),
new MD( "setByte", new Class[] { String.class, byte.class } ),
new MD( "setBytes", new Class[] { String.class, byte[].class } ),
new MD( "setCharacterStream", new Class[] { String.class, java.io.Reader.class } ),
new MD( "setCharacterStream", new Class[] { String.class, java.io.Reader.class, int.class } ),
new MD( "setCharacterStream", new Class[] { String.class, java.io.Reader.class, long.class } ),
new MD( "setClob", new Class[] { String.class, java.io.Reader.class } ),
new MD( "setClob", new Class[] { String.class, java.io.Reader.class, long.class } ),
new MD( "setClob", new Class[] { String.class, Clob.class } ),
new MD( "setDate", new Class[] { String.class, java.sql.Date.class } ),
new MD( "setDate", new Class[] { String.class, java.sql.Date.class, Calendar.class } ),
new MD( "setDouble", new Class[] { String.class, double.class} ),
new MD( "setFloat", new Class[] { String.class, float.class } ),
new MD( "setInt", new Class[] { String.class, int.class } ),
new MD( "setLong", new Class[] { String.class, long.class } ),
new MD( "setNCharacterStream", new Class[] { int.class, java.io.Reader.class, long.class } ),
new MD( "setNCharacterStream", new Class[] { String.class, java.io.Reader.class } ),
new MD( "setNCharacterStream", new Class[] { String.class, java.io.Reader.class, long.class } ),
new MD( "setNClob", new Class[] { int.class, java.io.Reader.class, long.class } ),
new MD( "setNClob", new Class[] { int.class, NClob.class } ),
new MD( "setNClob", new Class[] { String.class, java.io.Reader.class } ),
new MD( "setNClob", new Class[] { String.class, java.io.Reader.class, long.class } ),
new MD( "setNClob", new Class[] { String.class, NClob.class } ),
new MD( "setNString", new Class[] { int.class, String.class } ),
new MD( "setNString", new Class[] { String.class, String.class } ),
new MD( "setNull", new Class[] { String.class, int.class } ),
new MD( "setNull", new Class[] { String.class, int.class, String.class } ),
new MD( "setObject", new Class[] { String.class, Object.class } ),
new MD( "setObject", new Class[] { String.class, Object.class, int.class } ),
new MD( "setObject", new Class[] { String.class, Object.class, int.class, int.class } ),
new MD( "setRef", new Class[] { int.class, Ref.class } ),
new MD( "setRowId", new Class[] { int.class, RowId.class } ),
new MD( "setRowId", new Class[] { String.class, RowId.class } ),
new MD( "setSQLXML", new Class[] { int.class, SQLXML.class } ),
new MD( "setSQLXML", new Class[] { String.class, SQLXML.class } ),
new MD( "setShort", new Class[] { String.class, short.class } ),
new MD( "setString", new Class[] { String.class, String.class } ),
new MD( "setTime", new Class[] { String.class, Time.class } ),
new MD( "setTime", new Class[] { String.class, Time.class, Calendar.class } ),
new MD( "setTimestamp", new Class[] { String.class, Timestamp.class } ),
new MD( "setTimestamp", new Class[] { String.class, Timestamp.class, Calendar.class } ),
new MD( "setURL", new Class[] { int.class, URL.class } ),
new MD( "setURL", new Class[] { String.class, URL.class } )
}
),
new Exclusions
(
java.sql.ResultSet.class,
new MD[]
{
//
// THE FOLLOWING METHODS ARE MANDATORY ACCORDING TO THE
// JDBC SPEC. HOWEVER, DERBY DOES NOT IMPLEMENT THEM IN ONE
// OR THE OTHER OF OUR CLIENTS.
//
new FD( "updateNClob",new Class[] { int.class,Reader.class,long.class}),
new FD( "updateNClob",new Class[] { String.class,Reader.class,long.class}),
//
// According to the JDBC4 spec and javadoc, the following
// methods are optional and do not have to be implemented.
//
new MD( "getNCharacterStream", new Class[] { int.class } ),
new MD( "getNCharacterStream", new Class[] { String.class } ),
new MD( "getNString", new Class[] { int.class } ),
new MD( "getNString", new Class[] { String.class } ),
new MD( "getURL", new Class[] { int.class } ),
new MD( "getURL", new Class[] { String.class } ),
new MD( "getArray", new Class[] { int.class } ),
new MD( "getArray", new Class[] { String.class } ),
new MD( "getNClob", new Class[] { int.class } ),
new MD( "getNClob", new Class[] { String.class } ),
new MD( "getRef", new Class[] { int.class } ),
new MD( "getRef", new Class[] { String.class } ),
new MD( "getRowId", new Class[] { int.class } ),
new MD( "getRowId", new Class[] { String.class } ),
new MD( "getSQLXML", new Class[] { int.class } ),
new MD( "getSQLXML", new Class[] { String.class } ),
new MD( "getUnicodeStream", new Class[] { int.class } ),
new MD( "getUnicodeStream", new Class[] { String.class } ),
new MD( "refreshRow", new Class[] { } ),
new MD( "updateArray", new Class[] { int.class, java.sql.Array.class } ),
new MD( "updateArray", new Class[] { String.class, java.sql.Array.class } ),
new MD( "updateNCharacterStream", new Class[] { int.class, java.io.Reader.class } ),
new MD( "updateNCharacterStream", new Class[] { int.class, java.io.Reader.class, long.class } ),
new MD( "updateNCharacterStream", new Class[] { String.class, java.io.Reader.class } ),
new MD( "updateNCharacterStream", new Class[] { String.class, java.io.Reader.class, long.class } ),
new MD( "updateNClob", new Class[] { int.class, NClob.class } ),
new MD( "updateNClob", new Class[] { int.class, Reader.class } ),
new MD( "updateNClob", new Class[] { String.class, NClob.class } ),
new MD( "updateNClob", new Class[] { String.class, Reader.class } ),
new MD( "updateNString", new Class[] { int.class, String.class } ),
new MD( "updateNString", new Class[] { String.class, String.class } ),
new MD( "updateRef", new Class[] { int.class, Ref.class } ),
new MD( "updateRef", new Class[] { String.class, Ref.class } ),
new MD( "updateRowId", new Class[] { int.class, RowId.class } ),
new MD( "updateRowId", new Class[] { String.class, RowId.class } ),
new MD( "updateSQLXML", new Class[] { int.class, SQLXML.class } ),
new MD( "updateSQLXML", new Class[] { String.class, SQLXML.class } )
} ),
//
// Lance Andersen, spec lead for JDBC4, says:
// If you support a datatype, then you have to implement
// all of its methods.
//
};
//
// Make an MD if the JVM level supports the indicated classes.
// Returns null if the JVM doesn't.
//
private static MD makeMD
( String methodName, String[] argClassNames, boolean requiredAtThisLevel )
{
// return null if the class names can't be resolved
int count = argClassNames.length;
Class[] argTypes = new Class[ count ];
try {
for ( int i = 0; i < count; i++ )
{
String className = argClassNames[ i ];
if ( "int".equals( className ) ) { argTypes[ i ] = int.class; }
else { argTypes[ i ] = Class.forName( argClassNames[ i ] ); }
}
}
catch (Exception e) { return null; }
return new MD( methodName, argTypes, requiredAtThisLevel );
}
//
// This is the Hashtable where we keep the exclusions.
//
private static Hashtable< Class, HashSet<Method> > excludableMap;
/////////////////////////////////////////////////////////////
//
// CONSTRUCTOR
//
/////////////////////////////////////////////////////////////
/**
* Creates a new instance.
*/
public UnsupportedVetter() { super("UnsupportedVetter"); }
/////////////////////////////////////////////////////////////
//
// ENTRY POINTS
//
/////////////////////////////////////////////////////////////
/**
* <p>
* Find all methods in this framework which raise SQLFeatureNotSupportedException.
* </p>
*/
public void testSupportedMethods()
throws Exception
{
getTestConfiguration().setVerbosity( true );
// do not run on java 9. it introduces classes and methods not found in java 8.
if (vmAtLeast(1, 9)) { return; }
if ( savedVerbosity ) { println( "Supports JDBC 4.2 = " + JDBC. vmSupportsJDBC42() ); }
HashSet<String> vanishedMethodList = new HashSet<String>();
HashSet<String> unsupportedList = new HashSet<String>();
HashSet<String> notUnderstoodList = new HashSet<String>();
// Build map of interfaces to their methods which may raise SQLFeatureNotSupportedException.
initializeExcludableMap( vanishedMethodList );
vetDataSource( unsupportedList, notUnderstoodList );
vetConnectionPooledDataSource( unsupportedList, notUnderstoodList );
vetXADataSource( unsupportedList, notUnderstoodList );
//
// Print methods which behave unexpectedly.
//
printVanishedMethodList( vanishedMethodList );
printUnsupportedList( unsupportedList );
printNotUnderstoodList( notUnderstoodList );
assertEquals( "vanishedMethodList", 0, vanishedMethodList.size() );
assertEquals( "unsupportedList", 0, unsupportedList.size() );
assertEquals( "notUnderstoodList", 0, notUnderstoodList.size() );
}
//
// Find all the objects inside the DataSource and vet them.
//
private void vetDataSource
( HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
DataSource ds = JDBCDataSource.getDataSource();
Connection conn = ds.getConnection();
vetObject( ds, unsupportedList, notUnderstoodList );
connectionWorkhorse( conn, unsupportedList, notUnderstoodList );
}
//
// Find all the objects inside the ConnectionPooledDataSource and vet them.
//
private void vetConnectionPooledDataSource
( HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
PooledConnection pc = ds.getPooledConnection
(getTestConfiguration().getUserName(),
getTestConfiguration().getUserPassword());
Connection conn = pc.getConnection();
vetObject( ds, unsupportedList, notUnderstoodList );
vetObject( pc, unsupportedList, notUnderstoodList );
connectionWorkhorse( conn, unsupportedList, notUnderstoodList );
}
//
// Find all the objects inside the XADataSource and vet them.
//
private void vetXADataSource
( HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
XADataSource ds = J2EEDataSource.getXADataSource();
XAConnection xaconn = ds.getXAConnection
(getTestConfiguration().getUserName(),
getTestConfiguration().getUserPassword());
Connection conn = xaconn.getConnection();
vetObject( ds, unsupportedList, notUnderstoodList );
vetObject( xaconn, unsupportedList, notUnderstoodList );
connectionWorkhorse( conn, unsupportedList, notUnderstoodList );
}
//
// Find all the methods for java.sql objects in the Connection which raise
// SQLFeatureNotSupportedException.
//
private void connectionWorkhorse
( Connection conn, HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
vetSavepoint( conn, unsupportedList, notUnderstoodList );
vetLargeObjects( conn, unsupportedList, notUnderstoodList );
DatabaseMetaData dbmd = conn.getMetaData();
PreparedStatement ps = conn.prepareStatement
( "select * from sys.systables where tablename = ?" );
ps.setString( 1, "foo" );
ParameterMetaData parameterMetaData = ps.getParameterMetaData();
ResultSet rs = ps.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
Statement stmt = conn.createStatement();
CallableStatement cs =
conn.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(0)");
ParameterMetaData csmd = cs.getParameterMetaData();
//
// The vetObject() method calls all of the methods in these objects
// in a deterministic order, calling the close() method last.
// Inspect these objects in an order which respects the fact that
// the objects are closed as a result of calling vetObject().
//
vetObject( dbmd, unsupportedList, notUnderstoodList );
vetObject( stmt, unsupportedList, notUnderstoodList );
vetObject( csmd, unsupportedList, notUnderstoodList );
vetObject( cs, unsupportedList, notUnderstoodList );
vetObject( rsmd, unsupportedList, notUnderstoodList );
vetObject( rs, unsupportedList, notUnderstoodList );
vetObject( parameterMetaData, unsupportedList, notUnderstoodList );
vetObject( ps, unsupportedList, notUnderstoodList );
vetObject( conn, unsupportedList, notUnderstoodList );
// No need to close the objects. They were closed by vetObject().
}
//
// Examine Savepoints.
//
private void vetSavepoint
( Connection conn, HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
conn.setAutoCommit( false );
Savepoint sp = conn.setSavepoint();
vetObject( sp, unsupportedList, notUnderstoodList );
conn.releaseSavepoint(sp);
}
//
// Examine BLOBs and CLOBs.
//
private void vetLargeObjects
( Connection conn, HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE t (id INT PRIMARY KEY, " +
"b BLOB(10), c CLOB(10))");
stmt.execute("INSERT INTO t (id, b, c) VALUES (1, "+
"CAST (" + TestUtil.stringToHexLiteral("101010001101") +
"AS BLOB(10)), CAST ('hello' AS CLOB(10)))");
ResultSet rs = stmt.executeQuery("SELECT id, b, c FROM t");
rs.next();
Blob blob = rs.getBlob(2);
Clob clob = rs.getClob(3);
vetObject( blob, unsupportedList, notUnderstoodList );
vetObject( clob, unsupportedList, notUnderstoodList );
stmt.close();
conn.rollback();
}
/////////////////////////////////////////////////////////////
//
// MINIONS
//
/////////////////////////////////////////////////////////////
//
// Initialize the hashtable of methods which are allowed to raise
// SQLFeatureNotSupportedException.
//
private void initializeExcludableMap( HashSet<String> vanishedMethodList )
throws Exception
{
excludableMap = new Hashtable< Class, HashSet<Method> >();
int count = rawExcludables.length;
for ( int i = 0; i < count; i++ )
{
Exclusions exclusions = rawExcludables[ i ];
Class<?> iface = exclusions.getInterface();
MD[] mds = exclusions.getExcludedMethods();
int exclusionCount = mds.length;
HashSet<Method> excludedMethodSet = new HashSet<Method>();
for ( int j = 0; j < exclusionCount; j++ )
{
MD md = mds[ j ];
if ( md == null ) { continue; }
if ( !md.requiredAtThisLevel() ) { continue; }
//
// If we are strictly enforcing the JDBC standard,
// then expose the mandatory methods which we know Derby
// doesn't implement.
//
if ( STRICT_ENFORCEMENT && !md.isOptional() ) { continue; }
Method method = null;
try {
method = iface.getMethod( md.getMethodName(), md.getArgTypes() );
} catch (NoSuchMethodException e) {}
if ( method == null )
{
vanishedMethodList.add
( "Method has vanished from SQL interface: " + iface.getName() + "." + md );
}
excludedMethodSet.add( method );
}
excludableMap.put( iface, excludedMethodSet );
}
}
//
// Find all the methods from java.sql interfaces which are implemented by an object
// and which raise SQLFeatureNotSupportedException.
//
private void vetObject
( Object candidate, HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
Class myClass = candidate.getClass();
vetInterfaces( candidate, myClass, unsupportedList, notUnderstoodList );
}
//
// Find all the java.sql interfaces implemented by a class and find
// the methods in those interfaces which raise
// SQLFeatureNotSupportedException when called on the passed-in candidate object.
//
private void vetInterfaces
( Object candidate, Class myClass,
HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
Class superClass = myClass.getSuperclass();
if ( superClass != null )
{ vetInterfaces( candidate, superClass, unsupportedList, notUnderstoodList ); }
//
// The contract for Class.getInterfaces() states that the interfaces
// come back in a deterministic order, namely, in the order that
// they were declared in the "extends" clause.
//
Class<?>[] interfaces = myClass.getInterfaces();
int interfaceCount = interfaces.length;
for ( int i = 0; i < interfaceCount; i++ )
{
Class<?> iface = interfaces[ i ];
if ( iface.getPackage().getName().equals( SQL_PACKAGE_NAME ) )
{
vetInterfaceMethods( candidate, iface, unsupportedList, notUnderstoodList );
}
vetInterfaces( candidate, iface, unsupportedList, notUnderstoodList );
}
}
//
// Examine all the methods in an interface to determine which ones
// raise SQLFeatureNotSupportedException.
//
private void vetInterfaceMethods
( Object candidate, Class iface,
HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
Method[] methods = sortMethods( iface );
int methodCount = methods.length;
for ( int i = 0; i < methodCount; i++ )
{
Method method = methods[ i ];
vetMethod( candidate, iface, method, unsupportedList, notUnderstoodList );
}
}
//
// Return the methods of an interface in a deterministic
// order. Class.getMethods() does not do us this favor.
//
private Method[] sortMethods( Class iface )
throws Exception
{
Method[] raw = iface.getMethods();
int count = raw.length;
Method[] cooked = new Method[ count ];
MethodSortable[] sortables = new MethodSortable[ count ];
for ( int i = 0; i < count; i++ ) { sortables[ i ] = new MethodSortable( raw[ i ] ); }
Arrays.sort( sortables );
for ( int i = 0; i < count; i++ ) { cooked[ i ] = sortables[ i ].getMethod(); }
return cooked;
}
//
// Examine a single method to see if it raises SQLFeatureNotSupportedException.
//
private void vetMethod
( Object candidate, Class iface, Method method,
HashSet<String> unsupportedList, HashSet<String> notUnderstoodList )
throws Exception
{
try {
method.invoke( candidate, getNullArguments( method.getParameterTypes() ) );
// it's ok for the method to succeed
}
catch (Throwable e)
{
if ( !( e instanceof InvocationTargetException ) )
{
recordUnexpectedError( candidate, iface, method, notUnderstoodList, e );
}
else
{
Throwable cause = e.getCause();
if ( cause instanceof SQLFeatureNotSupportedException )
{
boolean isExcludable = isExcludable( method );
if ( !isExcludable )
{
StackTraceElement[] stack =
cause.getStackTrace();
int i = 0;
while(i < stack.length && !stack[i].getMethodName().
equals("notImplemented")){
++i;
}
while(i < stack.length && stack[i].getMethodName().
equals("notImplemented")){
++i;
}
if (i == stack.length) {
//cause.printStackTrace();
}
unsupportedList.add( candidate.getClass().getName() + ": " + method + "@" + (i==stack.length?"no source":cause.getStackTrace()[i]));
} else {
}
}
else if ( cause instanceof SQLException )
{
// swallow other SQLExceptions, caused by bogus args
}
else if ( cause instanceof NullPointerException )
{
// swallow other NPEs, caused by bogus args
}
else if ( cause instanceof ArrayIndexOutOfBoundsException )
{
// swallow these, caused by bogus args
}
else
{
recordUnexpectedError( candidate, iface, method, notUnderstoodList, cause );
}
}
}
}
//
// Record an unexpected error.
//
private void recordUnexpectedError
( Object candidate, Class iface, Method method,
HashSet<String> notUnderstoodList, Throwable cause )
throws Exception
{
notUnderstoodList.add
( candidate.getClass().getName() + " " + method + " raises " + cause );
}
//
// Returns true if this method is allowed to raise SQLFeatureNotSupportedException.
//
private boolean isExcludable(Method method )
throws Exception
{
Class iface = method.getDeclaringClass();
HashSet<Method> excludableMethods = excludableMap.get( iface );
if ( excludableMethods == null )
{
return false;
}
return excludableMethods.contains( method );
}
/**
* Takes an array of classes and returns an array of objects with
* null values compatible with the classes. Helper method for
* converting a parameter list to an argument list.
*
* @param params a <code>Class[]</code> value
* @return an <code>Object[]</code> value
*/
private Object[] getNullArguments(Class[] params) {
Object[] args = new Object[params.length];
for (int i = 0; i < params.length; i++) {
args[i] = getNullValueForType(params[i]);
}
return args;
}
/**
* Returns a null value compatible with the class. For instance,
* return <code>Boolean.FALSE</code> for primitive booleans, 0 for
* primitive integers and <code>null</code> for non-primitive
* types.
*
* @param type a <code>Class</code> value
* @return a null value
*/
private Object getNullValueForType(Class type)
{
if (!type.isPrimitive()) {
return null;
}
if (type == Boolean.TYPE) {
return Boolean.FALSE;
}
if (type == Character.TYPE) {
return (char) 0;
}
if (type == Byte.TYPE) {
return (byte) 0;
}
if (type == Short.TYPE) {
return (short) 0;
}
if (type == Integer.TYPE) {
// use 1 instead of 0. 0 = java.sql.Types.NULL and this causes
// various type-aware methods to raise SQLFeatureNotSupportedException
return 1;
}
if (type == Long.TYPE) {
return 0L;
}
if (type == Float.TYPE) {
return 0f;
}
if (type == Double.TYPE) {
return 0d;
}
fail("Don't know how to handle type " + type);
return null; // unreachable statement
}
// debug print the list of methods which throw SQLFeatureNotSupportedException
private void printUnsupportedList( HashSet<String> unsupportedList )
{
int count = unsupportedList.size();
if ( count == 0 ) { return; }
println( "--------------- UNSUPPORTED METHODS ------------------" );
println( "--" );
String[] result = new String[ count ];
unsupportedList.toArray( result );
Arrays.sort( result );
for ( int i = 0; i < count; i++ )
{
println( result[ i ] );
}
}
// debug print the list of methods which have disappeared from the SQL interface
private void printVanishedMethodList( HashSet<String> vanishedMethodList )
{
int count = vanishedMethodList.size();
if ( count == 0 ) { return; }
println( "--------------- VANISHED METHODS ------------------" );
println( "--" );
String[] result = new String[ count ];
vanishedMethodList.toArray( result );
Arrays.sort( result );
for ( int i = 0; i < count; i++ )
{
println( result[ i ] );
}
}
// Debug print the list of method failures which we don't understand
private void printNotUnderstoodList( HashSet<String> notUnderstoodList )
{
int count = notUnderstoodList.size();
if ( count == 0 ) { return; }
println( "\n\n" );
println( "--------------- NOT UNDERSTOOD METHODS ------------------" );
println( "--" );
String[] result = new String[ count ];
notUnderstoodList.toArray( result );
Arrays.sort( result );
for ( int i = 0; i < count; i++ )
{
println( result[ i ] );
}
}
/////////////////////////////////////////////////////////////
//
// INNER CLASSES
//
/////////////////////////////////////////////////////////////
/**
* <p>
* Method descriptor for optional methods which Derby does not have
* to implement. We abbreviate the name of this class to make
* arrays of these declarations compact and readable.
* </p>
*/
public static class MD
{
private String _methodName;
private Class[] _argTypes;
private boolean _requiredAtThisLevel;
/** Construct from methodName and argument types. */
public MD( String methodName, Class[] argTypes )
{
this( methodName, argTypes, true );
}
public MD( String methodName, Class[] argTypes, boolean requiredAtThisLevel )
{
_methodName = methodName;
_argTypes = argTypes;
_requiredAtThisLevel = requiredAtThisLevel;
}
/** Get the name of this method. */
public String getMethodName() { return _methodName; }
/** Get the types of the method's arguments */
public Class[] getArgTypes() { return _argTypes; }
/** Return whether this method is optional */
public boolean isOptional() { return true; }
/** Return whether this method is required at the current JDBC level */
public boolean requiredAtThisLevel() { return _requiredAtThisLevel; }
public String toString()
{
StringBuffer buffer = new StringBuffer();
buffer.append( _methodName );
buffer.append( "( " );
if ( _argTypes != null )
{
int count = _argTypes.length;
for ( int i = 0; i < count; i++ )
{
if ( i > 0 ) { buffer.append( ", " ); }
buffer.append( _argTypes[ i ].getName() );
}
}
buffer.append( " )" );
return buffer.toString();
}
}
/**
* <p>
* Method descriptor for mandatory methods which we know Derby does not
* implement. We abbreviate the name of this class to make
* arrays of these declarations compact and readable.
* </p>
*/
public static final class FD extends MD
{
private String _methodName;
private Class[] _argTypes;
/** Construct from methodName and argument types. */
public FD( String methodName, Class[] argTypes ) { super( methodName, argTypes ); }
/** Return whether this method is optional */
public boolean isOptional() { return false; }
}
/**
* <p>
* Describes all of the methods for an interface which are allowed
* to raise SQLFeatureNotSupportedException.
* </p>
*/
public static final class Exclusions
{
private Class _class;
private MD[] _excludedMethods;
/** Construct from the interface and descriptors for the methods which
are allowed to raise SQLFeatureNotSupportedException */
public Exclusions( Class theInterface, MD[] excludedMethods )
{
_class = theInterface;
_excludedMethods = excludedMethods;
}
/** Get the interface. */
public Class getInterface() { return _class; }
/** Get descriptors for the methods which may raise
SQLFeatureNotSupportedException. */
public MD[] getExcludedMethods() { return _excludedMethods; }
}
/**
* <p>
* Used for sorting methods, which don't come back from Class.getMethods()
* in a deterministic order. For extra credit, we put the close() method at
* the end of the sort order so that, when we invoke the sorted methods, we
* don't accidentally invalidate the receiver.
* </p>
*/
public static final class MethodSortable implements Comparable
{
private Method _method;
/** Conjure out of a Method */
public MethodSortable( Method method ) { _method = method; }
/** Get the wrapped Method */
public Method getMethod() { return _method; }
//////////////////////////////////////////////////
//
// Comparable BEHAVIOR
//
//////////////////////////////////////////////////
public int compareTo( Object other )
{
MethodSortable that = (MethodSortable) other;
boolean thisIsClose = this.isCloseMethod();
boolean thatIsClose = that.isCloseMethod();
// throw the close() method to the end of the sort order
if ( thisIsClose )
{
if ( thatIsClose ) { return 0; }
else { return 1; }
}
else if ( thatIsClose ) { return -1; }
return this.toString().compareTo( that.toString() );
}
//////////////////////////////////////////////////
//
// Object OVERRIDES
//
//////////////////////////////////////////////////
public String toString() { return _method.toString(); }
//////////////////////////////////////////////////
//
// MINIONS
//
//////////////////////////////////////////////////
// Returns true if the wrapped method is close().
private boolean isCloseMethod()
{
return ( toString().startsWith( "close()" ) );
}
}
private boolean savedVerbosity;
protected void setUp() {
// testSupportedMethods() sets the verbosity, so we need to save the
// original verbosity here and restore it in tearDown.
savedVerbosity = getTestConfiguration().isVerbose();
}
protected void tearDown() throws Exception {
getTestConfiguration().setVerbosity(savedVerbosity);
super.tearDown();
}
public static Test suite() {
return TestConfiguration.defaultSuite(UnsupportedVetter.class);
}
}
|