Search in sources :

Example 1 with StatementHolder

use of com.bgsoftware.wildchests.database.StatementHolder 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);
    }
}
Also used : ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) Query(com.bgsoftware.wildchests.database.Query) ArrayList(java.util.ArrayList) StatementHolder(com.bgsoftware.wildchests.database.StatementHolder) SQLException(java.sql.SQLException) LinkedChest(com.bgsoftware.wildchests.api.objects.chests.LinkedChest) Location(org.bukkit.Location) World(org.bukkit.World) ResultSet(java.sql.ResultSet) Executor(com.bgsoftware.wildchests.utils.Executor) WRegularChest(com.bgsoftware.wildchests.objects.chests.WRegularChest) Chunk(org.bukkit.Chunk) ChestType(com.bgsoftware.wildchests.api.objects.ChestType) LocationUtils(com.bgsoftware.wildchests.utils.LocationUtils) SQLHelper(com.bgsoftware.wildchests.database.SQLHelper) Bukkit(org.bukkit.Bukkit) StorageChest(com.bgsoftware.wildchests.api.objects.chests.StorageChest) DatabaseObject(com.bgsoftware.wildchests.database.DatabaseObject) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WChest(com.bgsoftware.wildchests.objects.chests.WChest) File(java.io.File) WildChestsPlugin(com.bgsoftware.wildchests.WildChestsPlugin) List(java.util.List) WLinkedChest(com.bgsoftware.wildchests.objects.chests.WLinkedChest) WStorageChest(com.bgsoftware.wildchests.objects.chests.WStorageChest) ChunksListener(com.bgsoftware.wildchests.listeners.ChunksListener) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Chest(com.bgsoftware.wildchests.api.objects.chests.Chest) LinkedChest(com.bgsoftware.wildchests.api.objects.chests.LinkedChest) WRegularChest(com.bgsoftware.wildchests.objects.chests.WRegularChest) StorageChest(com.bgsoftware.wildchests.api.objects.chests.StorageChest) WChest(com.bgsoftware.wildchests.objects.chests.WChest) WLinkedChest(com.bgsoftware.wildchests.objects.chests.WLinkedChest) WStorageChest(com.bgsoftware.wildchests.objects.chests.WStorageChest) Chest(com.bgsoftware.wildchests.api.objects.chests.Chest) DatabaseObject(com.bgsoftware.wildchests.database.DatabaseObject) StatementHolder(com.bgsoftware.wildchests.database.StatementHolder)

Aggregations

WildChestsPlugin (com.bgsoftware.wildchests.WildChestsPlugin)1 ChestType (com.bgsoftware.wildchests.api.objects.ChestType)1 Chest (com.bgsoftware.wildchests.api.objects.chests.Chest)1 LinkedChest (com.bgsoftware.wildchests.api.objects.chests.LinkedChest)1 StorageChest (com.bgsoftware.wildchests.api.objects.chests.StorageChest)1 ChestData (com.bgsoftware.wildchests.api.objects.data.ChestData)1 DatabaseObject (com.bgsoftware.wildchests.database.DatabaseObject)1 Query (com.bgsoftware.wildchests.database.Query)1 SQLHelper (com.bgsoftware.wildchests.database.SQLHelper)1 StatementHolder (com.bgsoftware.wildchests.database.StatementHolder)1 ChunksListener (com.bgsoftware.wildchests.listeners.ChunksListener)1 WChest (com.bgsoftware.wildchests.objects.chests.WChest)1 WLinkedChest (com.bgsoftware.wildchests.objects.chests.WLinkedChest)1 WRegularChest (com.bgsoftware.wildchests.objects.chests.WRegularChest)1 WStorageChest (com.bgsoftware.wildchests.objects.chests.WStorageChest)1 Executor (com.bgsoftware.wildchests.utils.Executor)1 LocationUtils (com.bgsoftware.wildchests.utils.LocationUtils)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1