diff --git a/src/main/java/com/songoda/epicanchors/files/DataManager.java b/src/main/java/com/songoda/epicanchors/files/DataManager.java index e0922d2..21ad7d0 100644 --- a/src/main/java/com/songoda/epicanchors/files/DataManager.java +++ b/src/main/java/com/songoda/epicanchors/files/DataManager.java @@ -17,6 +17,7 @@ import org.jetbrains.annotations.Nullable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -141,9 +142,9 @@ public class DataManager extends DataManagerAbstract { SQLException err = null; - for (AnchorMigration.LegacyAnchorEntry entry : anchorEntries) { - try (PreparedStatement ps = con.prepareStatement("INSERT INTO " + this.anchorTable + - "(world_name,x,y,z, ticks_left) VALUES (?,?,?,?, ?);")) { + try (PreparedStatement ps = con.prepareStatement("INSERT INTO " + this.anchorTable + + "(world_name,x,y,z, ticks_left) VALUES (?,?,?,?, ?);")) { + for (AnchorMigration.LegacyAnchorEntry entry : anchorEntries) { ps.setString(1, entry.worldName); ps.setInt(2, entry.x); ps.setInt(3, entry.y); @@ -151,10 +152,18 @@ public class DataManager extends DataManagerAbstract { ps.setInt(5, entry.ticksLeft); - ps.executeUpdate(); - } catch (SQLException ex) { - err = ex; + ps.addBatch(); } + + int[] batchRes = ps.executeBatch(); + + for (int i : batchRes) { + if (i < 0 && i != Statement.SUCCESS_NO_INFO) { + throw new AssertionError("Batch-INSERT failed for at least one statement with code " + i + ""); + } + } + } catch (SQLException ex) { + err = ex; } if (err == null) { diff --git a/src/main/java/com/songoda/epicanchors/files/Settings.java b/src/main/java/com/songoda/epicanchors/files/Settings.java index 855a55b..599409f 100644 --- a/src/main/java/com/songoda/epicanchors/files/Settings.java +++ b/src/main/java/com/songoda/epicanchors/files/Settings.java @@ -6,13 +6,14 @@ import com.songoda.core.configuration.Config; import com.songoda.core.configuration.ConfigSetting; import com.songoda.core.hooks.EconomyManager; import com.songoda.epicanchors.EpicAnchors; +import org.bukkit.plugin.java.JavaPlugin; public class Settings { private Settings() { throw new IllegalStateException("Utility class"); } - public static final Config config = EpicAnchors.getPlugin(EpicAnchors.class).getCoreConfig(); + public static final Config config = JavaPlugin.getPlugin(EpicAnchors.class).getCoreConfig(); public static final ConfigSetting NAME_TAG = new ConfigSetting(config, "Main.Name Tag", "&6Anchor &8(&7{REMAINING}&8)", diff --git a/src/main/java/com/songoda/epicanchors/files/migration/AnchorMigration.java b/src/main/java/com/songoda/epicanchors/files/migration/AnchorMigration.java index 765e3c5..8899362 100644 --- a/src/main/java/com/songoda/epicanchors/files/migration/AnchorMigration.java +++ b/src/main/java/com/songoda/epicanchors/files/migration/AnchorMigration.java @@ -8,7 +8,7 @@ import com.songoda.core.database.DatabaseConnector; import com.songoda.epicanchors.files.DataManager; import com.songoda.epicanchors.utils.ThreadSync; import org.bukkit.Location; -import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.plugin.Plugin; import java.io.IOException; import java.nio.file.Files; @@ -27,9 +27,7 @@ public class AnchorMigration extends DataMigrationManager { this.dataManager = dataManager; } - // TODO: Migration of a lot of Anchors takes **very** long (1100 anchors => 9 seconds) - // This is easily fixed by putting all inserts into one big transaction but prevents us from - public void migrateLegacyData(JavaPlugin plugin) { + public void migrateLegacyData(Plugin plugin) { long start = System.nanoTime(); AtomicBoolean abortMigration = new AtomicBoolean(false);