GuardAgainstUnmigratedRDB should behave well if the database driver is not found.
This commit is contained in:
parent
bd06c0cfbe
commit
8591894262
1 changed files with 27 additions and 16 deletions
|
@ -29,6 +29,9 @@ public class GuardAgainstUnmigratedRDB implements ServletContextListener {
|
||||||
private static final String PROPERTY_DB_URL = "VitroConnection.DataSource.url";
|
private static final String PROPERTY_DB_URL = "VitroConnection.DataSource.url";
|
||||||
private static final String PROPERTY_DB_USERNAME = "VitroConnection.DataSource.username";
|
private static final String PROPERTY_DB_USERNAME = "VitroConnection.DataSource.username";
|
||||||
private static final String PROPERTY_DB_PASSWORD = "VitroConnection.DataSource.password";
|
private static final String PROPERTY_DB_PASSWORD = "VitroConnection.DataSource.password";
|
||||||
|
private static final String PROPERTY_DB_DRIVER_CLASS_NAME = "VitroConnection.DataSource.driver";
|
||||||
|
|
||||||
|
private static final String DEFAULT_DRIVER_CLASS = "com.mysql.jdbc.Driver";
|
||||||
|
|
||||||
private static final String TABLE_NAME_RDB = "jena_graph";
|
private static final String TABLE_NAME_RDB = "jena_graph";
|
||||||
private static final String TABLE_NAME_CONVERSION = "vivo_rdb_migrated";
|
private static final String TABLE_NAME_CONVERSION = "vivo_rdb_migrated";
|
||||||
|
@ -54,13 +57,18 @@ public class GuardAgainstUnmigratedRDB implements ServletContextListener {
|
||||||
String url = props.getProperty(PROPERTY_DB_URL);
|
String url = props.getProperty(PROPERTY_DB_URL);
|
||||||
String username = props.getProperty(PROPERTY_DB_USERNAME);
|
String username = props.getProperty(PROPERTY_DB_USERNAME);
|
||||||
String password = props.getProperty(PROPERTY_DB_PASSWORD);
|
String password = props.getProperty(PROPERTY_DB_PASSWORD);
|
||||||
|
String driverClassName = props.getProperty(
|
||||||
|
PROPERTY_DB_DRIVER_CLASS_NAME, DEFAULT_DRIVER_CLASS);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName(driverClassName).newInstance();
|
||||||
|
|
||||||
Properties connectionProps = new Properties();
|
Properties connectionProps = new Properties();
|
||||||
connectionProps.put("user", username);
|
connectionProps.put("user", username);
|
||||||
connectionProps.put("password", password);
|
connectionProps.put("password", password);
|
||||||
|
|
||||||
try (Connection conn = DriverManager
|
try (Connection conn = DriverManager.getConnection(url,
|
||||||
.getConnection(url, connectionProps)) {
|
connectionProps)) {
|
||||||
boolean hasRdb = checkForRdbTables(conn);
|
boolean hasRdb = checkForRdbTables(conn);
|
||||||
boolean hasBeenConverted = checkForConversionTable(conn);
|
boolean hasBeenConverted = checkForConversionTable(conn);
|
||||||
if (hasRdb && !hasBeenConverted) {
|
if (hasRdb && !hasBeenConverted) {
|
||||||
|
@ -69,10 +77,13 @@ public class GuardAgainstUnmigratedRDB implements ServletContextListener {
|
||||||
ss.fatal(this, String.format(MESSAGE_WHAT_NOW, url));
|
ss.fatal(this, String.format(MESSAGE_WHAT_NOW, url));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
ss.fatal(this, "Can't connect to the database: " + PROPERTY_DB_URL
|
ss.fatal(this, "Can't connect to the database: "
|
||||||
+ "='" + url + "', " + PROPERTY_DB_USERNAME + "='"
|
+ PROPERTY_DB_URL + "='" + url + "', "
|
||||||
+ username + "'", e);
|
+ PROPERTY_DB_USERNAME + "='" + username + "'", e);
|
||||||
return;
|
}
|
||||||
|
} catch (InstantiationException | IllegalAccessException
|
||||||
|
| ClassNotFoundException e) {
|
||||||
|
ss.fatal(this, "Can't load the database driver: " + driverClassName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue