On conflict update.

This commit is contained in:
Brianna 2020-08-28 18:21:58 -05:00
parent 2e8004e6a1
commit 756671a632
1 changed files with 4 additions and 1 deletions

View File

@ -133,12 +133,15 @@ public class DataManager extends DataManagerAbstract {
public void createStackedEntities(ColdEntityStack hostStack, List<StackedEntity> stackedEntities) {
this.queueAsync(() -> this.databaseConnector.connect(connection -> {
if (hostStack.getHostUniqueId() == null) return;
String createSerializedEntity = "INSERT INTO " + this.getTablePrefix() + "stacked_entities (uuid, host, serialized_entity) VALUES (?, ?, ?)";
String createSerializedEntity = "INSERT INTO " + this.getTablePrefix() + "stacked_entities (uuid, host, serialized_entity) VALUES (?, ?, ?)" +
"ON CONFLICT(uuid) DO UPDATE SET host = ?, serialized_entity = ?";
try (PreparedStatement statement = connection.prepareStatement(createSerializedEntity)) {
for (StackedEntity entity : stackedEntities) {
statement.setString(1, entity.getUniqueId().toString());
statement.setInt(2, hostStack.getId());
statement.setBytes(3, entity.getSerializedEntity());
statement.setInt(4, hostStack.getId());
statement.setBytes(5, entity.getSerializedEntity());
statement.addBatch();
}
statement.executeBatch();