HHH-14875 Slow query log seems to be missing in Hibernate 6.0.0.Beta1
This commit is contained in:
parent
dd36e349b1
commit
9c2c7e13dd
|
@ -18,6 +18,8 @@ import org.hibernate.Session;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.pagination.LimitHandler;
|
import org.hibernate.dialect.pagination.LimitHandler;
|
||||||
import org.hibernate.dialect.pagination.NoopLimitHandler;
|
import org.hibernate.dialect.pagination.NoopLimitHandler;
|
||||||
|
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
|
||||||
|
import org.hibernate.engine.spi.SessionEventListenerManager;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
@ -42,6 +44,7 @@ public class DeferredResultSetAccess extends AbstractResultSetAccess {
|
||||||
private final JdbcParameterBindings jdbcParameterBindings;
|
private final JdbcParameterBindings jdbcParameterBindings;
|
||||||
private final ExecutionContext executionContext;
|
private final ExecutionContext executionContext;
|
||||||
private final Function<String, PreparedStatement> statementCreator;
|
private final Function<String, PreparedStatement> statementCreator;
|
||||||
|
private final SqlStatementLogger sqlStatementLogger;
|
||||||
private final String finalSql;
|
private final String finalSql;
|
||||||
private final Limit limit;
|
private final Limit limit;
|
||||||
private final LimitHandler limitHandler;
|
private final LimitHandler limitHandler;
|
||||||
|
@ -60,6 +63,8 @@ public class DeferredResultSetAccess extends AbstractResultSetAccess {
|
||||||
this.executionContext = executionContext;
|
this.executionContext = executionContext;
|
||||||
this.jdbcSelect = jdbcSelect;
|
this.jdbcSelect = jdbcSelect;
|
||||||
this.statementCreator = statementCreator;
|
this.statementCreator = statementCreator;
|
||||||
|
this.sqlStatementLogger = executionContext.getSession().getJdbcServices().getSqlStatementLogger();
|
||||||
|
|
||||||
final QueryOptions queryOptions = executionContext.getQueryOptions();
|
final QueryOptions queryOptions = executionContext.getQueryOptions();
|
||||||
if ( queryOptions == null ) {
|
if ( queryOptions == null ) {
|
||||||
finalSql = jdbcSelect.getSql();
|
finalSql = jdbcSelect.getSql();
|
||||||
|
@ -200,12 +205,20 @@ public class DeferredResultSetAccess extends AbstractResultSetAccess {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
executionContext.getSession().getEventListenerManager().jdbcExecuteStatementStart();
|
final SessionEventListenerManager eventListenerManager = executionContext.getSession()
|
||||||
|
.getEventListenerManager();
|
||||||
|
|
||||||
|
long executeStartNanos = 0;
|
||||||
|
if ( this.sqlStatementLogger.getLogSlowQuery() > 0 ) {
|
||||||
|
executeStartNanos = System.nanoTime();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
eventListenerManager.jdbcExecuteStatementStart();
|
||||||
resultSet = preparedStatement.executeQuery();
|
resultSet = preparedStatement.executeQuery();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
executionContext.getSession().getEventListenerManager().jdbcExecuteStatementEnd();
|
eventListenerManager.jdbcExecuteStatementEnd();
|
||||||
|
sqlStatementLogger.logSlowQuery( preparedStatement, executeStartNanos );
|
||||||
}
|
}
|
||||||
|
|
||||||
// For dialects that don't support an offset clause
|
// For dialects that don't support an offset clause
|
||||||
|
|
Loading…
Reference in New Issue