From 414a0dd75d5df62f536be068ace2cf53d27b12e5 Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Wed, 11 Jul 2018 18:22:31 +0300 Subject: [PATCH] HHH-12787 - SessionJdbcBatchTest hangs with DB2 --- .../test/agroal/AgroalSkipAutoCommitTest.java | 3 + ...stractCriteriaLiteralHandlingModeTest.java | 34 ++--- .../nulliteral/CriteriaLiteralsTest.java | 50 +++----- ...eDiscardPersistenceContextOnCloseTest.java | 3 + ...eDiscardPersistenceContextOnCloseTest.java | 5 + .../EntityGraphWithFetchAnnotationTest.java | 32 ++--- ...tementIsClosedAfterALockExceptionTest.java | 3 + .../jpa/test/query/NamedQueryCommentTest.java | 118 +++++------------- .../query/InClauseParameterPaddingTest.java | 31 ++--- .../MaxInExpressionParameterPaddingTest.java | 29 ++--- ...dableWithOneToMany_HHH_11302_xml_Test.java | 11 -- ...ySQLDropConstraintThrowsExceptionTest.java | 3 + .../test/criteria/CriteriaQueryTest.java | 5 +- .../insertordering/ElementCollectionTest.java | 15 +-- ...rtOrderingWithBidirectionalManyToMany.java | 3 + ...deringWithBidirectionalMapsIdOneToOne.java | 3 + ...ertOrderingWithBidirectionalOneToMany.java | 3 + ...sertOrderingWithBidirectionalOneToOne.java | 3 + ...ertOrderingWithJoinedTableInheritance.java | 3 + ...gWithJoinedTableMultiLevelInheritance.java | 3 + .../InsertOrderingWithManyToOne.java | 3 + .../InsertOrderingWithMultipleManyToOne.java | 3 + ...ertOrderingWithSingleTableInheritance.java | 3 + ...tOrderingWithTablePerClassInheritance.java | 3 + ...ertOrderingWithUnidirectionalOneToOne.java | 3 + .../jdbc/internal/SessionJdbcBatchTest.java | 5 + .../test/queryhint/QueryHintHANATest.java | 70 ++++------- .../test/queryhint/QueryHintTest.java | 73 ++++------- .../test/querytimeout/QueryTimeOutTest.java | 3 + .../AbstractSkipAutoCommitTest.java | 3 + .../timestamp/JdbcTimeCustomTimeZoneTest.java | 3 + .../JdbcTimeDefaultTimeZoneTest.java | 4 + ...mestampCustomSessionLevelTimeZoneTest.java | 3 + .../JdbcTimestampCustomTimeZoneTest.java | 3 + .../JdbcTimestampDefaultTimeZoneTest.java | 3 + .../hikaricp/HikariCPSkipAutoCommitTest.java | 3 + .../org/hibernate/testing/DialectChecks.java | 9 ++ .../testing/jdbc/SQLStatementInterceptor.java | 26 +++- 38 files changed, 246 insertions(+), 337 deletions(-) diff --git a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalSkipAutoCommitTest.java b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalSkipAutoCommitTest.java index e4025cb298..d32cc2be75 100644 --- a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalSkipAutoCommitTest.java +++ b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalSkipAutoCommitTest.java @@ -9,6 +9,8 @@ package org.hibernate.test.agroal; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; import org.hibernate.test.agroal.util.PreparedStatementSpyConnectionProvider; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -28,6 +30,7 @@ import static org.mockito.Mockito.verify; /** * @author Vlad Mihalcea */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class AgroalSkipAutoCommitTest extends BaseCoreFunctionalTestCase { private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/AbstractCriteriaLiteralHandlingModeTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/AbstractCriteriaLiteralHandlingModeTest.java index 2df54e6482..1b5dab0546 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/AbstractCriteriaLiteralHandlingModeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/AbstractCriteriaLiteralHandlingModeTest.java @@ -20,41 +20,27 @@ import org.hibernate.dialect.H2Dialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Before; import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; +import static org.hibernate.testing.transaction.TransactionUtil.setJdbcTimeout; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * @author Vlad Mihalcea */ public abstract class AbstractCriteriaLiteralHandlingModeTest extends BaseEntityManagerFunctionalTestCase { - private PreparedStatementSpyConnectionProvider connectionProvider; + private SQLStatementInterceptor sqlStatementInterceptor; @Override - protected Map getConfig() { - Map config = super.getConfig(); - config.put( - org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, - connectionProvider - ); - return config; - } - - @Override - public void buildEntityManagerFactory() { - connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); - super.buildEntityManagerFactory(); - } - - @Override - public void releaseResources() { - super.releaseResources(); - connectionProvider.stop(); + protected void addConfigOptions(Map options) { + sqlStatementInterceptor = new SQLStatementInterceptor( options ); } @Override @@ -101,12 +87,12 @@ public abstract class AbstractCriteriaLiteralHandlingModeTest extends BaseEntity entity.get( "name" ) ); - connectionProvider.clear(); - List tuples = entityManager.createQuery( query ) - .getResultList(); + sqlStatementInterceptor.clear(); + + List tuples = entityManager.createQuery( query ).getResultList(); assertEquals( 1, tuples.size() ); - assertNotNull( connectionProvider.getPreparedStatement( expectedSQL() ) ); + sqlStatementInterceptor.assertExecuted( expectedSQL() ); } ); } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/CriteriaLiteralsTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/CriteriaLiteralsTest.java index 8d4b0a06ce..b38f9ab95e 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/CriteriaLiteralsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/CriteriaLiteralsTest.java @@ -29,7 +29,7 @@ import org.hibernate.hql.internal.ast.QuerySyntaxException; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.RequiresDialect; -import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; +import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.junit.Before; import org.junit.Test; @@ -44,29 +44,12 @@ import static org.junit.Assert.fail; */ @RequiresDialect(H2Dialect.class) public class CriteriaLiteralsTest extends BaseEntityManagerFunctionalTestCase { - - private PreparedStatementSpyConnectionProvider connectionProvider; + + private SQLStatementInterceptor sqlStatementInterceptor; @Override - protected Map getConfig() { - Map config = super.getConfig(); - config.put( - org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, - connectionProvider - ); - return config; - } - - @Override - public void buildEntityManagerFactory() { - connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); - super.buildEntityManagerFactory(); - } - - @Override - public void releaseResources() { - super.releaseResources(); - connectionProvider.stop(); + protected void addConfigOptions(Map options) { + sqlStatementInterceptor = new SQLStatementInterceptor( options ); } @Override @@ -128,16 +111,15 @@ public class CriteriaLiteralsTest extends BaseEntityManagerFunctionalTestCase { entity.get( "name" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.clear(); List tuples = entityManager.createQuery( query ) .getResultList(); assertEquals( 1, - connectionProvider.getPreparedStatements().size() + sqlStatementInterceptor.getSqlQueries().size() ); - assertNotNull( connectionProvider.getPreparedStatement( - "select 'abc' as col_0_0_, criteriali0_.name as col_1_0_ from Book criteriali0_ where criteriali0_.name=?" ) ); + sqlStatementInterceptor.assertExecuted("select 'abc' as col_0_0_, criteriali0_.name as col_1_0_ from Book criteriali0_ where criteriali0_.name=?"); assertTrue( tuples.isEmpty() ); } ); } @@ -178,12 +160,12 @@ public class CriteriaLiteralsTest extends BaseEntityManagerFunctionalTestCase { entity.get( "name" ) ); - connectionProvider.clear(); - List tuples = entityManager.createQuery( query ) - .getResultList(); + sqlStatementInterceptor.clear(); + + List tuples = entityManager.createQuery( query ).getResultList(); assertEquals( 1, tuples.size() ); - assertNotNull( connectionProvider.getPreparedStatement(expectedSQL) ); + sqlStatementInterceptor.assertExecuted( expectedSQL ); } @Test @@ -200,15 +182,13 @@ public class CriteriaLiteralsTest extends BaseEntityManagerFunctionalTestCase { ), cb.equal( authors.index(), 0 ) ) .select( authors.get( "name" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.clear(); entityManager.createQuery( query ).getResultList(); assertEquals( 1, - connectionProvider.getPreparedStatements().size() - ); - assertNotNull( connectionProvider.getPreparedStatement( - "select authors1_.name as col_0_0_ from Book criteriali0_ inner join Author authors1_ on criteriali0_.id=authors1_.book_id where criteriali0_.name=? and authors1_.index_id=0" ) + sqlStatementInterceptor.getSqlQueries().size() ); + sqlStatementInterceptor.assertExecuted( "select authors1_.name as col_0_0_ from Book criteriali0_ inner join Author authors1_ on criteriali0_.id=authors1_.book_id where criteriali0_.name=? and authors1_.index_id=0" ); } ); } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/DisableDiscardPersistenceContextOnCloseTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/DisableDiscardPersistenceContextOnCloseTest.java index 6ef95aa974..8ed46a1a83 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/DisableDiscardPersistenceContextOnCloseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/DisableDiscardPersistenceContextOnCloseTest.java @@ -14,6 +14,8 @@ import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.jpa.test.Wallet; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; @@ -24,6 +26,7 @@ import static org.junit.Assert.assertTrue; /** * @author Vlad Mihalcea */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class DisableDiscardPersistenceContextOnCloseTest extends BaseEntityManagerFunctionalTestCase { private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EnableDiscardPersistenceContextOnCloseTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EnableDiscardPersistenceContextOnCloseTest.java index 2fbe9cb98d..71fc4fda17 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EnableDiscardPersistenceContextOnCloseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EnableDiscardPersistenceContextOnCloseTest.java @@ -9,10 +9,14 @@ package org.hibernate.jpa.test.ejb3configuration; import java.util.Map; import javax.persistence.EntityManager; +import org.hibernate.dialect.DB2Dialect; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.jpa.test.Wallet; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; +import org.hibernate.testing.SkipForDialect; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; @@ -23,6 +27,7 @@ import static org.junit.Assert.fail; /** * @author Vlad Mihalcea */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class EnableDiscardPersistenceContextOnCloseTest extends BaseEntityManagerFunctionalTestCase { private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/EntityGraphWithFetchAnnotationTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/EntityGraphWithFetchAnnotationTest.java index 178fbf5234..cfcc2176b4 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/EntityGraphWithFetchAnnotationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/EntityGraphWithFetchAnnotationTest.java @@ -23,6 +23,7 @@ import org.hibernate.jpa.QueryHints; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; @@ -36,28 +37,11 @@ import static org.junit.Assert.assertTrue; public class EntityGraphWithFetchAnnotationTest extends BaseEntityManagerFunctionalTestCase { - private PreparedStatementSpyConnectionProvider connectionProvider; + private SQLStatementInterceptor sqlStatementInterceptor; @Override - protected Map getConfig() { - Map config = super.getConfig(); - config.put( - org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, - connectionProvider - ); - return config; - } - - @Override - public void buildEntityManagerFactory() { - connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); - super.buildEntityManagerFactory(); - } - - @Override - public void releaseResources() { - super.releaseResources(); - connectionProvider.stop(); + protected void addConfigOptions(Map options) { + sqlStatementInterceptor = new SQLStatementInterceptor( options ); } @Override @@ -79,7 +63,7 @@ public class EntityGraphWithFetchAnnotationTest .createQuery( Order.class ); criteriaQuery.from( Order.class ); - connectionProvider.clear(); + sqlStatementInterceptor.clear(); entityManager .createQuery( criteriaQuery ) @@ -87,7 +71,7 @@ public class EntityGraphWithFetchAnnotationTest .setMaxResults( 20 ) .getResultList(); - assertFalse( connectionProvider.getPreparedSQLStatements().get( 0 ).toLowerCase().contains( "left outer join" ) ); + assertFalse( sqlStatementInterceptor.getSqlQueries().get( 0 ).toLowerCase().contains( "left outer join" ) ); } ); } @@ -104,7 +88,7 @@ public class EntityGraphWithFetchAnnotationTest EntityGraph entityGraph = entityManager.createEntityGraph( Order.class ); entityGraph.addAttributeNodes( "products" ); - connectionProvider.clear(); + sqlStatementInterceptor.clear(); entityManager .createQuery( criteriaQuery ) @@ -113,7 +97,7 @@ public class EntityGraphWithFetchAnnotationTest .setHint( QueryHints.HINT_FETCHGRAPH, entityGraph ) .getResultList(); - assertTrue( connectionProvider.getPreparedSQLStatements().get( 0 ).toLowerCase().contains( "left outer join" ) ); + assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).toLowerCase().contains( "left outer join" ) ); } ); } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/lock/StatementIsClosedAfterALockExceptionTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/lock/StatementIsClosedAfterALockExceptionTest.java index c571b5c09f..304839017a 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/lock/StatementIsClosedAfterALockExceptionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/lock/StatementIsClosedAfterALockExceptionTest.java @@ -15,6 +15,8 @@ import javax.persistence.LockModeType; import org.hibernate.Session; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.hibernate.testing.transaction.TransactionUtil; @@ -30,6 +32,7 @@ import static org.junit.Assert.fail; /** * @author Andrea Boriero */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class StatementIsClosedAfterALockExceptionTest extends BaseEntityManagerFunctionalTestCase { private static final PreparedStatementSpyConnectionProvider CONNECTION_PROVIDER = new PreparedStatementSpyConnectionProvider( false, false ); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/NamedQueryCommentTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/NamedQueryCommentTest.java index 73d29fa163..c0e07bcea0 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/NamedQueryCommentTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/NamedQueryCommentTest.java @@ -26,6 +26,7 @@ import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.After; import org.junit.Before; @@ -41,32 +42,12 @@ import static org.junit.Assert.assertNotNull; @TestForIssue(jiraKey = "HHH-11640") public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { - private PreparedStatementSpyConnectionProvider connectionProvider; + private SQLStatementInterceptor sqlStatementInterceptor; @Override - protected Map getConfig() { - Map config = super.getConfig(); - config.put( - org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, - connectionProvider - ); - config.put( - AvailableSettings.USE_SQL_COMMENTS, - Boolean.TRUE.toString() - ); - return config; - } - - @Override - public void buildEntityManagerFactory() { - connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); - super.buildEntityManagerFactory(); - } - - @Override - public void releaseResources() { - super.releaseResources(); - connectionProvider.stop(); + protected void addConfigOptions(Map options) { + sqlStatementInterceptor = new SQLStatementInterceptor( options ); + options.put( AvailableSettings.USE_SQL_COMMENTS, Boolean.TRUE.toString() ); } private static final String[] GAME_TITLES = { "Halo", "Grand Theft Auto", "NetHack" }; @@ -76,11 +57,6 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { return new Class[] { Game.class }; } - @Override - protected void addConfigOptions(Map options) { - options.put( AvailableSettings.USE_SQL_COMMENTS, Boolean.TRUE.toString() ); - } - @Before public void setUp() { doInJPA( this::entityManagerFactory, entityManager -> { @@ -101,22 +77,17 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { @Test public void testSelectNamedQueryWithSqlComment() { doInJPA( this::entityManagerFactory, entityManager -> { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); TypedQuery query = entityManager.createNamedQuery( "SelectNamedQuery", Game.class ); query.setParameter( "title", GAME_TITLES[0] ); List list = query.getResultList(); assertEquals( 1, list.size() ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); + sqlStatementInterceptor.assertExecutedCount(1); - assertNotNull( - connectionProvider.getPreparedStatement( - "/* COMMENT_SELECT_INDEX_game_title */ select namedquery0_.id as id1_0_, namedquery0_.title as title2_0_ from game namedquery0_ where namedquery0_.title=?" - ) + sqlStatementInterceptor.assertExecuted( + "/* COMMENT_SELECT_INDEX_game_title */ select namedquery0_.id as id1_0_, namedquery0_.title as title2_0_ from game namedquery0_ where namedquery0_.title=?" ); } ); } @@ -124,22 +95,18 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { @Test public void testSelectNamedNativeQueryWithSqlComment() { doInJPA( this::entityManagerFactory, entityManager -> { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); TypedQuery query = entityManager.createNamedQuery( "SelectNamedNativeQuery", Game.class ); query.setParameter( "title", GAME_TITLES[0] ); List list = query.getResultList(); assertEquals( 1, list.size() ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); + sqlStatementInterceptor.assertExecutedCount(1); - assertNotNull( - connectionProvider.getPreparedStatement( + sqlStatementInterceptor.assertExecuted( "/* + INDEX (game idx_game_title) */ select * from game g where title = ?" - ) + ); } ); } @@ -147,7 +114,7 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { @Test public void testUpdateNamedQueryWithSqlComment() { doInJPA( this::entityManagerFactory, entityManager -> { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); Query query = entityManager.createNamedQuery( "UpdateNamedNativeQuery" ); query.setParameter( "title", GAME_TITLES[0] ); @@ -155,15 +122,10 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { int updateCount = query.executeUpdate(); assertEquals( 1, updateCount ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); + sqlStatementInterceptor.assertExecutedCount(1); - assertNotNull( - connectionProvider.getPreparedStatement( + sqlStatementInterceptor.assertExecuted( "/* COMMENT_INDEX_game_title */ update game set title = ? where id = ?" - ) ); } ); } @@ -171,7 +133,7 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { @Test public void testUpdateNamedNativeQueryWithSqlComment() { doInJPA( this::entityManagerFactory, entityManager -> { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); Query query = entityManager.createNamedQuery( "UpdateNamedNativeQuery" ); query.setParameter( "title", GAME_TITLES[0] ); @@ -179,15 +141,10 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { int updateCount = query.executeUpdate(); assertEquals( 1, updateCount ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); + sqlStatementInterceptor.assertExecutedCount(1); - assertNotNull( - connectionProvider.getPreparedStatement( + sqlStatementInterceptor.assertExecuted( "/* COMMENT_INDEX_game_title */ update game set title = ? where id = ?" - ) ); } ); } @@ -196,7 +153,7 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { @RequiresDialect(Oracle8iDialect.class) public void testUpdateNamedNativeQueryWithQueryHintUsingOracle() { doInJPA( this::entityManagerFactory, entityManager -> { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); Query query = entityManager.createNamedQuery( "UpdateNamedNativeQuery" ); query.setParameter( "title", GAME_TITLES[0] ); @@ -205,15 +162,10 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { int updateCount = query.executeUpdate(); assertEquals( 1, updateCount ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); + sqlStatementInterceptor.assertExecutedCount(1); - assertNotNull( - connectionProvider.getPreparedStatement( + sqlStatementInterceptor.assertExecuted( "/* COMMENT_INDEX_game_title */ update /*+ INDEX (game idx_game_id) */ game set title = ? where id = ?" - ) ); } ); } @@ -222,7 +174,7 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { @RequiresDialect(H2Dialect.class) public void testUpdateNamedNativeQueryWithQueryHintUsingIndex() { doInJPA( this::entityManagerFactory, entityManager -> { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); Query query = entityManager.createNamedQuery( "UpdateNamedNativeQuery" ); query.setParameter( "title", GAME_TITLES[0] ); @@ -231,15 +183,10 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { int updateCount = query.executeUpdate(); assertEquals( 1, updateCount ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); + sqlStatementInterceptor.assertExecutedCount(1); - assertNotNull( - connectionProvider.getPreparedStatement( + sqlStatementInterceptor.assertExecuted( "/* COMMENT_INDEX_game_title */ update game set title = ? where id = ?" - ) ); } ); } @@ -249,7 +196,7 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { @RequiresDialect(H2Dialect.class) public void testSelectNamedNativeQueryWithQueryHintUsingIndex() { doInJPA( this::entityManagerFactory, entityManager -> { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); Query query = entityManager.createNamedQuery( "SelectNamedQuery" ); query.setParameter( "title", GAME_TITLES[0] ); @@ -257,16 +204,11 @@ public class NamedQueryCommentTest extends BaseEntityManagerFunctionalTestCase { List list = query.getResultList(); assertEquals( 1, list.size() ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); + sqlStatementInterceptor.assertExecutedCount(1); - assertNotNull( - connectionProvider.getPreparedStatement( - "/* COMMENT_SELECT_INDEX_game_title */ select namedquery0_.id as id1_0_, namedquery0_.title as title2_0_ from game namedquery0_ USE INDEX (idx_game_id) where namedquery0_.title=?" - ) - ); + sqlStatementInterceptor.assertExecuted( + "/* COMMENT_SELECT_INDEX_game_title */ select namedquery0_.id as id1_0_, namedquery0_.title as title2_0_ from game namedquery0_ USE INDEX (idx_game_id) where namedquery0_.title=?" ) + ; } ); } diff --git a/hibernate-core/src/test/java/org/hibernate/query/InClauseParameterPaddingTest.java b/hibernate-core/src/test/java/org/hibernate/query/InClauseParameterPaddingTest.java index f2bc0a869f..77860ab63f 100644 --- a/hibernate-core/src/test/java/org/hibernate/query/InClauseParameterPaddingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/query/InClauseParameterPaddingTest.java @@ -15,12 +15,11 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** @@ -29,18 +28,13 @@ import static org.junit.Assert.assertTrue; @TestForIssue( jiraKey = "HHH-12469" ) public class InClauseParameterPaddingTest extends BaseEntityManagerFunctionalTestCase { - private PreparedStatementSpyConnectionProvider connectionProvider; + private SQLStatementInterceptor sqlStatementInterceptor; @Override - public void buildEntityManagerFactory() { - connectionProvider = new PreparedStatementSpyConnectionProvider(); - super.buildEntityManagerFactory(); - } - - @Override - public void releaseResources() { - super.releaseResources(); - connectionProvider.stop(); + protected void addConfigOptions(Map options) { + sqlStatementInterceptor = new SQLStatementInterceptor( options ); + options.put( AvailableSettings.USE_SQL_COMMENTS, Boolean.TRUE.toString() ); + options.put( AvailableSettings.IN_CLAUSE_PARAMETER_PADDING, Boolean.TRUE.toString() ); } @Override @@ -50,15 +44,6 @@ public class InClauseParameterPaddingTest extends BaseEntityManagerFunctionalTes }; } - @Override - protected void addConfigOptions(Map options) { - options.put( AvailableSettings.IN_CLAUSE_PARAMETER_PADDING, Boolean.TRUE.toString() ); - options.put( - org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, - connectionProvider - ); - } - @Override protected void afterEntityManagerFactoryBuilt() { doInJPA( this::entityManagerFactory, entityManager -> { @@ -87,7 +72,7 @@ public class InClauseParameterPaddingTest extends BaseEntityManagerFunctionalTes } private void validateInClauseParameterPadding(String expectedInClause, Integer... ids) { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); doInJPA( this::entityManagerFactory, entityManager -> { return entityManager.createQuery( @@ -98,7 +83,7 @@ public class InClauseParameterPaddingTest extends BaseEntityManagerFunctionalTes .getResultList(); } ); - assertTrue(connectionProvider.getPreparedSQLStatements().get( 0 ).endsWith( expectedInClause )); + assertTrue(sqlStatementInterceptor.getSqlQueries().get( 0 ).endsWith( expectedInClause )); } @Entity(name = "Person") diff --git a/hibernate-core/src/test/java/org/hibernate/query/MaxInExpressionParameterPaddingTest.java b/hibernate-core/src/test/java/org/hibernate/query/MaxInExpressionParameterPaddingTest.java index b60e602860..92fddb1315 100644 --- a/hibernate-core/src/test/java/org/hibernate/query/MaxInExpressionParameterPaddingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/query/MaxInExpressionParameterPaddingTest.java @@ -19,6 +19,7 @@ import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; @@ -32,20 +33,15 @@ import static org.junit.Assert.assertTrue; @RequiresDialect(H2Dialect.class) public class MaxInExpressionParameterPaddingTest extends BaseEntityManagerFunctionalTestCase { - private PreparedStatementSpyConnectionProvider connectionProvider; - public static final int MAX_COUNT = 15; - @Override - public void buildEntityManagerFactory() { - connectionProvider = new PreparedStatementSpyConnectionProvider(); - super.buildEntityManagerFactory(); - } + private SQLStatementInterceptor sqlStatementInterceptor; @Override - public void releaseResources() { - super.releaseResources(); - connectionProvider.stop(); + protected void addConfigOptions(Map options) { + sqlStatementInterceptor = new SQLStatementInterceptor( options ); + options.put( AvailableSettings.USE_SQL_COMMENTS, Boolean.TRUE.toString() ); + options.put( AvailableSettings.IN_CLAUSE_PARAMETER_PADDING, Boolean.TRUE.toString() ); } @Override @@ -55,15 +51,6 @@ public class MaxInExpressionParameterPaddingTest extends BaseEntityManagerFuncti }; } - @Override - protected void addConfigOptions(Map options) { - options.put( AvailableSettings.IN_CLAUSE_PARAMETER_PADDING, Boolean.TRUE.toString() ); - options.put( - AvailableSettings.CONNECTION_PROVIDER, - connectionProvider - ); - } - @Override protected Dialect getDialect() { return new MaxCountInExpressionH2Dialect(); @@ -84,7 +71,7 @@ public class MaxInExpressionParameterPaddingTest extends BaseEntityManagerFuncti @Test public void testInClauseParameterPadding() { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); doInJPA( this::entityManagerFactory, entityManager -> { return entityManager.createQuery( @@ -102,7 +89,7 @@ public class MaxInExpressionParameterPaddingTest extends BaseEntityManagerFuncti } expectedInClause.append( ")" ); - assertTrue(connectionProvider.getPreparedSQLStatements().get( 0 ).endsWith( expectedInClause.toString() )); + assertTrue(sqlStatementInterceptor.getSqlQueries().get( 0 ).endsWith( expectedInClause.toString() )); } @Entity(name = "Person") diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/EmbeddableWithOneToMany_HHH_11302_xml_Test.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/EmbeddableWithOneToMany_HHH_11302_xml_Test.java index 1e47fd62ee..ee345f5442 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/EmbeddableWithOneToMany_HHH_11302_xml_Test.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/EmbeddableWithOneToMany_HHH_11302_xml_Test.java @@ -26,8 +26,6 @@ import static org.junit.Assert.fail; public class EmbeddableWithOneToMany_HHH_11302_xml_Test extends BaseEntityManagerFunctionalTestCase { - PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); - @Override public String[] getEjb3DD() { return new String[] { @@ -45,15 +43,6 @@ public class EmbeddableWithOneToMany_HHH_11302_xml_Test extends "@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection" ) ); } - finally { - connectionProvider.stop(); - } - } - - protected Map buildSettings() { - Map settings = super.buildSettings(); - settings.put( AvailableSettings.CONNECTION_PROVIDER, connectionProvider ); - return settings; } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java index 6745f5d333..34f4911f54 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java @@ -25,7 +25,9 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.testing.DialectChecks; import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -40,6 +42,7 @@ import static org.junit.Assert.assertTrue; */ @TestForIssue(jiraKey = "HHH-11236") @RequiresDialect(MySQL5Dialect.class) +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class MySQLDropConstraintThrowsExceptionTest extends BaseUnitTestCase { @Before diff --git a/hibernate-core/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java b/hibernate-core/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java index 2dc8188fc3..46a980d4a8 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java @@ -68,7 +68,10 @@ import static org.mockito.Mockito.verify; * @author Gavin King * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -@RequiresDialectFeature(DialectChecks.SupportsSequences.class) +@RequiresDialectFeature({ + DialectChecks.SupportsSequences.class, + DialectChecks.SupportsJdbcDriverProxying.class +}) public class CriteriaQueryTest extends BaseNonConfigCoreFunctionalTestCase { private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( true, false ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/ElementCollectionTest.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/ElementCollectionTest.java index 6f04248e9b..1f1cdd755b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/ElementCollectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/ElementCollectionTest.java @@ -25,7 +25,6 @@ import org.hibernate.cfg.Environment; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; @@ -41,17 +40,11 @@ public class ElementCollectionTest extends BaseNonConfigCoreFunctionalTestCase { return new Class[] {Task.class}; } - private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); - @Override protected void addSettings(Map settings) { settings.put( Environment.ORDER_INSERTS, "true" ); settings.put( Environment.STATEMENT_BATCH_SIZE, "10" ); - settings.put( - org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, - connectionProvider - ); - } + } @Test public void testBatchOrdering() { @@ -66,12 +59,6 @@ public class ElementCollectionTest extends BaseNonConfigCoreFunctionalTestCase { } ); } - @Override - public void releaseResources() { - super.releaseResources(); - connectionProvider.stop(); - } - @Entity @Table(name = "TASK") public static class Task { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalManyToMany.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalManyToMany.java index 274fc51685..f46e17cb73 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalManyToMany.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalManyToMany.java @@ -22,6 +22,8 @@ import javax.persistence.SequenceGenerator; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -36,6 +38,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithBidirectionalManyToMany extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalMapsIdOneToOne.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalMapsIdOneToOne.java index aac1176668..bcdc7adbad 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalMapsIdOneToOne.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalMapsIdOneToOne.java @@ -21,6 +21,8 @@ import javax.persistence.SequenceGenerator; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -34,6 +36,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithBidirectionalMapsIdOneToOne extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToMany.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToMany.java index 40007c377c..d29a306b76 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToMany.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToMany.java @@ -23,6 +23,8 @@ import javax.persistence.SequenceGenerator; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -36,6 +38,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithBidirectionalOneToMany extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToOne.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToOne.java index 4d298d0352..099dcdce9b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToOne.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToOne.java @@ -8,6 +8,8 @@ package org.hibernate.test.insertordering; import org.hibernate.cfg.Environment; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.Test; @@ -25,6 +27,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithBidirectionalOneToOne extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableInheritance.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableInheritance.java index f192a47956..7a4092ccc3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableInheritance.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableInheritance.java @@ -30,6 +30,8 @@ import javax.persistence.Table; import org.hibernate.annotations.BatchSize; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -42,6 +44,7 @@ import static org.junit.Assert.assertEquals; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithJoinedTableInheritance extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableMultiLevelInheritance.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableMultiLevelInheritance.java index 3d2be218de..ab4fb1b94c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableMultiLevelInheritance.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableMultiLevelInheritance.java @@ -29,6 +29,8 @@ import javax.persistence.Table; import org.hibernate.annotations.BatchSize; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -41,6 +43,7 @@ import static org.junit.Assert.assertEquals; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithJoinedTableMultiLevelInheritance extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithManyToOne.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithManyToOne.java index e4481fe79a..8773f270f5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithManyToOne.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithManyToOne.java @@ -23,6 +23,8 @@ import javax.persistence.SequenceGenerator; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -36,6 +38,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithManyToOne extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithMultipleManyToOne.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithMultipleManyToOne.java index 8ab6a8c639..8b7b29c575 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithMultipleManyToOne.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithMultipleManyToOne.java @@ -23,6 +23,8 @@ import javax.persistence.SequenceGenerator; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -37,6 +39,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-11996") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithMultipleManyToOne extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithSingleTableInheritance.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithSingleTableInheritance.java index d44f21e3f6..b0b84c92ef 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithSingleTableInheritance.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithSingleTableInheritance.java @@ -30,6 +30,8 @@ import javax.persistence.Table; import org.hibernate.annotations.BatchSize; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -42,6 +44,7 @@ import static org.junit.Assert.assertEquals; * @author Steve Ebersole */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithSingleTableInheritance extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithTablePerClassInheritance.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithTablePerClassInheritance.java index d0e8bdcd8e..a3e48b8783 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithTablePerClassInheritance.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithTablePerClassInheritance.java @@ -30,6 +30,8 @@ import javax.persistence.Table; import org.hibernate.annotations.BatchSize; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -42,6 +44,7 @@ import static org.junit.Assert.assertEquals; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithTablePerClassInheritance extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithUnidirectionalOneToOne.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithUnidirectionalOneToOne.java index 55f0619b5f..95b4884d03 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithUnidirectionalOneToOne.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithUnidirectionalOneToOne.java @@ -20,6 +20,8 @@ import javax.persistence.SequenceGenerator; import org.hibernate.cfg.Environment; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -33,6 +35,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-9864") +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingWithUnidirectionalOneToOne extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/SessionJdbcBatchTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/SessionJdbcBatchTest.java index 1c040b04b2..0e4e917d98 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/SessionJdbcBatchTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/SessionJdbcBatchTest.java @@ -15,7 +15,11 @@ import javax.persistence.Id; import org.hibernate.Session; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.DB2Dialect; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; @@ -27,6 +31,7 @@ import static org.mockito.Mockito.verify; /** * @author Vlad Mihalcea */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class SessionJdbcBatchTest extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintHANATest.java b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintHANATest.java index fb8070fef1..ca46fd7ac2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintHANATest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintHANATest.java @@ -26,9 +26,9 @@ import org.hibernate.criterion.Restrictions; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.query.Query; -import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.Test; @@ -38,26 +38,12 @@ import org.junit.Test; @RequiresDialect(AbstractHANADialect.class) public class QueryHintHANATest extends BaseNonConfigCoreFunctionalTestCase { - private PreparedStatementSpyConnectionProvider connectionProvider; + private SQLStatementInterceptor sqlStatementInterceptor; @Override protected void addSettings(Map settings) { settings.put( AvailableSettings.USE_SQL_COMMENTS, "true" ); - settings.put( - org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, - connectionProvider ); - } - - @Override - protected void buildResources() { - connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); - super.buildResources(); - } - - @Override - public void releaseResources() { - super.releaseResources(); - connectionProvider.stop(); + sqlStatementInterceptor = new SQLStatementInterceptor( settings ); } @Override @@ -84,7 +70,7 @@ public class QueryHintHANATest extends BaseNonConfigCoreFunctionalTestCase { @Test public void testQueryHint() { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); doInHibernate( this::sessionFactory, s -> { Query query = s.createQuery( "FROM QueryHintHANATest$Employee e WHERE e.department.name = :departmentName", Employee.class ) @@ -95,11 +81,9 @@ public class QueryHintHANATest extends BaseNonConfigCoreFunctionalTestCase { assertEquals( results.size(), 2 ); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() ); - assertThat( connectionProvider.getPreparedSQLStatements().get( 0 ), containsString( " with hint (NO_CS_JOIN)" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + assertThat( sqlStatementInterceptor.getSqlQueries().get( 0 ), containsString( " with hint (NO_CS_JOIN)" ) ); + sqlStatementInterceptor.clear(); // test multiple hints doInHibernate( this::sessionFactory, s -> { @@ -112,11 +96,10 @@ public class QueryHintHANATest extends BaseNonConfigCoreFunctionalTestCase { assertEquals( results.size(), 2 ); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() ); - assertThat( connectionProvider.getPreparedSQLStatements().get( 0 ), containsString( " with hint (NO_CS_JOIN,OPTIMIZE_METAMODEL)" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + + assertThat( sqlStatementInterceptor.getSqlQueries().get( 0 ), containsString( " with hint (NO_CS_JOIN,OPTIMIZE_METAMODEL)" ) ); + sqlStatementInterceptor.clear(); // ensure the insertion logic can handle a comment appended to the front doInHibernate( this::sessionFactory, s -> { @@ -129,11 +112,10 @@ public class QueryHintHANATest extends BaseNonConfigCoreFunctionalTestCase { assertEquals( results.size(), 2 ); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() ); - assertThat( connectionProvider.getPreparedSQLStatements().get( 0 ), containsString( " with hint (NO_CS_JOIN)" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + + assertThat( sqlStatementInterceptor.getSqlQueries().get( 0 ), containsString( " with hint (NO_CS_JOIN)" ) ); + sqlStatementInterceptor.clear(); // test Criteria doInHibernate( this::sessionFactory, s -> { @@ -145,17 +127,16 @@ public class QueryHintHANATest extends BaseNonConfigCoreFunctionalTestCase { assertEquals( results.size(), 2 ); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() ); - assertThat( connectionProvider.getPreparedSQLStatements().get( 0 ), containsString( " with hint (NO_CS_JOIN)" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + + assertThat( sqlStatementInterceptor.getSqlQueries().get( 0 ), containsString( " with hint (NO_CS_JOIN)" ) ); + sqlStatementInterceptor.clear(); } @Test @TestForIssue(jiraKey = "HHH-12362") public void testQueryHintAndComment() { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); doInHibernate( this::sessionFactory, s -> { Query query = s.createQuery( "FROM QueryHintHANATest$Employee e WHERE e.department.name = :departmentName", Employee.class ) @@ -167,12 +148,11 @@ public class QueryHintHANATest extends BaseNonConfigCoreFunctionalTestCase { assertEquals( results.size(), 2 ); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() ); - assertThat( connectionProvider.getPreparedSQLStatements().get( 0 ), containsString( " with hint (NO_CS_JOIN)" ) ); - assertThat( connectionProvider.getPreparedSQLStatements().get( 0 ), containsString( "/* My_Query */ select" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + + assertThat( sqlStatementInterceptor.getSqlQueries().get( 0 ), containsString( " with hint (NO_CS_JOIN)" ) ); + assertThat( sqlStatementInterceptor.getSqlQueries().get( 0 ), containsString( "/* My_Query */ select" ) ); + sqlStatementInterceptor.clear(); } @Entity diff --git a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintTest.java b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintTest.java index c4ab0767b7..504d3827e1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintTest.java @@ -23,8 +23,8 @@ import org.hibernate.query.Query; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; @@ -37,27 +37,12 @@ import static org.junit.Assert.assertTrue; @RequiresDialect( Oracle8iDialect.class ) public class QueryHintTest extends BaseNonConfigCoreFunctionalTestCase { - private PreparedStatementSpyConnectionProvider connectionProvider; + private SQLStatementInterceptor sqlStatementInterceptor; @Override protected void addSettings(Map settings) { settings.put( AvailableSettings.USE_SQL_COMMENTS, "true" ); - settings.put( - org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, - connectionProvider - ); - } - - @Override - protected void buildResources() { - connectionProvider = new PreparedStatementSpyConnectionProvider( false, false ); - super.buildResources(); - } - - @Override - public void releaseResources() { - super.releaseResources(); - connectionProvider.stop(); + sqlStatementInterceptor = new SQLStatementInterceptor( settings ); } @Override @@ -84,7 +69,7 @@ public class QueryHintTest extends BaseNonConfigCoreFunctionalTestCase { @Test public void testQueryHint() { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); // test Query w/ a simple Oracle optimizer hint doInHibernate( this::sessionFactory, s -> { @@ -96,12 +81,9 @@ public class QueryHintTest extends BaseNonConfigCoreFunctionalTestCase { assertEquals(results.size(), 2); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); - assertTrue( connectionProvider.getPreparedSQLStatements().get( 0 ).contains( "select /*+ ALL_ROWS */" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).contains( "select /*+ ALL_ROWS */" ) ); + sqlStatementInterceptor.clear(); // test multiple hints doInHibernate( this::sessionFactory, s -> { @@ -114,12 +96,9 @@ public class QueryHintTest extends BaseNonConfigCoreFunctionalTestCase { assertEquals(results.size(), 2); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); - assertTrue( connectionProvider.getPreparedSQLStatements().get( 0 ).contains( "select /*+ ALL_ROWS, USE_CONCAT */" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).contains( "select /*+ ALL_ROWS, USE_CONCAT */" ) ); + sqlStatementInterceptor.clear(); // ensure the insertion logic can handle a comment appended to the front doInHibernate( this::sessionFactory, s -> { @@ -132,12 +111,10 @@ public class QueryHintTest extends BaseNonConfigCoreFunctionalTestCase { assertEquals(results.size(), 2); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); - assertTrue( connectionProvider.getPreparedSQLStatements().get( 0 ).contains( "select /*+ ALL_ROWS */" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + + assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).contains( "select /*+ ALL_ROWS */" ) ); + sqlStatementInterceptor.clear(); // test Criteria doInHibernate( this::sessionFactory, s -> { @@ -149,18 +126,16 @@ public class QueryHintTest extends BaseNonConfigCoreFunctionalTestCase { assertEquals(results.size(), 2); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); - assertTrue( connectionProvider.getPreparedSQLStatements().get( 0 ).contains( "select /*+ ALL_ROWS */" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + + assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).contains( "select /*+ ALL_ROWS */" ) ); + sqlStatementInterceptor.clear(); } @Test @TestForIssue( jiraKey = "HHH-12362" ) public void testQueryHintAndComment() { - connectionProvider.clear(); + sqlStatementInterceptor.clear(); doInHibernate( this::sessionFactory, s -> { Query query = s.createQuery( "FROM QueryHintTest$Employee e WHERE e.department.name = :departmentName" ) @@ -172,12 +147,10 @@ public class QueryHintTest extends BaseNonConfigCoreFunctionalTestCase { assertEquals(results.size(), 2); } ); - assertEquals( - 1, - connectionProvider.getPreparedStatements().size() - ); - assertTrue( connectionProvider.getPreparedSQLStatements().get( 0 ).contains( "/* My_Query */ select /*+ ALL_ROWS */" ) ); - connectionProvider.clear(); + sqlStatementInterceptor.assertExecutedCount( 1 ); + + assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).contains( "/* My_Query */ select /*+ ALL_ROWS */" ) ); + sqlStatementInterceptor.clear(); } @Entity diff --git a/hibernate-core/src/test/java/org/hibernate/test/querytimeout/QueryTimeOutTest.java b/hibernate-core/src/test/java/org/hibernate/test/querytimeout/QueryTimeOutTest.java index b33af5bc38..2ef1433cca 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/querytimeout/QueryTimeOutTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/querytimeout/QueryTimeOutTest.java @@ -19,6 +19,8 @@ import org.hibernate.jpa.QueryHints; import org.hibernate.query.NativeQuery; import org.hibernate.query.Query; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -33,6 +35,7 @@ import static org.mockito.Mockito.verify; /** * @author Gail Badner */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase { private static final PreparedStatementSpyConnectionProvider CONNECTION_PROVIDER = new PreparedStatementSpyConnectionProvider( true, false ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/resource/transaction/jdbc/autocommit/AbstractSkipAutoCommitTest.java b/hibernate-core/src/test/java/org/hibernate/test/resource/transaction/jdbc/autocommit/AbstractSkipAutoCommitTest.java index 55379eb980..f7371903ff 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/resource/transaction/jdbc/autocommit/AbstractSkipAutoCommitTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/resource/transaction/jdbc/autocommit/AbstractSkipAutoCommitTest.java @@ -17,6 +17,8 @@ import javax.sql.DataSource; import org.hibernate.cfg.AvailableSettings; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; @@ -30,6 +32,7 @@ import static org.mockito.Mockito.verify; /** * @author Vlad Mihalcea */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public abstract class AbstractSkipAutoCommitTest extends BaseEntityManagerFunctionalTestCase { private PreparedStatementSpyConnectionProvider connectionProvider = diff --git a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimeCustomTimeZoneTest.java b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimeCustomTimeZoneTest.java index bf18cb4db7..6baae104f6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimeCustomTimeZoneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimeCustomTimeZoneTest.java @@ -23,6 +23,8 @@ import javax.persistence.Id; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.MySQL5Dialect; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -42,6 +44,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @SkipForDialect(MySQL5Dialect.class) +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class JdbcTimeCustomTimeZoneTest extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimeDefaultTimeZoneTest.java b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimeDefaultTimeZoneTest.java index 9fe9d9e260..666e3517ca 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimeDefaultTimeZoneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimeDefaultTimeZoneTest.java @@ -16,6 +16,8 @@ import javax.persistence.Id; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; @@ -31,6 +33,8 @@ import static org.mockito.Mockito.verify; /** * @author Vlad Mihalcea */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) + public class JdbcTimeDefaultTimeZoneTest extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampCustomSessionLevelTimeZoneTest.java b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampCustomSessionLevelTimeZoneTest.java index a2b82128c3..95a65a8f9c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampCustomSessionLevelTimeZoneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampCustomSessionLevelTimeZoneTest.java @@ -20,6 +20,8 @@ import javax.persistence.Id; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.MySQL5Dialect; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -39,6 +41,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @SkipForDialect(MySQL5Dialect.class) +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class JdbcTimestampCustomSessionLevelTimeZoneTest extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampCustomTimeZoneTest.java b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampCustomTimeZoneTest.java index d4e7355aae..8db15237d9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampCustomTimeZoneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampCustomTimeZoneTest.java @@ -20,6 +20,8 @@ import javax.persistence.Id; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.MySQL5Dialect; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; @@ -39,6 +41,7 @@ import static org.mockito.Mockito.verify; * @author Vlad Mihalcea */ @SkipForDialect(MySQL5Dialect.class) +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class JdbcTimestampCustomTimeZoneTest extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampDefaultTimeZoneTest.java b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampDefaultTimeZoneTest.java index 25bab7da43..9cfb20911b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampDefaultTimeZoneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/timestamp/JdbcTimestampDefaultTimeZoneTest.java @@ -15,6 +15,8 @@ import javax.persistence.Id; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.Test; @@ -30,6 +32,7 @@ import static org.mockito.Mockito.verify; /** * @author Vlad Mihalcea */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class JdbcTimestampDefaultTimeZoneTest extends BaseNonConfigCoreFunctionalTestCase { diff --git a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPSkipAutoCommitTest.java b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPSkipAutoCommitTest.java index be33188931..491ceb6088 100644 --- a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPSkipAutoCommitTest.java +++ b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPSkipAutoCommitTest.java @@ -15,6 +15,8 @@ import javax.persistence.Id; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.test.util.PreparedStatementSpyConnectionProvider; import org.junit.Test; @@ -29,6 +31,7 @@ import static org.mockito.Mockito.verify; /** * @author Vlad Mihalcea */ +@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) public class HikariCPSkipAutoCommitTest extends BaseCoreFunctionalTestCase { private PreparedStatementSpyConnectionProvider connectionProvider = diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java b/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java index 0c7ba1fa2e..b5b7476630 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java @@ -6,6 +6,7 @@ */ package org.hibernate.testing; +import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; /** @@ -247,4 +248,12 @@ abstract public class DialectChecks { return dialect.forceLobAsLastValue(); } } + + public static class SupportsJdbcDriverProxying implements DialectCheck { + public boolean isMatch(Dialect dialect) { + return !( + dialect instanceof DB2Dialect + ); + } + } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SQLStatementInterceptor.java b/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SQLStatementInterceptor.java index bc37c11b97..43b114f014 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SQLStatementInterceptor.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SQLStatementInterceptor.java @@ -7,16 +7,21 @@ package org.hibernate.testing.jdbc; import java.util.LinkedList; +import java.util.Map; import org.hibernate.boot.SessionFactoryBuilder; +import org.hibernate.cfg.AvailableSettings; import org.hibernate.resource.jdbc.spi.StatementInspector; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * @author Vlad Mihalcea */ public class SQLStatementInterceptor { - private final LinkedList sqlQueries = new LinkedList<>( ); + private final LinkedList sqlQueries = new LinkedList<>(); public SQLStatementInterceptor(SessionFactoryBuilder sessionFactoryBuilder) { sessionFactoryBuilder.applyStatementInspector( (StatementInspector) sql -> { @@ -25,7 +30,26 @@ public class SQLStatementInterceptor { } ); } + public SQLStatementInterceptor(Map settings) { + settings.put( AvailableSettings.STATEMENT_INSPECTOR, (StatementInspector) sql -> { + sqlQueries.add( sql ); + return sql; + } ); + } + public LinkedList getSqlQueries() { return sqlQueries; } + + public void clear() { + sqlQueries.clear(); + } + + public void assertExecuted(String expected) { + assertTrue(sqlQueries.contains( expected )); + } + + public void assertExecutedCount(int expected) { + assertEquals(expected, sqlQueries.size()); + } }