Commit 503ddc28 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

1) When upgrading will now check against the proper required version. JM-819

2) ResultSet wasn't being closed in finally block.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5176 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6c0a4fd9
......@@ -139,16 +139,18 @@ public class SchemaManager {
{
int currentVersion = -1;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = con.prepareStatement(CHECK_VERSION);
pstmt.setString(1, schemaKey);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next()) {
currentVersion = rs.getInt(1);
}
rs.close();
}
catch (SQLException sqle) {
DbConnectionManager.closeResultSet(rs);
DbConnectionManager.closeStatement(pstmt);
// Releases of Wildfire before 2.6.0 stored a major and minor version
// number so the normal check for version can fail. Check for the
// version using the old format in that case.
......@@ -158,11 +160,10 @@ public class SchemaManager {
pstmt.close();
}
pstmt = con.prepareStatement(CHECK_VERSION_OLD);
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
if (rs.next()) {
currentVersion = rs.getInt(1);
}
rs.close();
}
catch (SQLException sqle2) {
// The database schema must not be installed.
......@@ -171,14 +172,8 @@ public class SchemaManager {
}
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
DbConnectionManager.closeResultSet(rs);
DbConnectionManager.closeStatement(pstmt);
}
// If already up to date, return.
if (currentVersion == requiredVersion) {
......@@ -237,7 +232,7 @@ public class SchemaManager {
}
// Run all upgrade scripts until we're up to the latest schema.
for (int i = currentVersion + 1; i <= DATABASE_VERSION; i++) {
for (int i = currentVersion + 1; i <= requiredVersion; i++) {
InputStream resource = getUpgradeResource(resourceLoader, i, schemaKey);
if(resource == null) {
continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment