Shifted GSON conversion to main thread to avoid concurrent modification

https://github.com/BentoBoxWorld/BentoBox/issues/968
This commit is contained in:
tastybento 2019-09-30 15:38:00 -07:00
parent 2f7a4b2528
commit 8c037fc1a3
2 changed files with 6 additions and 7 deletions

View File

@ -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());
}
}

View File

@ -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());