diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupElement.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupElement.java index 5723364..ce96feb 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupElement.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupElement.java @@ -52,7 +52,7 @@ public class MPGroupElement extends SQLElement { public List getUsers() throws SQLException { - return ((MPGroupUserTable)ORM.getTable("mp_group_user")) + return ORM.getTable(MPGroupUserTable.class) .getAll("groupId = "+getId(), "id ASC", null, null); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserElement.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserElement.java index f3cf21e..bfb88bb 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserElement.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserElement.java @@ -60,7 +60,7 @@ public class MPGroupUserElement extends SQLElement { public MPWebSessionElement getWebSessionData() throws SQLException { - return ((MPWebSessionTable)ORM.getTable("mp_web_session")) + return ORM.getTable(MPWebSessionTable.class) .getFirst("playerName LIKE '"+getPlayerName()+"'", "id ASC"); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageElement.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageElement.java index 8a81372..145ba4a 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageElement.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageElement.java @@ -159,7 +159,7 @@ public class MPMessageElement extends SQLElement { public MPGroupElement getDestGroupElement() throws SQLException { if (getDestGroup() == null) return null; - return ((MPGroupTable)ORM.getTable("mp_group")).get(getDestGroup()); + return ORM.getTable(MPGroupTable.class).get(getDestGroup()); } } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/ORM.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/ORM.java index 4a70f5a..4fe502d 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/ORM.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/ORM.java @@ -1,8 +1,8 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; /** * ORM = Object-Relational Mapping
@@ -21,7 +21,7 @@ import java.util.Map; public final class ORM { @SuppressWarnings("rawtypes") - private static Map tables = new HashMap(); + private static List tables = new ArrayList(); public synchronized static void init() { @@ -31,14 +31,14 @@ public final class ORM { * Les tables SQL sont à instancier ici ! */ - tables.put("modo_history", new ModoHistoryTable()); + tables.add(new ModoHistoryTable()); - tables.put("staff_ticket", new StaffTicketTable()); + tables.add(new StaffTicketTable()); - tables.put("mp_message", new MPMessageTable()); - tables.put("mp_group", new MPGroupTable()); - tables.put("mp_group_user", new MPGroupUserTable()); - tables.put("mp_web_session", new MPWebSessionTable()); + tables.add(new MPMessageTable()); + tables.add(new MPGroupTable()); + tables.add(new MPGroupUserTable()); + tables.add(new MPWebSessionTable()); } catch (SQLException e) { @@ -50,22 +50,10 @@ public final class ORM { - - /** - * Récupère l'instance de la classe associé à la table demandé en paramètre.
- * Il est conseillé de caster le retour de cette méthode par la classe associé à la table demandé. - * @param name nom de la table telle qu'elle est enregistrée dans la classe ORM - * @return ta table dont le nom est passé en paramètre - */ - @SuppressWarnings("rawtypes") - public synchronized static SQLTable getTable(String name) { - return tables.get(name); - } - @SuppressWarnings("rawtypes") public synchronized static T getTable(Class c) { if (c == null) return null; - for (SQLTable table : tables.values()) { + for (SQLTable table : tables) { if (c.isAssignableFrom(table.getClass())) { return c.cast(table); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java index e5535eb..a39d914 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java @@ -105,7 +105,7 @@ public class PrivateMessagesManager extends BukkitRunnable { - List messages = ((MPMessageTable)ORM.getTable("mp_message")).getAllUnsyncMessage(); + List messages = ORM.getTable(MPMessageTable.class).getAllUnsyncMessage(); @@ -173,14 +173,14 @@ public class PrivateMessagesManager extends BukkitRunnable { MPGroupElement groupEl = null; try { - groupEl = ((MPGroupTable)ORM.getTable("mp_group")).getFirst("groupName LIKE '"+groupe+ "'", "id"); + groupEl = ORM.getTable(MPGroupTable.class).getFirst("groupName LIKE '"+groupe+ "'", "id"); if (groupEl == null) throw new MessageSendingException("Ce groupe n'existe pas"); // on vérifie si le joueur source est dans le groupe if (sender.isPlayer()) { - MPGroupUserElement userInGroup = ((MPGroupUserTable)ORM.getTable("mp_group_user")).getPlayerInGroup(groupEl, sender.senderName); + MPGroupUserElement userInGroup = ORM.getTable(MPGroupUserTable.class).getPlayerInGroup(groupEl, sender.senderName); if (userInGroup == null) throw new MessageSendingException("Vous n'êtes pas dans ce groupe"); @@ -593,7 +593,7 @@ public class PrivateMessagesManager extends BukkitRunnable { public void onxAuthLogin(xAuthLoginEvent event) { try { - List messages = ((MPMessageTable)ORM.getTable("mp_message")).getAllUnreadForPlayer(event.getPlayer().getName()); + List messages = ORM.getTable(MPMessageTable.class).getAllUnreadForPlayer(event.getPlayer().getName()); int nbMess = messages.size(); @@ -640,7 +640,7 @@ public class PrivateMessagesManager extends BukkitRunnable { } try { - MPWebSessionElement webSession = ((MPWebSessionTable)ORM.getTable("mp_web_session")).getFirst("playerName LIKE '"+playerName+"'", null); + MPWebSessionElement webSession = ORM.getTable(MPWebSessionTable.class).getFirst("playerName LIKE '"+playerName+"'", null); if (webSession != null) { long lastWebActivity = webSession.getLastWebActivity(); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java index c6e43c4..beec9c3 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java @@ -39,9 +39,7 @@ public class StaffQueueManager { public StaffQueueManager() { try { - StaffTicketTable dbTable = (StaffTicketTable) ORM.getTable("staff_ticket"); - - List elmts = dbTable.getAll(null, "creationTime ASC, id ASC", null, null); + List elmts = ORM.getTable(StaffTicketTable.class).getAll(null, "creationTime ASC, id ASC", null, null); for (StaffTicketElement el : elmts) playerQueue.add(new WaitingPlayer(el)); @@ -322,7 +320,7 @@ public class StaffQueueManager { message = m; try { - StaffTicketElement el = ((StaffTicketTable)ORM.getTable("staff_ticket")).get(dbId); + StaffTicketElement el = ORM.getTable(StaffTicketTable.class).get(dbId); el.setMessage(message); el.save(); @@ -342,7 +340,7 @@ public class StaffQueueManager { else staffPlayer = p.getName(); try { - StaffTicketElement el = ((StaffTicketTable)ORM.getTable("staff_ticket")).get(dbId); + StaffTicketElement el = ORM.getTable(StaffTicketTable.class).get(dbId); el.setStaffPlayer(staffPlayer); el.save(); @@ -357,7 +355,7 @@ public class StaffQueueManager { public void deleteFromDB() { try { - ((StaffTicketTable)ORM.getTable("staff_ticket")).get(dbId).delete(); + ORM.getTable(StaffTicketTable.class).get(dbId).delete(); } catch (SQLException e) { e.printStackTrace(); }