2727import static io .opentelemetry .semconv .incubating .DbIncubatingAttributes .DB_USER ;
2828import static java .util .Arrays .asList ;
2929import static org .assertj .core .api .Assertions .assertThatThrownBy ;
30- import static org .junit .jupiter .api .Assumptions .assumeTrue ;
3130
3231import com .google .common .collect .ImmutableMap ;
3332import com .google .common .collect .Maps ;
@@ -850,23 +849,44 @@ static Stream<Arguments> preparedStatementLargeUpdateStream() throws SQLExceptio
850849 "CREATE TABLE PS_LARGE_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))" ,
851850 "CREATE TABLE jdbcunittest.PS_LARGE_H2" ,
852851 "h2:mem:" ,
853- "PS_LARGE_H2" ),
852+ "PS_LARGE_H2" ,
853+ true ),
854854 Arguments .of (
855855 "h2" ,
856856 cpDatasources .get ("tomcat" ).get ("h2" ).getConnection (),
857857 null ,
858858 "CREATE TABLE PS_LARGE_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))" ,
859859 "CREATE TABLE jdbcunittest.PS_LARGE_H2_TOMCAT" ,
860860 "h2:mem:" ,
861- "PS_LARGE_H2_TOMCAT" ),
861+ "PS_LARGE_H2_TOMCAT" ,
862+ true ),
862863 Arguments .of (
863864 "h2" ,
864865 cpDatasources .get ("hikari" ).get ("h2" ).getConnection (),
865866 null ,
866867 "CREATE TABLE PS_LARGE_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))" ,
867868 "CREATE TABLE jdbcunittest.PS_LARGE_H2_HIKARI" ,
868869 "h2:mem:" ,
869- "PS_LARGE_H2_HIKARI" ));
870+ "PS_LARGE_H2_HIKARI" ,
871+ true ),
872+ Arguments .of (
873+ "derby" ,
874+ new EmbeddedDriver ().connect (jdbcUrls .get ("derby" ), null ),
875+ "APP" ,
876+ "CREATE TABLE PS_LARGE_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))" ,
877+ "CREATE TABLE jdbcunittest.PS_LARGE_DERBY" ,
878+ "derby:memory:" ,
879+ "PS_LARGE_DERBY" ,
880+ false ),
881+ Arguments .of (
882+ "hsqldb" ,
883+ new JDBCDriver ().connect (jdbcUrls .get ("hsqldb" ), null ),
884+ "SA" ,
885+ "CREATE TABLE PUBLIC.PS_LARGE_HSQLDB (id INTEGER not NULL, PRIMARY KEY ( id ))" ,
886+ "CREATE TABLE PUBLIC.PS_LARGE_HSQLDB" ,
887+ "hsqldb:mem:" ,
888+ "PUBLIC.PS_LARGE_HSQLDB" ,
889+ false ));
870890 }
871891
872892 @ ParameterizedTest
@@ -878,12 +898,13 @@ void testPreparedStatementLargeUpdate(
878898 String query ,
879899 String spanName ,
880900 String url ,
881- String table )
901+ String table ,
902+ boolean supportsJdbc42 )
882903 throws SQLException {
883904 Connection connection = wrap (conn );
884-
905+
885906 // executeLargeUpdate was added in JDBC 4.2
886- if (supportsJdbc42 ( connection ) ) {
907+ if (supportsJdbc42 ) {
887908 testPreparedStatementUpdateImpl (
888909 system ,
889910 connection ,
@@ -1433,6 +1454,24 @@ static Stream<Arguments> batchStream() throws SQLException {
14331454 "hsqldb" , new JDBCDriver ().connect (jdbcUrls .get ("hsqldb" ), null ), "SA" , "hsqldb:mem:" ));
14341455 }
14351456
1457+ static Stream <Arguments > largeBatchStream () throws SQLException {
1458+ return Stream .of (
1459+ Arguments .of (
1460+ "h2" , new org .h2 .Driver ().connect (jdbcUrls .get ("h2" ), null ), null , "h2:mem:" , true ),
1461+ Arguments .of (
1462+ "derby" ,
1463+ new EmbeddedDriver ().connect (jdbcUrls .get ("derby" ), null ),
1464+ "APP" ,
1465+ "derby:memory:" ,
1466+ false ),
1467+ Arguments .of (
1468+ "hsqldb" ,
1469+ new JDBCDriver ().connect (jdbcUrls .get ("hsqldb" ), null ),
1470+ "SA" ,
1471+ "hsqldb:mem:" ,
1472+ false ));
1473+ }
1474+
14361475 @ ParameterizedTest
14371476 @ MethodSource ("batchStream" )
14381477 void testBatch (String system , Connection connection , String username , String url )
@@ -1447,11 +1486,10 @@ void testBatch(String system, Connection connection, String username, String url
14471486 }
14481487
14491488 @ ParameterizedTest
1450- @ MethodSource ("batchStream" )
1451- void testLargeBatch (String system , Connection connection , String username , String url )
1489+ @ MethodSource ("largeBatchStream" )
1490+ void testLargeBatch (
1491+ String system , Connection connection , String username , String url , boolean supportsJdbc42 )
14521492 throws SQLException {
1453- // derby and hsqldb used in this test don't support executeLargeBatch
1454- assumeTrue ("h2" .equals (system ));
14551493
14561494 Statement createTable = wrap (connection ).createStatement ();
14571495 createTable .execute (
@@ -1461,7 +1499,7 @@ void testLargeBatch(String system, Connection connection, String username, Strin
14611499 statement .addBatch ("INSERT INTO simple_batch_test_large VALUES(2)" );
14621500
14631501 // executeLargeBatch was added in JDBC 4.2
1464- if (supportsJdbc42 ( connection ) ) {
1502+ if (supportsJdbc42 ) {
14651503 assertThat (statement .executeLargeBatch ()).isEqualTo (new long [] {1 , 1 });
14661504 } else {
14671505 // Driver doesn't support JDBC 4.2, expect UnsupportedOperationException
@@ -1471,12 +1509,6 @@ void testLargeBatch(String system, Connection connection, String username, Strin
14711509 }
14721510 }
14731511
1474- private static boolean supportsJdbc42 (Connection connection ) throws SQLException {
1475- return connection .getMetaData ().getJDBCMajorVersion () > 4
1476- || (connection .getMetaData ().getJDBCMajorVersion () == 4
1477- && connection .getMetaData ().getJDBCMinorVersion () >= 2 );
1478- }
1479-
14801512 private void testBatchImpl (
14811513 String system ,
14821514 Connection connection ,
0 commit comments