From 79bc79bb4c6b127b4d5ba8c71b4c001615c433b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Thu, 4 Mar 2021 14:14:50 +0100 Subject: [PATCH] HHH-14439 Backport SQLStatementInterceptor improvements from the master branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yoann Rodière --- .../testing/jdbc/SQLStatementInterceptor.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 43b114f014..9955a8acc8 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 @@ -10,7 +10,9 @@ import java.util.LinkedList; import java.util.Map; import org.hibernate.boot.SessionFactoryBuilder; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.resource.jdbc.spi.StatementInspector; import static org.junit.Assert.assertEquals; @@ -37,6 +39,20 @@ public class SQLStatementInterceptor { } ); } + public SQLStatementInterceptor(StandardServiceRegistryBuilder ssrb) { + ssrb.applySetting( + AvailableSettings.STATEMENT_INSPECTOR, + (StatementInspector) sql -> { + sqlQueries.add( sql ); + return sql; + } + ); + } + + public SQLStatementInterceptor(Configuration configuration) { + this( configuration.getProperties() ); + } + public LinkedList getSqlQueries() { return sqlQueries; } @@ -52,4 +68,8 @@ public class SQLStatementInterceptor { public void assertExecutedCount(int expected) { assertEquals(expected, sqlQueries.size()); } + + public int getQueryCount() { + return sqlQueries.size(); + } }