Optimize and cleanup various classes

Reformatted several classes for optimization purposes. This includes removing unnecessary try-catch blocks, redundant initializers and imports, and condensing confirmation checks. Additionally, updated the `Database` class's `createUserPointsTable` and `createQuestLogTable` methods to use try-with-resources to ensure proper resource management.
This commit is contained in:
2024-04-13 20:43:37 +02:00
parent c6b186e2c6
commit 3bb822b41c
16 changed files with 85 additions and 113 deletions
@@ -10,6 +10,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Database {
@@ -88,19 +89,19 @@ public class Database {
}
private static void createUserPointsTable() {
try {
String sql = "CREATE TABLE IF NOT EXISTS generic_quest_progress(" +
"year_day INT NOT NULL, " +
"uuid VARCHAR(36) NOT NULL, " +
"quest VARCHAR(36) NOT NULL, " +
"quest_variant VARCHAR(36) NOT NULL, " +
"step_1_progress INT NOT NULL, " +
"step_2_progress INT NOT NULL, " +
"amount INT NOT NULL, " +
"reward_received BIT(1) NOT NULL, " +
"PRIMARY KEY (uuid)" +
")";
getDatabase().getConnection().prepareStatement(sql).executeUpdate();
String sql = "CREATE TABLE IF NOT EXISTS generic_quest_progress(" +
"year_day INT NOT NULL, " +
"uuid VARCHAR(36) NOT NULL, " +
"quest VARCHAR(36) NOT NULL, " +
"quest_variant VARCHAR(36) NOT NULL, " +
"step_1_progress INT NOT NULL, " +
"step_2_progress INT NOT NULL, " +
"amount INT NOT NULL, " +
"reward_received BIT(1) NOT NULL, " +
"PRIMARY KEY (uuid)" +
")";
try (PreparedStatement preparedStatement = getDatabase().getConnection().prepareStatement(sql)) {
preparedStatement.executeUpdate();
} catch (SQLException e) {
Logger.throwing(Database.class.getName(), "createUserPointsTable", e);
Logger.severe("Error while trying to create user point table");
@@ -110,15 +111,15 @@ public class Database {
}
private static void createQuestLogTable() {
try {
String sql = "CREATE TABLE IF NOT EXISTS quest_log(" +
"uuid VARCHAR(36) NOT NULL, " +
"year INT NOT NULL, " +
"month INT NOT NULL, " +
"day INT NOT NULL, " +
"PRIMARY KEY (uuid, year, month, day)" +
")";
getDatabase().getConnection().prepareStatement(sql).executeUpdate();
String sql = "CREATE TABLE IF NOT EXISTS quest_log(" +
"uuid VARCHAR(36) NOT NULL, " +
"year INT NOT NULL, " +
"month INT NOT NULL, " +
"day INT NOT NULL, " +
"PRIMARY KEY (uuid, year, month, day)" +
")";
try (PreparedStatement preparedStatement = getDatabase().getConnection().prepareStatement(sql)) {
preparedStatement.executeUpdate();
} catch (SQLException e) {
Logger.throwing(Database.class.getName(), "createQuestLogTable", e);
Logger.severe("Error while trying to create quest log table\nShutting down AltitudeQuests");