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 { ...@@ -139,16 +139,18 @@ public class SchemaManager {
{ {
int currentVersion = -1; int currentVersion = -1;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try { try {
pstmt = con.prepareStatement(CHECK_VERSION); pstmt = con.prepareStatement(CHECK_VERSION);
pstmt.setString(1, schemaKey); pstmt.setString(1, schemaKey);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
currentVersion = rs.getInt(1); currentVersion = rs.getInt(1);
} }
rs.close();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
DbConnectionManager.closeResultSet(rs);
DbConnectionManager.closeStatement(pstmt);
// Releases of Wildfire before 2.6.0 stored a major and minor version // 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 // number so the normal check for version can fail. Check for the
// version using the old format in that case. // version using the old format in that case.
...@@ -158,11 +160,10 @@ public class SchemaManager { ...@@ -158,11 +160,10 @@ public class SchemaManager {
pstmt.close(); pstmt.close();
} }
pstmt = con.prepareStatement(CHECK_VERSION_OLD); pstmt = con.prepareStatement(CHECK_VERSION_OLD);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
currentVersion = rs.getInt(1); currentVersion = rs.getInt(1);
} }
rs.close();
} }
catch (SQLException sqle2) { catch (SQLException sqle2) {
// The database schema must not be installed. // The database schema must not be installed.
...@@ -171,14 +172,8 @@ public class SchemaManager { ...@@ -171,14 +172,8 @@ public class SchemaManager {
} }
} }
finally { finally {
try { DbConnectionManager.closeResultSet(rs);
if (pstmt != null) { DbConnectionManager.closeStatement(pstmt);
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
} }
// If already up to date, return. // If already up to date, return.
if (currentVersion == requiredVersion) { if (currentVersion == requiredVersion) {
...@@ -237,7 +232,7 @@ public class SchemaManager { ...@@ -237,7 +232,7 @@ public class SchemaManager {
} }
// Run all upgrade scripts until we're up to the latest schema. // 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); InputStream resource = getUpgradeResource(resourceLoader, i, schemaKey);
if(resource == null) { if(resource == null) {
continue; 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