Make timestamp optional again

This commit is contained in:
William committed 2021-08-28 23:28:02 +01:00
1 parent e200bd670c
commit 7539094a2d
5 files changed
+37 -20

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>me.William278</groupId>
<artifactId>HuskHomes</artifactId>
<version>2.8</version>
<version>2.8.1</version>
<packaging>jar</packaging>
<name>HuskHomes</name>
@@ -164,13 +164,18 @@ public class DataManager {
while (resultSet.next()) {
int locationID = resultSet.getInt("location_id");
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID, connection);
long epochTime = 0;
final Timestamp timestamp = resultSet.getTimestamp("creation_time");
if (timestamp != null) {
epochTime = timestamp.getTime();
}
playerHomes.add(new Home(teleportationPoint,
playerName,
getPlayerUUID(resultSet.getInt("player_id"), connection),
resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getBoolean("public"),
resultSet.getTimestamp("creation_time").getTime()));
epochTime));
}
}
@@ -187,12 +192,17 @@ public class DataManager {
int playerID = resultSet.getInt("player_id");
int locationID = resultSet.getInt("location_id");
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID, connection);
long epochTime = 0;
final Timestamp timestamp = resultSet.getTimestamp("creation_time");
if (timestamp != null) {
epochTime = timestamp.getTime();
}
publicHomes.add(new Home(teleportationPoint,
getPlayerUsername(playerID, connection),
getPlayerUUID(playerID, connection),
resultSet.getString("name"),
resultSet.getString("description"), true,
resultSet.getTimestamp("creation_time").getTime()));
epochTime));
}
}
@@ -208,10 +218,15 @@ public class DataManager {
while (resultSet.next()) {
int locationID = resultSet.getInt("location_id");
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID, connection);
long epochTime = 0;
final Timestamp timestamp = resultSet.getTimestamp("creation_time");
if (timestamp != null) {
epochTime = timestamp.getTime();
}
warps.add(new Warp(teleportationPoint,
resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("creation_time").getTime()));
epochTime));
}
} else {
Bukkit.getLogger().severe("Result set of warps returned null!");
@@ -229,10 +244,15 @@ public class DataManager {
if (resultSet.next()) {
int locationID = resultSet.getInt("location_id");
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID, connection);
long epochTime = 0;
final Timestamp timestamp = resultSet.getTimestamp("creation_time");
if (timestamp != null) {
epochTime = timestamp.getTime();
}
return new Warp(teleportationPoint,
resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getTimestamp("creation_time").getTime());
epochTime);
}
}
return null;
@@ -505,13 +525,18 @@ public class DataManager {
if (resultSet.next()) {
final int locationID = resultSet.getInt("location_id");
final TeleportationPoint teleportationPoint = getTeleportationPoint(locationID, connection);
long epochTime = 0;
final Timestamp timestamp = resultSet.getTimestamp("creation_time");
if (timestamp != null) {
epochTime = timestamp.getTime();
}
final Home home = new Home(teleportationPoint,
ownerUsername,
getPlayerUUID(resultSet.getInt("player_id"), connection),
resultSet.getString("name"),
resultSet.getString("description"),
resultSet.getBoolean("public"),
resultSet.getTimestamp("creation_time").getTime());
epochTime);
statement.close();
return home;
}
@@ -48,7 +48,7 @@ public class MySQL extends Database {
"`name` varchar(16) NOT NULL," +
"`description` varchar(255) NOT NULL," +
"`public` boolean NOT NULL," +
"`creation_time` timestamp NOT NULL," +
"`creation_time` timestamp NULL," +
"PRIMARY KEY (`player_id`, `name`)," +
"FOREIGN KEY (`player_id`) REFERENCES " + HuskHomes.getSettings().getPlayerDataTable() + " (`player_id`) ON DELETE CASCADE ON UPDATE NO ACTION," +
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
@@ -58,7 +58,7 @@ public class MySQL extends Database {
"`location_id` integer NOT NULL," +
"`name` varchar(16) NOT NULL UNIQUE," +
"`description` varchar(255) NOT NULL," +
"`creation_time` timestamp NOT NULL," +
"`creation_time` timestamp NULL," +
"PRIMARY KEY (`location_id`)," +
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
");"
@@ -50,7 +50,7 @@ public class SQLite extends Database {
"`name` varchar(16) NOT NULL," +
"`description` varchar(255) NOT NULL," +
"`public` boolean NOT NULL," +
"`creation_time` timestamp NOT NULL," +
"`creation_time` timestamp NULL," +
"PRIMARY KEY (`player_id`, `name`)," +
"FOREIGN KEY (`player_id`) REFERENCES " + HuskHomes.getSettings().getPlayerDataTable() + " (`player_id`) ON DELETE CASCADE ON UPDATE NO ACTION," +
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
@@ -60,7 +60,7 @@ public class SQLite extends Database {
"`location_id` integer NOT NULL," +
"`name` varchar(16) NOT NULL UNIQUE," +
"`description` varchar(255) NOT NULL," +
"`creation_time` timestamp NOT NULL," +
"`creation_time` timestamp NULL," +
"PRIMARY KEY (`location_id`)," +
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
");"
@@ -74,12 +74,8 @@ public class UpgradeDatabase {
plugin.getLogger().info("Database upgrade needed: Adding creation timestamps to homes and warps...");
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
"ALTER TABLE " + HuskHomes.getSettings().getHomesDataTable()
+ " ADD `creation_time` timestamp NOT NULL DEFAULT 0;")) {
+ " ADD `creation_time` timestamp NULL DEFAULT NULL;")) {
tableUpdateStatement.execute();
try (PreparedStatement timeSettingStatement = HuskHomes.getConnection().prepareStatement(
"UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `creation_time`=CURRENT_TIMESTAMP;")) {
timeSettingStatement.executeUpdate();
}
plugin.getLogger().info("Database upgrade in progress... (1/2)");
} catch (SQLException e) {
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
@@ -87,12 +83,8 @@ public class UpgradeDatabase {
}
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
"ALTER TABLE " + HuskHomes.getSettings().getWarpsDataTable()
+ " ADD `creation_time` timestamp NOT NULL DEFAULT 0;")) {
+ " ADD `creation_time` timestamp NULL DEFAULT NULL;")) {
tableUpdateStatement.execute();
try (PreparedStatement timeSettingStatement = HuskHomes.getConnection().prepareStatement(
"UPDATE " + HuskHomes.getSettings().getWarpsDataTable() + " SET `creation_time`=CURRENT_TIMESTAMP;")) {
timeSettingStatement.executeUpdate();
}
plugin.getLogger().info("Database upgrade in progress... (2/2)");
} catch (SQLException e) {
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");