1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.web.health;
17
18 import com.codahale.metrics.Gauge;
19 import com.codahale.metrics.health.HealthCheck;
20 import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform;
21 import org.springframework.jdbc.core.JdbcTemplate;
22
23 import javax.sql.DataSource;
24
25
26
27
28
29
30
31 public class DatabaseConnectionHealthGauge extends HealthCheck implements Gauge<Boolean> {
32
33 private final DataSource dataSource;
34 private final DatabasePlatform platform;
35
36 public DatabaseConnectionHealthGauge(DataSource dataSource, DatabasePlatform platform) {
37 this.dataSource = dataSource;
38 this.platform = platform;
39 }
40
41 @Override
42 public Boolean getValue() {
43 Result result = execute();
44 return result.isHealthy();
45 }
46
47 @Override
48 protected Result check() throws Exception {
49 JdbcTemplate template = new JdbcTemplate(dataSource);
50 template.execute(platform.getValidationQuery());
51
52 return Result.healthy();
53 }
54
55 }