use of com.bgsoftware.wildchests.database.DatabaseObject in project WildChests by BG-Software-LLC.
the class DataHandler method saveDatabase.
public void saveDatabase(Chunk chunk, boolean async) {
List<Chest> chestList = chunk == null ? plugin.getChestsManager().getChests() : plugin.getChestsManager().getChests(chunk);
List<Chest> regularModifiedChests = chestList.stream().filter(chest -> chest.getChestType() == ChestType.CHEST).collect(Collectors.toList());
List<Chest> storageModifiedChests = chestList.stream().filter(chest -> chest.getChestType() == ChestType.STORAGE_UNIT).collect(Collectors.toList());
List<Chest> linkedChestsModifiedChests = chestList.stream().filter(chest -> chest.getChestType() == ChestType.LINKED_CHEST).collect(Collectors.toList());
if (!regularModifiedChests.isEmpty()) {
StatementHolder chestsUpdateHolder = Query.REGULAR_CHEST_UPDATE_INVENTORIES.getStatementHolder(null);
chestsUpdateHolder.prepareBatch();
regularModifiedChests.forEach(chest -> ((DatabaseObject) chest).setUpdateStatement(chestsUpdateHolder).addBatch());
chestsUpdateHolder.execute(async);
}
if (!storageModifiedChests.isEmpty()) {
StatementHolder chestsUpdateHolder = Query.STORAGE_UNIT_UPDATE_ITEM.getStatementHolder(null);
chestsUpdateHolder.prepareBatch();
storageModifiedChests.forEach(chest -> ((DatabaseObject) chest).setUpdateStatement(chestsUpdateHolder).addBatch());
chestsUpdateHolder.execute(async);
}
if (!linkedChestsModifiedChests.isEmpty()) {
StatementHolder chestsUpdateHolder = Query.LINKED_CHEST_UPDATE_INVENTORIES.getStatementHolder(null);
chestsUpdateHolder.prepareBatch();
linkedChestsModifiedChests.forEach(chest -> ((DatabaseObject) chest).setUpdateStatement(chestsUpdateHolder).addBatch());
chestsUpdateHolder.execute(async);
}
}
Aggregations