Polishing

This commit is contained in:
Juergen Hoeller
2018-07-26 15:55:15 +02:00
parent 79936d98de
commit 5da58393c1
4 changed files with 26 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,8 +42,14 @@ import org.springframework.lang.Nullable;
*/
public class DatabaseStartupValidator implements InitializingBean {
/**
* The default interval.
*/
public static final int DEFAULT_INTERVAL = 1;
/**
* The default timeout.
*/
public static final int DEFAULT_TIMEOUT = 60;
@@ -98,8 +104,7 @@ public class DatabaseStartupValidator implements InitializingBean {
*/
@Override
public void afterPropertiesSet() {
DataSource dataSource = this.dataSource;
if (dataSource == null) {
if (this.dataSource == null) {
throw new IllegalArgumentException("Property 'dataSource' is required");
}
if (this.validationQuery == null) {
@@ -116,10 +121,10 @@ public class DatabaseStartupValidator implements InitializingBean {
Connection con = null;
Statement stmt = null;
try {
con = dataSource.getConnection();
con = this.dataSource.getConnection();
if (con == null) {
throw new CannotGetJdbcConnectionException("Failed to execute validation query: " +
"DataSource returned null from getConnection(): " + dataSource);
"DataSource returned null from getConnection(): " + this.dataSource);
}
stmt = con.createStatement();
stmt.execute(this.validationQuery);
@@ -144,7 +149,7 @@ public class DatabaseStartupValidator implements InitializingBean {
}
if (!validated) {
Thread.sleep(TimeUnit.SECONDS.toMillis(this.interval));
TimeUnit.SECONDS.sleep(this.interval);
}
}