mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-25 09:31:46 +01:00
Use try-with-resources to close ResultSet in SQLite handler.
This commit is contained in:
parent
72bbac2594
commit
5e1f095b9d
@ -48,7 +48,21 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
|
||||
// SQLite does not have a rename if exists command so we have to manually check if the old table exists
|
||||
String sql = "SELECT EXISTS (SELECT 1 FROM sqlite_master WHERE type='table' AND name='" + getSqlConfig().getOldTableName() + "' COLLATE NOCASE)";
|
||||
try (PreparedStatement pstmt = getConnection().prepareStatement(sql)) {
|
||||
ResultSet resultSet = pstmt.executeQuery();
|
||||
rename(pstmt);
|
||||
} catch (SQLException e) {
|
||||
plugin.logError("Could not check if " + getSqlConfig().getOldTableName() + " exists for data object " + dataObject.getCanonicalName() + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
// Prepare and execute the database statements
|
||||
try (PreparedStatement pstmt = getConnection().prepareStatement(getSqlConfig().getSchemaSQL())) {
|
||||
pstmt.execute();
|
||||
} catch (SQLException e) {
|
||||
plugin.logError("Problem trying to create schema for data object " + dataObject.getCanonicalName() + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void rename(PreparedStatement pstmt) {
|
||||
try (ResultSet resultSet = pstmt.executeQuery()) {
|
||||
if (resultSet.next() && resultSet.getBoolean(1)) {
|
||||
// Transition from the old table name
|
||||
try (PreparedStatement pstmt2 = getConnection().prepareStatement(getSqlConfig().getRenameTableSQL())) {
|
||||
@ -57,16 +71,8 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
|
||||
plugin.logError("Could not rename " + getSqlConfig().getOldTableName() + " for data object " + dataObject.getCanonicalName() + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.logError("Could not check if " + getSqlConfig().getOldTableName() + " exists for data object " + dataObject.getCanonicalName() + " " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
// Prepare and execute the database statements
|
||||
try (PreparedStatement pstmt = getConnection().prepareStatement(getSqlConfig().getSchemaSQL())) {
|
||||
pstmt.execute();
|
||||
} catch (SQLException e) {
|
||||
plugin.logError("Problem trying to create schema for data object " + dataObject.getCanonicalName() + " " + e.getMessage());
|
||||
} catch (Exception ex) {
|
||||
plugin.logError("Could not check if " + getSqlConfig().getOldTableName() + " exists for data object " + dataObject.getCanonicalName() + " " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user