From 0402d4456a385d7f2b76fa354408b6df2b26d473 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 12 Apr 2013 10:42:37 +0200 Subject: [PATCH] Migrate the auto increment id as well. --- .../massivecraft/factions/FactionColl.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/com/massivecraft/factions/FactionColl.java b/src/com/massivecraft/factions/FactionColl.java index 1caa06d9..a77aceda 100644 --- a/src/com/massivecraft/factions/FactionColl.java +++ b/src/com/massivecraft/factions/FactionColl.java @@ -9,6 +9,7 @@ import org.bukkit.ChatColor; import com.massivecraft.mcore.store.Coll; import com.massivecraft.mcore.store.MStore; +import com.massivecraft.mcore.store.idstrategy.IdStrategyAiAbstract; import com.massivecraft.mcore.util.DiscUtil; import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.xlib.gson.reflect.TypeToken; @@ -51,7 +52,6 @@ public class FactionColl extends Coll } } - // TODO: REMEMBER: Deciding on the next AI value is part of the migration routine. public void migrate() { // Create file objects @@ -65,14 +65,34 @@ public class FactionColl extends Coll Type type = new TypeToken>(){}.getType(); Map id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); + // We need to find the next AI id! + int highestId = 0; + // Set the data for (Entry entry : id2faction.entrySet()) { String factionId = entry.getKey(); Faction faction = entry.getValue(); + + try + { + int intFactionId = Integer.valueOf(factionId); + if (highestId < intFactionId) + { + highestId = intFactionId; + } + } + catch (Exception e) + { + // Just ignore + } + FactionColl.get().create(factionId).load(faction); } + IdStrategyAiAbstract idStrategy = (IdStrategyAiAbstract) FactionColl.get().getIdStrategy(); + idStrategy.setNext(this, highestId + 1); + // Mark as migrated oldFile.renameTo(newFile); }