Merge pull request #6524 from APriestman/fixHealthMontiorUpgrade2

Fix health monitor upgrade code 2
This commit is contained in:
Richard Cordovano 2020-12-04 14:48:39 -05:00 committed by GitHub
commit 291a476be8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -183,6 +183,7 @@ public final class HealthMonitor implements PropertyChangeListener {
if (conn == null) {
throw new HealthMonitorException("Error getting database connection");
}
ResultSet resultSet = null;
try (Statement statement = conn.createStatement()) {
conn.setAutoCommit(false);
@ -210,8 +211,13 @@ public final class HealthMonitor implements PropertyChangeListener {
// Changes: username added to user_data table
if (currentSchema.compareTo(new CaseDbSchemaVersionNumber(1, 2)) < 0) {
// Add the user_data table
statement.execute("ALTER TABLE user_data ADD COLUMN IF NOT EXISTS username text");
resultSet = statement.executeQuery("SELECT column_name " +
"FROM information_schema.columns " +
"WHERE table_name='user_data' and column_name='username'");
if (! resultSet.next()) {
// Add the user_data table
statement.execute("ALTER TABLE user_data ADD COLUMN username text");
}
}
// Update the schema version
@ -228,6 +234,13 @@ public final class HealthMonitor implements PropertyChangeListener {
}
throw new HealthMonitorException("Error upgrading database", ex);
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException ex2) {
logger.log(Level.SEVERE, "Error closing result set");
}
}
try {
conn.close();
} catch (SQLException ex) {
@ -971,7 +984,7 @@ public final class HealthMonitor implements PropertyChangeListener {
getInstance().writeCurrentStateToDatabase();
}
} catch (HealthMonitorException ex) {
logger.log(Level.SEVERE, "Error performing periodic task", ex); //NON-NLS
logger.log(Level.SEVERE, "Error recording health monitor metrics", ex); //NON-NLS
}
}