Skip to content

Commit

Permalink
Merge pull request quarkusio#19205 from geoand/quarkusio#18634
Browse files Browse the repository at this point in the history
Add Configuration option to enable Hibernate's LOG_SLOW_QUERY feature
  • Loading branch information
geoand authored Aug 4, 2021
2 parents 20f3afc + 9ea1faf commit 89f260a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,34 +366,6 @@ public boolean isAnyPropertySet() {
}
}

@ConfigGroup
public static class HibernateOrmConfigPersistenceUnitLog {

/**
* Show SQL logs and format them nicely.
* <p>
* Setting it to true is obviously not recommended in production.
*/
@ConfigItem
public boolean sql;

/**
* Format the SQL logs if SQL log is enabled
*/
@ConfigItem(defaultValue = "true")
public boolean formatSql;

/**
* Whether JDBC warnings should be collected and logged.
*/
@ConfigItem(defaultValueDocumentation = "depends on dialect")
public Optional<Boolean> jdbcWarnings;

public boolean isAnyPropertySet() {
return sql || !formatSql || jdbcWarnings.isPresent();
}
}

@ConfigGroup
public static class HibernateOrmConfigPersistenceUnitCache {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ private static void injectRuntimeConfiguration(String persistenceUnitName,
runtimeSettingsBuilder.put(AvailableSettings.LOG_JDBC_WARNINGS,
persistenceUnitConfig.log.jdbcWarnings.get().toString());
}

if (persistenceUnitConfig.log.queriesSlowerThanMs.isPresent()) {
runtimeSettingsBuilder.put(AvailableSettings.LOG_SLOW_QUERY,
persistenceUnitConfig.log.queriesSlowerThanMs.get());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,14 @@ public static class HibernateOrmConfigPersistenceUnitLog {
@ConfigItem(defaultValueDocumentation = "depends on dialect")
public Optional<Boolean> jdbcWarnings = Optional.empty();

/**
* If set, Hibernate will log queries that took more than specified number of milliseconds to execute.
*/
@ConfigItem
public Optional<Long> queriesSlowerThanMs;

public boolean isAnyPropertySet() {
return sql || !formatSql || jdbcWarnings.isPresent();
return sql || !formatSql || jdbcWarnings.isPresent() || queriesSlowerThanMs.isPresent();
}
}

Expand Down

0 comments on commit 89f260a

Please sign in to comment.