Skip to content

Commit b807640

Browse files
committed
minor cleanup, modernizing for J21
1 parent 317f05d commit b807640

33 files changed

Lines changed: 142 additions & 200 deletions

bootique-jdbc-hikaricp-instrumented/src/main/java/io/bootique/jdbc/instrumented/hikaricp/HikariCPInstrumentedDataSourceFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected ManagedDataSourceStarter createDataSourceStarter(
6060
Consumer<DataSource> shutdown) {
6161

6262
HealthCheckGroup healthChecks = healthChecks(dataSourceName);
63-
return new InstrumentedManagedDataSourceStarter(() -> getJdbcUrl(), startup, shutdown, healthChecks);
63+
return new InstrumentedManagedDataSourceStarter(this::getJdbcUrl, startup, shutdown, healthChecks);
6464
}
6565

6666
@BQConfigProperty

bootique-jdbc-hikaricp-instrumented/src/main/java/io/bootique/jdbc/instrumented/hikaricp/HikariCPMetricsInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class HikariCPMetricsInitializer implements DataSourceListener {
3434

3535
private static final Logger LOGGER = LoggerFactory.getLogger(HikariCPMetricsInitializer.class);
3636

37-
private MetricRegistry metricRegistry;
37+
private final MetricRegistry metricRegistry;
3838

3939
public HikariCPMetricsInitializer(MetricRegistry metricRegistry) {
4040
this.metricRegistry = metricRegistry;

bootique-jdbc-hikaricp-instrumented/src/main/java/io/bootique/jdbc/instrumented/hikaricp/healthcheck/HikariCPConnectivityCheck.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ public HealthCheckOutcome check() {
6868

6969
HealthCheckOutcome warningOutcome = checkThreshold(ThresholdType.WARNING, HealthCheckOutcome::warning);
7070

71-
switch (warningOutcome.getStatus()) {
72-
case WARNING:
73-
return warningOutcome;
74-
case UNKNOWN:
75-
return checkThreshold(ThresholdType.CRITICAL, HealthCheckOutcome::critical);
76-
}
71+
return switch (warningOutcome.getStatus()) {
72+
case WARNING -> warningOutcome;
73+
case UNKNOWN -> checkThreshold(ThresholdType.CRITICAL, HealthCheckOutcome::critical);
74+
default -> HealthCheckOutcome.ok();
75+
};
7776

78-
return HealthCheckOutcome.ok();
7977
}
8078

8179
protected HealthCheckOutcome checkThreshold(ThresholdType type, Function<SQLException, HealthCheckOutcome> onFailure) {

bootique-jdbc-hikaricp-instrumented/src/main/java/io/bootique/jdbc/instrumented/hikaricp/healthcheck/HikariCPConnectivityCheckFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class HikariCPConnectivityCheckFactory {
3030

31-
private DurationRangeFactory thresholdsFactory;
31+
private final DurationRangeFactory thresholdsFactory;
3232

3333
HikariCPConnectivityCheckFactory(DurationRangeFactory thresholdsFactory) {
3434
this.thresholdsFactory = thresholdsFactory;

bootique-jdbc-hikaricp-instrumented/src/main/java/io/bootique/jdbc/instrumented/hikaricp/healthcheck/HikariCPHealthChecks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
public class HikariCPHealthChecks implements HealthCheckGroup {
3535

36-
private Map<String, ManagedDataSourceStarter> starters;
36+
private final Map<String, ManagedDataSourceStarter> starters;
3737

3838
public HikariCPHealthChecks(Map<String, ManagedDataSourceStarter> starters) {
3939
this.starters = starters;

bootique-jdbc-hikaricp-instrumented/src/main/java/io/bootique/jdbc/instrumented/hikaricp/healthcheck/Wait99PercentCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
/**
3030
* The health check checks that, on average, 99% of all calls to {@code getConnection()} obtain a
31-
* {@link java.sql.Connection} within a specified number of milliseconds.
31+
* {@link java.sql.Connection} within a specified number of milliseconds.
3232
*/
3333
public class Wait99PercentCheck extends ValueRangeCheck<Duration> {
3434

bootique-jdbc-hikaricp-instrumented/src/main/java/io/bootique/jdbc/instrumented/hikaricp/healthcheck/Wait99PercentCheckFactory.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
class Wait99PercentCheckFactory {
3535

36-
private DurationRangeFactory thresholdsFactory;
36+
private final DurationRangeFactory thresholdsFactory;
3737

3838
public Wait99PercentCheckFactory(DurationRangeFactory thresholdsFactory) {
3939
this.thresholdsFactory = thresholdsFactory;
@@ -73,13 +73,10 @@ private Duration readConnection99Percent(MetricRegistry registry, String metricN
7373
private Timer findTimer(MetricRegistry registry, String name) {
7474

7575
Collection<Timer> timers = registry.getTimers((n, m) -> name.equals(n)).values();
76-
switch (timers.size()) {
77-
case 0:
78-
throw new IllegalArgumentException("Timer not found: " + name);
79-
case 1:
80-
return timers.iterator().next();
81-
default:
82-
throw new IllegalArgumentException("More than one Timer matching the name: " + name);
83-
}
76+
return switch (timers.size()) {
77+
case 0 -> throw new IllegalArgumentException("Timer not found: " + name);
78+
case 1 -> timers.iterator().next();
79+
default -> throw new IllegalArgumentException("More than one Timer matching the name: " + name);
80+
};
8481
}
8582
}

bootique-jdbc-hikaricp-instrumented/src/main/java/io/bootique/jdbc/instrumented/hikaricp/managed/InstrumentedManagedDataSourceStarter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
public class InstrumentedManagedDataSourceStarter extends ManagedDataSourceStarter {
3030

31-
private HealthCheckGroup healthChecks;
31+
private final HealthCheckGroup healthChecks;
3232

3333
public InstrumentedManagedDataSourceStarter(
3434
Supplier<String> url,

bootique-jdbc-hikaricp/src/main/java/io/bootique/jdbc/hikaricp/HikariCPManagedDataSourceFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class HikariCPManagedDataSourceFactory implements ManagedDataSourceFactor
6161
private long connectionTimeout;
6262
private String dataSourceClassName;
6363
private String dataSourceJNDI;
64-
private Properties dataSourceProperties;
64+
private final Properties dataSourceProperties;
6565
private String driverClassName;
6666
private long idleTimeout;
6767
private long initializationFailTimeout;
@@ -338,7 +338,7 @@ protected HikariConfig toConfiguration(String dataSourceName) {
338338

339339
private static class HikariThreadFactory implements ThreadFactory {
340340

341-
private AtomicInteger counter = new AtomicInteger();
341+
private final AtomicInteger counter = new AtomicInteger();
342342

343343
@Override
344344
public Thread newThread(Runnable r) {

bootique-jdbc-junit5/src/main/java/io/bootique/jdbc/junit5/connector/ArrayReader.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
public abstract class ArrayReader implements RowReader {
3535

36-
public static <T> RowReader create(DbColumnMetadata... columns) {
36+
public static RowReader create(DbColumnMetadata... columns) {
3737

3838
if (columns.length == 0) {
3939
return ResultSetRowReader.instance;
@@ -50,19 +50,17 @@ public static <T> RowReader create(DbColumnMetadata... columns) {
5050
static ColumnReader forJdbcType(int type, int pos) {
5151
// TODO: add conversions to java.time types?
5252

53-
switch (type) {
54-
// only care about types requiring special handling.. Let the driver handle the rest via "getObject"
55-
case Types.TIME:
56-
// MySQL 8 requires a Calendar instance to save local time without undesired TZ conversion.
57-
// Other DBs work fine with or without the calendar
58-
return rs -> rs.getTime(pos, Calendar.getInstance());
59-
case Types.TIMESTAMP:
60-
// MySQL 8 requires a Calendar instance to save local time without undesired TZ conversion.
61-
// Other DBs work fine with or without the calendar
62-
return rs -> rs.getTimestamp(pos, Calendar.getInstance());
63-
default:
64-
return rs -> rs.getObject(pos);
65-
}
53+
return switch (type) {
54+
// We only care about types requiring special handling. Let the driver handle the rest via "getObject"
55+
56+
// MySQL 8 requires a Calendar instance to save local time without undesired TZ conversion.
57+
// Other DBs work fine with or without the calendar
58+
case Types.TIME -> rs -> rs.getTime(pos, Calendar.getInstance());
59+
// MySQL 8 requires a Calendar instance to save local time without undesired TZ conversion.
60+
// Other DBs work fine with or without the calendar
61+
case Types.TIMESTAMP -> rs -> rs.getTimestamp(pos, Calendar.getInstance());
62+
default -> rs -> rs.getObject(pos);
63+
};
6664
}
6765

6866
protected ArrayReader() {

0 commit comments

Comments
 (0)