mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-30 06:33:49 +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;
|
return;
|
||||||
}
|
}
|
||||||
// Async
|
// 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) {
|
private void store(String name, String toStore, String sb) {
|
||||||
String toStore = getGson().toJson(instance);
|
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb)) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sb)) {
|
||||||
preparedStatement.setString(1, toStore);
|
preparedStatement.setString(1, toStore);
|
||||||
preparedStatement.setString(2, toStore);
|
preparedStatement.setString(2, toStore);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
} catch (SQLException e) {
|
} 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());
|
plugin.logError("This class is not a DataObject: " + instance.getClass().getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
processQueue.add(() -> {
|
Gson gson = getGson();
|
||||||
Gson gson = getGson();
|
String toStore = gson.toJson(instance);
|
||||||
String toStore = gson.toJson(instance);
|
processQueue.add(() -> {
|
||||||
try (PreparedStatement preparedStatement = getConnection().prepareStatement(getSqlConfig().getSaveObjectSQL())) {
|
try (PreparedStatement preparedStatement = getConnection().prepareStatement(getSqlConfig().getSaveObjectSQL())) {
|
||||||
preparedStatement.setString(1, toStore);
|
preparedStatement.setString(1, toStore);
|
||||||
preparedStatement.setString(2, ((DataObject)instance).getUniqueId());
|
preparedStatement.setString(2, ((DataObject)instance).getUniqueId());
|
||||||
|
Loading…
Reference in New Issue
Block a user