HHH-16909 make setting for slow query logging obey our naming conventions
This commit is contained in:
parent
94b33e6198
commit
33700597af
|
@ -2267,6 +2267,15 @@ public interface AvailableSettings {
|
||||||
*/
|
*/
|
||||||
String GENERATE_STATISTICS = "hibernate.generate_statistics";
|
String GENERATE_STATISTICS = "hibernate.generate_statistics";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies a duration in milliseconds defining the minimum query execution time that
|
||||||
|
* characterizes a "slow" query. Any SQL query which takes longer than this amount of
|
||||||
|
* time to execute will be logged.
|
||||||
|
* <p>
|
||||||
|
* A value of {@code 0}, the default, disables logging of "slow" queries.
|
||||||
|
*/
|
||||||
|
String LOG_SLOW_QUERY = "hibernate.log_slow_query";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls whether {@linkplain org.hibernate.stat.SessionStatistics session metrics}
|
* Controls whether {@linkplain org.hibernate.stat.SessionStatistics session metrics}
|
||||||
* should be {@linkplain org.hibernate.engine.internal.StatisticalLoggingSessionEventListener
|
* should be {@linkplain org.hibernate.engine.internal.StatisticalLoggingSessionEventListener
|
||||||
|
@ -2277,15 +2286,6 @@ public interface AvailableSettings {
|
||||||
*/
|
*/
|
||||||
String LOG_SESSION_METRICS = "hibernate.session.events.log";
|
String LOG_SESSION_METRICS = "hibernate.session.events.log";
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies a duration in milliseconds defining the minimum query execution time that
|
|
||||||
* characterizes a "slow" query. Any SQL query which takes longer than this amount of
|
|
||||||
* time to execute will be logged.
|
|
||||||
* <p>
|
|
||||||
* A value of {@code 0}, the default, disables logging of "slow" queries.
|
|
||||||
*/
|
|
||||||
String LOG_SLOW_QUERY = "hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a default {@link org.hibernate.SessionEventListener} to be applied to
|
* Defines a default {@link org.hibernate.SessionEventListener} to be applied to
|
||||||
* newly-opened {@link org.hibernate.Session}s.
|
* newly-opened {@link org.hibernate.Session}s.
|
||||||
|
|
|
@ -9,27 +9,38 @@ package org.hibernate.engine.jdbc.internal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||||
import org.hibernate.cfg.Environment;
|
|
||||||
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
|
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
|
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.FORMAT_SQL;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.HIGHLIGHT_SQL;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.LOG_SLOW_QUERY;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.SHOW_SQL;
|
||||||
|
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
|
||||||
|
import static org.hibernate.internal.util.config.ConfigurationHelper.getLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link SqlStatementLogger} is accessible via {@link org.hibernate.engine.jdbc.spi.JdbcServices},
|
* The {@link SqlStatementLogger} is accessible via {@link org.hibernate.engine.jdbc.spi.JdbcServices},
|
||||||
* but during service initialization, it might be needed before the {@code JdbcServices} service is initialized.
|
* but during service initialization, it might be needed before the {@code JdbcServices} service is
|
||||||
*
|
* initialized.
|
||||||
* For Hibernate Reactive
|
|
||||||
*/
|
*/
|
||||||
public class SqlStatementLoggerInitiator implements StandardServiceInitiator<SqlStatementLogger> {
|
public class SqlStatementLoggerInitiator implements StandardServiceInitiator<SqlStatementLogger> {
|
||||||
|
|
||||||
|
// this deprecated property name never respected our conventions
|
||||||
|
private static final String OLD_LOG_SLOW_QUERY = "hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS";
|
||||||
|
|
||||||
public static final SqlStatementLoggerInitiator INSTANCE = new SqlStatementLoggerInitiator();
|
public static final SqlStatementLoggerInitiator INSTANCE = new SqlStatementLoggerInitiator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SqlStatementLogger initiateService(Map<String, Object> configValues, ServiceRegistryImplementor registry) {
|
public SqlStatementLogger initiateService(Map<String, Object> configValues, ServiceRegistryImplementor registry) {
|
||||||
final boolean showSQL = ConfigurationHelper.getBoolean( Environment.SHOW_SQL, configValues );
|
final boolean showSQL = getBoolean( SHOW_SQL, configValues );
|
||||||
final boolean formatSQL = ConfigurationHelper.getBoolean( Environment.FORMAT_SQL, configValues );
|
final boolean formatSQL = getBoolean( FORMAT_SQL, configValues );
|
||||||
final boolean highlightSQL = ConfigurationHelper.getBoolean( Environment.HIGHLIGHT_SQL, configValues );
|
final boolean highlightSQL = getBoolean( HIGHLIGHT_SQL, configValues );
|
||||||
final long logSlowQuery = ConfigurationHelper.getLong( Environment.LOG_SLOW_QUERY, configValues, 0 );
|
|
||||||
|
long logSlowQuery = getLong( LOG_SLOW_QUERY, configValues, -2 );
|
||||||
|
if ( logSlowQuery == -2 ) {
|
||||||
|
logSlowQuery = getLong( OLD_LOG_SLOW_QUERY, configValues, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
return new SqlStatementLogger( showSQL, formatSQL, highlightSQL, logSlowQuery );
|
return new SqlStatementLogger( showSQL, formatSQL, highlightSQL, logSlowQuery );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue