Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -72,7 +72,7 @@ public class DatabaseStartupValidator implements InitializingBean {
|
||||
|
||||
/**
|
||||
* Set the interval between validation runs (in seconds).
|
||||
* Default is 1.
|
||||
* Default is {@value #DEFAULT_INTERVAL}.
|
||||
*/
|
||||
public void setInterval(int interval) {
|
||||
this.interval = interval;
|
||||
@@ -80,7 +80,7 @@ public class DatabaseStartupValidator implements InitializingBean {
|
||||
|
||||
/**
|
||||
* Set the timeout (in seconds) after which a fatal exception
|
||||
* will be thrown. Default is 60.
|
||||
* will be thrown. Default is {@value #DEFAULT_TIMEOUT}.
|
||||
*/
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -94,11 +94,12 @@ public class DatabaseStartupValidator implements InitializingBean {
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (this.dataSource == null) {
|
||||
throw new IllegalArgumentException("dataSource is required");
|
||||
DataSource dataSource = this.dataSource;
|
||||
if (dataSource == null) {
|
||||
throw new IllegalArgumentException("Property 'dataSource' is required");
|
||||
}
|
||||
if (this.validationQuery == null) {
|
||||
throw new IllegalArgumentException("validationQuery is required");
|
||||
throw new IllegalArgumentException("Property 'validationQuery' is required");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -111,18 +112,22 @@ public class DatabaseStartupValidator implements InitializingBean {
|
||||
Connection con = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
con = this.dataSource.getConnection();
|
||||
con = dataSource.getConnection();
|
||||
stmt = con.createStatement();
|
||||
stmt.execute(this.validationQuery);
|
||||
validated = true;
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
latestEx = ex;
|
||||
logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex);
|
||||
float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000;
|
||||
if (rest > this.interval) {
|
||||
logger.warn("Database has not started up yet - retrying in " + this.interval +
|
||||
" seconds (timeout in " + rest + " seconds)");
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex);
|
||||
}
|
||||
if (logger.isWarnEnabled()) {
|
||||
float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000;
|
||||
if (rest > this.interval) {
|
||||
logger.warn("Database has not started up yet - retrying in " + this.interval +
|
||||
" seconds (timeout in " + rest + " seconds)");
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
@@ -140,8 +145,8 @@ public class DatabaseStartupValidator implements InitializingBean {
|
||||
"Database has not started up within " + this.timeout + " seconds", latestEx);
|
||||
}
|
||||
|
||||
float duration = (System.currentTimeMillis() - beginTime) / 1000;
|
||||
if (logger.isInfoEnabled()) {
|
||||
float duration = ((float) (System.currentTimeMillis() - beginTime)) / 1000;
|
||||
logger.info("Database startup detected after " + duration + " seconds");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user