Polish DataSourceHealthIndicator

See gh-20367
pull/20407/head
Johnny Lim 5 years ago committed by Stephane Nicoll
parent de062b4f52
commit bd08b4d91c

@ -105,25 +105,17 @@ public class DataSourceHealthIndicator extends AbstractHealthIndicator implement
builder.up().withDetail("database", getProduct()); builder.up().withDetail("database", getProduct());
String validationQuery = this.query; String validationQuery = this.query;
if (StringUtils.hasText(validationQuery)) { if (StringUtils.hasText(validationQuery)) {
try { builder.withDetail("validationQuery", validationQuery);
// Avoid calling getObject as it breaks MySQL on Java 7 // Avoid calling getObject as it breaks MySQL on Java 7 and later
List<Object> results = this.jdbcTemplate.query(validationQuery, new SingleColumnRowMapper()); List<Object> results = this.jdbcTemplate.query(validationQuery, new SingleColumnRowMapper());
Object result = DataAccessUtils.requiredSingleResult(results); Object result = DataAccessUtils.requiredSingleResult(results);
builder.withDetail("result", result); builder.withDetail("result", result);
} }
finally {
builder.withDetail("validationQuery", validationQuery);
}
}
else { else {
try { builder.withDetail("validationQuery", "isValid()");
boolean valid = isConnectionValid(); boolean valid = isConnectionValid();
builder.status((valid) ? Status.UP : Status.DOWN); builder.status((valid) ? Status.UP : Status.DOWN);
} }
finally {
builder.withDetail("validationQuery", "isValid()");
}
}
} }
private String getProduct() { private String getProduct() {

Loading…
Cancel
Save