HHH-14439 Backport SQLStatementInterceptor improvements from the master branch

Signed-off-by: Yoann Rodière <yoann@hibernate.org>
This commit is contained in:
Yoann Rodière 2021-03-04 14:14:50 +01:00
parent e3be7e610c
commit 79bc79bb4c
No known key found for this signature in database
GPG Key ID: B8D049359DC35ABC
1 changed files with 20 additions and 0 deletions

View File

@ -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<String> 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();
}
}