mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 05:05:18 +01:00
Shifted GSON conversion to main thread to avoid concurrent modification
https://github.com/BentoBoxWorld/BentoBox/issues/968
This commit is contained in:
parent
2f7a4b2528
commit
8c037fc1a3
@ -155,17 +155,16 @@ public class SQLDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
|
||||
return;
|
||||
}
|
||||
// Async
|
||||
processQueue.add(() -> store(instance, sqlConfig.getSaveObjectSQL()));
|
||||
processQueue.add(() -> store(instance.getClass().getName(), getGson().toJson(instance), sqlConfig.getSaveObjectSQL()));
|
||||
}
|
||||
|
||||
private void store(T instance, String sb) {
|
||||
String toStore = getGson().toJson(instance);
|
||||
private void store(String name, String toStore, String sb) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb)) {
|
||||
preparedStatement.setString(1, toStore);
|
||||
preparedStatement.setString(2, toStore);
|
||||
preparedStatement.execute();
|
||||
} catch (SQLException e) {
|
||||
plugin.logError("Could not save object " + instance.getClass().getName() + " " + e.getMessage());
|
||||
plugin.logError("Could not save object " + name + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,9 +49,9 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
|
||||
plugin.logError("This class is not a DataObject: " + instance.getClass().getName());
|
||||
return;
|
||||
}
|
||||
processQueue.add(() -> {
|
||||
Gson gson = getGson();
|
||||
String toStore = gson.toJson(instance);
|
||||
Gson gson = getGson();
|
||||
String toStore = gson.toJson(instance);
|
||||
processQueue.add(() -> {
|
||||
try (PreparedStatement preparedStatement = getConnection().prepareStatement(getSqlConfig().getSaveObjectSQL())) {
|
||||
preparedStatement.setString(1, toStore);
|
||||
preparedStatement.setString(2, ((DataObject)instance).getUniqueId());
|
||||
|
Loading…
Reference in New Issue
Block a user