|
|
|
@ -217,7 +217,7 @@ public class MySqlDatabase extends Database {
|
|
|
|
|
public Optional<DataSnapshot.Packed> getLatestSnapshot(@NotNull User user) {
|
|
|
|
|
try (Connection connection = getConnection()) {
|
|
|
|
|
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
|
|
|
|
SELECT `version_uuid`, `timestamp`, `save_cause`, `pinned`, `data`
|
|
|
|
|
SELECT `version_uuid`, `timestamp`, `data`
|
|
|
|
|
FROM `%user_data_table%`
|
|
|
|
|
WHERE `player_uuid`=?
|
|
|
|
|
ORDER BY `timestamp` DESC
|
|
|
|
@ -225,10 +225,14 @@ public class MySqlDatabase extends Database {
|
|
|
|
|
statement.setString(1, user.getUuid().toString());
|
|
|
|
|
final ResultSet resultSet = statement.executeQuery();
|
|
|
|
|
if (resultSet.next()) {
|
|
|
|
|
final UUID versionUuid = UUID.fromString(resultSet.getString("version_uuid"));
|
|
|
|
|
final OffsetDateTime timestamp = OffsetDateTime.ofInstant(
|
|
|
|
|
resultSet.getTimestamp("timestamp").toInstant(), TimeZone.getDefault().toZoneId()
|
|
|
|
|
);
|
|
|
|
|
final Blob blob = resultSet.getBlob("data");
|
|
|
|
|
final byte[] dataByteArray = blob.getBytes(1, (int) blob.length());
|
|
|
|
|
blob.free();
|
|
|
|
|
return Optional.of(DataSnapshot.deserialize(plugin, dataByteArray));
|
|
|
|
|
return Optional.of(DataSnapshot.deserialize(plugin, dataByteArray, versionUuid, timestamp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException | DataAdapter.AdaptionException e) {
|
|
|
|
@ -244,17 +248,21 @@ public class MySqlDatabase extends Database {
|
|
|
|
|
final List<DataSnapshot.Packed> retrievedData = new ArrayList<>();
|
|
|
|
|
try (Connection connection = getConnection()) {
|
|
|
|
|
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
|
|
|
|
SELECT `version_uuid`, `timestamp`, `save_cause`, `pinned`, `data`
|
|
|
|
|
SELECT `version_uuid`, `timestamp`, `data`
|
|
|
|
|
FROM `%user_data_table%`
|
|
|
|
|
WHERE `player_uuid`=?
|
|
|
|
|
ORDER BY `timestamp` DESC;"""))) {
|
|
|
|
|
statement.setString(1, user.getUuid().toString());
|
|
|
|
|
final ResultSet resultSet = statement.executeQuery();
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
final UUID versionUuid = UUID.fromString(resultSet.getString("version_uuid"));
|
|
|
|
|
final OffsetDateTime timestamp = OffsetDateTime.ofInstant(
|
|
|
|
|
resultSet.getTimestamp("timestamp").toInstant(), TimeZone.getDefault().toZoneId()
|
|
|
|
|
);
|
|
|
|
|
final Blob blob = resultSet.getBlob("data");
|
|
|
|
|
final byte[] dataByteArray = blob.getBytes(1, (int) blob.length());
|
|
|
|
|
blob.free();
|
|
|
|
|
retrievedData.add(DataSnapshot.deserialize(plugin, dataByteArray));
|
|
|
|
|
retrievedData.add(DataSnapshot.deserialize(plugin, dataByteArray, versionUuid, timestamp));
|
|
|
|
|
}
|
|
|
|
|
return retrievedData;
|
|
|
|
|
}
|
|
|
|
@ -269,7 +277,7 @@ public class MySqlDatabase extends Database {
|
|
|
|
|
public Optional<DataSnapshot.Packed> getSnapshot(@NotNull User user, @NotNull UUID versionUuid) {
|
|
|
|
|
try (Connection connection = getConnection()) {
|
|
|
|
|
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
|
|
|
|
SELECT `version_uuid`, `timestamp`, `save_cause`, `pinned`, `data`
|
|
|
|
|
SELECT `version_uuid`, `timestamp`, `data`
|
|
|
|
|
FROM `%user_data_table%`
|
|
|
|
|
WHERE `player_uuid`=? AND `version_uuid`=?
|
|
|
|
|
ORDER BY `timestamp` DESC
|
|
|
|
@ -279,9 +287,12 @@ public class MySqlDatabase extends Database {
|
|
|
|
|
final ResultSet resultSet = statement.executeQuery();
|
|
|
|
|
if (resultSet.next()) {
|
|
|
|
|
final Blob blob = resultSet.getBlob("data");
|
|
|
|
|
final OffsetDateTime timestamp = OffsetDateTime.ofInstant(
|
|
|
|
|
resultSet.getTimestamp("timestamp").toInstant(), TimeZone.getDefault().toZoneId()
|
|
|
|
|
);
|
|
|
|
|
final byte[] dataByteArray = blob.getBytes(1, (int) blob.length());
|
|
|
|
|
blob.free();
|
|
|
|
|
return Optional.of(DataSnapshot.deserialize(plugin, dataByteArray));
|
|
|
|
|
return Optional.of(DataSnapshot.deserialize(plugin, dataByteArray, versionUuid, timestamp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException | DataAdapter.AdaptionException e) {
|
|
|
|
|