From 805ff052d3180246c47c9769b3b33503999914dd Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Fri, 15 Jul 2016 02:05:22 +0200 Subject: [PATCH] =?UTF-8?q?Refactoring=20de=20l'ORM=20:=20package=20'db2'?= =?UTF-8?q?=20->=20'db'=20+=20typage=20plus=20pr=C3=A9cis=20des=20SQLField?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fr/pandacube/java/util/PlayerFinder.java | 18 ++-- src/fr/pandacube/java/util/db/SQLContact.java | 43 +++++++++ .../java/util/db/SQLForumCategorie.java | 25 +++++ .../pandacube/java/util/db/SQLForumForum.java | 36 +++++++ .../pandacube/java/util/db/SQLForumPost.java | 41 ++++++++ .../java/util/db/SQLForumThread.java | 45 +++++++++ .../java/util/db/SQLLoginHistory.java | 47 +++++++++ src/fr/pandacube/java/util/db/SQLMPGroup.java | 41 ++++++++ .../java/util/{db2 => db}/SQLMPGroupUser.java | 26 ++--- .../java/util/{db2 => db}/SQLMPMessage.java | 60 ++++++------ .../java/util/db/SQLModoHistory.java | 57 +++++++++++ .../java/util/db/SQLOnlineshopHistory.java | 65 +++++++++++++ src/fr/pandacube/java/util/db/SQLPlayer.java | 91 ++++++++++++++++++ .../util/{db2 => db}/SQLPlayerIgnore.java | 30 +++--- .../pandacube/java/util/db/SQLShopStock.java | 27 ++++++ .../java/util/db/SQLStaffTicket.java | 50 ++++++++++ .../java/util/db/SQLStaticPages.java | 28 ++++++ .../pandacube/java/util/db/SQLUUIDPlayer.java | 38 ++++++++ .../{db2 => db}/sql_tools/DBConnection.java | 2 +- .../java/util/{db2 => db}/sql_tools/ORM.java | 95 ++++++++----------- .../{db2 => db}/sql_tools/ORMException.java | 2 +- .../sql_tools/ORMInitTableException.java | 6 +- .../{db2 => db}/sql_tools/SQLElement.java | 89 ++++++++++------- .../{db2 => db}/sql_tools/SQLElementList.java | 13 ++- .../{db2 => db}/sql_tools/SQLFKField.java | 40 ++++---- .../util/{db2 => db}/sql_tools/SQLField.java | 12 +-- .../{db2 => db}/sql_tools/SQLOrderBy.java | 10 +- .../util/{db2 => db}/sql_tools/SQLType.java | 2 +- .../util/{db2 => db}/sql_tools/SQLWhere.java | 2 +- .../{db2 => db}/sql_tools/SQLWhereChain.java | 2 +- .../{db2 => db}/sql_tools/SQLWhereComp.java | 6 +- .../{db2 => db}/sql_tools/SQLWhereLike.java | 6 +- .../{db2 => db}/sql_tools/SQLWhereNull.java | 6 +- .../pandacube/java/util/db2/SQLContact.java | 43 --------- .../java/util/db2/SQLForumCategorie.java | 25 ----- .../java/util/db2/SQLForumForum.java | 36 ------- .../pandacube/java/util/db2/SQLForumPost.java | 41 -------- .../java/util/db2/SQLForumThread.java | 45 --------- .../java/util/db2/SQLLoginHistory.java | 47 --------- .../pandacube/java/util/db2/SQLMPGroup.java | 41 -------- .../java/util/db2/SQLModoHistory.java | 57 ----------- .../java/util/db2/SQLOnlineshopHistory.java | 65 ------------- src/fr/pandacube/java/util/db2/SQLPlayer.java | 91 ------------------ .../pandacube/java/util/db2/SQLShopStock.java | 27 ------ .../java/util/db2/SQLStaffTicket.java | 50 ---------- .../java/util/db2/SQLStaticPages.java | 28 ------ .../java/util/db2/SQLUUIDPlayer.java | 38 -------- 47 files changed, 850 insertions(+), 845 deletions(-) create mode 100644 src/fr/pandacube/java/util/db/SQLContact.java create mode 100644 src/fr/pandacube/java/util/db/SQLForumCategorie.java create mode 100644 src/fr/pandacube/java/util/db/SQLForumForum.java create mode 100644 src/fr/pandacube/java/util/db/SQLForumPost.java create mode 100644 src/fr/pandacube/java/util/db/SQLForumThread.java create mode 100644 src/fr/pandacube/java/util/db/SQLLoginHistory.java create mode 100644 src/fr/pandacube/java/util/db/SQLMPGroup.java rename src/fr/pandacube/java/util/{db2 => db}/SQLMPGroupUser.java (59%) rename src/fr/pandacube/java/util/{db2 => db}/SQLMPMessage.java (63%) create mode 100644 src/fr/pandacube/java/util/db/SQLModoHistory.java create mode 100644 src/fr/pandacube/java/util/db/SQLOnlineshopHistory.java create mode 100644 src/fr/pandacube/java/util/db/SQLPlayer.java rename src/fr/pandacube/java/util/{db2 => db}/SQLPlayerIgnore.java (69%) create mode 100644 src/fr/pandacube/java/util/db/SQLShopStock.java create mode 100644 src/fr/pandacube/java/util/db/SQLStaffTicket.java create mode 100644 src/fr/pandacube/java/util/db/SQLStaticPages.java create mode 100644 src/fr/pandacube/java/util/db/SQLUUIDPlayer.java rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/DBConnection.java (95%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/ORM.java (69%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/ORMException.java (87%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/ORMInitTableException.java (52%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLElement.java (76%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLElementList.java (91%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLFKField.java (51%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLField.java (86%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLOrderBy.java (83%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLType.java (98%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLWhere.java (82%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLWhereChain.java (96%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLWhereComp.java (89%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLWhereLike.java (82%) rename src/fr/pandacube/java/util/{db2 => db}/sql_tools/SQLWhereNull.java (87%) delete mode 100644 src/fr/pandacube/java/util/db2/SQLContact.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLForumCategorie.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLForumForum.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLForumPost.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLForumThread.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLLoginHistory.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLMPGroup.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLModoHistory.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLOnlineshopHistory.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLPlayer.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLShopStock.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLStaffTicket.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLStaticPages.java delete mode 100644 src/fr/pandacube/java/util/db2/SQLUUIDPlayer.java diff --git a/src/fr/pandacube/java/util/PlayerFinder.java b/src/fr/pandacube/java/util/PlayerFinder.java index f19cb33..f5d2853 100644 --- a/src/fr/pandacube/java/util/PlayerFinder.java +++ b/src/fr/pandacube/java/util/PlayerFinder.java @@ -4,15 +4,15 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import fr.pandacube.java.util.db2.SQLLoginHistory; -import fr.pandacube.java.util.db2.SQLPlayer; -import fr.pandacube.java.util.db2.SQLUUIDPlayer; -import fr.pandacube.java.util.db2.sql_tools.ORM; -import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy; -import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy.Direction; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereLike; +import fr.pandacube.java.util.db.SQLLoginHistory; +import fr.pandacube.java.util.db.SQLPlayer; +import fr.pandacube.java.util.db.SQLUUIDPlayer; +import fr.pandacube.java.util.db.sql_tools.ORM; +import fr.pandacube.java.util.db.sql_tools.SQLOrderBy; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereLike; +import fr.pandacube.java.util.db.sql_tools.SQLOrderBy.Direction; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; import net.alpenblock.bungeeperms.BungeePerms; /* diff --git a/src/fr/pandacube/java/util/db/SQLContact.java b/src/fr/pandacube/java/util/db/SQLContact.java new file mode 100644 index 0000000..d543527 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLContact.java @@ -0,0 +1,43 @@ +package fr.pandacube.java.util.db; + +import java.util.UUID; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLContact extends SQLElement { + + public SQLContact() { + super(); + } + + public SQLContact(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_contact"; + } + + public static final SQLField time = new SQLField<>("time", SQLType.INT, false); + public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), true, + SQLPlayer.playerId); + public static final SQLField userName = new SQLField<>("userName", SQLType.VARCHAR(50), true); + public static final SQLField userMail = new SQLField<>("userMail", SQLType.VARCHAR(50), true); + public static final SQLField titre = new SQLField<>("titre", SQLType.VARCHAR(100), false); + public static final SQLField texte = new SQLField<>("texte", SQLType.TEXT, false); + public static final SQLField hidden = new SQLField<>("hidden", SQLType.BOOLEAN, false, (Boolean) false); + + public UUID getPlayerId() { + String id = get(playerId); + return (id == null) ? null : UUID.fromString(id); + } + + public void setPlayerId(UUID pName) { + set(playerId, (pName == null) ? (String) null : pName.toString()); + } + +} diff --git a/src/fr/pandacube/java/util/db/SQLForumCategorie.java b/src/fr/pandacube/java/util/db/SQLForumCategorie.java new file mode 100644 index 0000000..d3a9252 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLForumCategorie.java @@ -0,0 +1,25 @@ +package fr.pandacube.java.util.db; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLForumCategorie extends SQLElement { + + public SQLForumCategorie() { + super(); + } + + public SQLForumCategorie(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_forum_categorie"; + } + + public static final SQLField nom = new SQLField<>("nom", SQLType.VARCHAR(100), false); + public static final SQLField ordre = new SQLField<>("ordre", SQLType.INT, false); + +} diff --git a/src/fr/pandacube/java/util/db/SQLForumForum.java b/src/fr/pandacube/java/util/db/SQLForumForum.java new file mode 100644 index 0000000..6be9eaf --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLForumForum.java @@ -0,0 +1,36 @@ +package fr.pandacube.java.util.db; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLForumForum extends SQLElement { + + public SQLForumForum() { + super(); + } + + public SQLForumForum(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_forum_forum"; + } + + public static final SQLFKField catId = SQLFKField.idFK("catId", SQLType.INT, false, + SQLForumCategorie.class); + public static final SQLField nom = new SQLField<>("nom", SQLType.VARCHAR(100), false); + public static final SQLField description = new SQLField<>("description", SQLType.TEXT, false); + public static final SQLField ordre = new SQLField<>("ordre", SQLType.INT, false); + public static final SQLField authView = new SQLField<>("authView", SQLType.INT, false); + public static final SQLField authPost = new SQLField<>("authPost", SQLType.INT, false); + public static final SQLField authThread = new SQLField<>("authThread", SQLType.INT, false); + public static final SQLField authAnchored = new SQLField<>("authAnchored", SQLType.INT, false); + public static final SQLField authModo = new SQLField<>("authModo", SQLType.INT, false); + public static final SQLField nbThreads = new SQLField<>("nbThreads", SQLType.INT, false); + public static final SQLField nbMessages = new SQLField<>("nbMessages", SQLType.INT, false); + +} diff --git a/src/fr/pandacube/java/util/db/SQLForumPost.java b/src/fr/pandacube/java/util/db/SQLForumPost.java new file mode 100644 index 0000000..f606cb2 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLForumPost.java @@ -0,0 +1,41 @@ +package fr.pandacube.java.util.db; + +import java.util.UUID; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLForumPost extends SQLElement { + + public SQLForumPost() { + super(); + } + + public SQLForumPost(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_forum_post"; + } + + public static final SQLField createur = new SQLField<>("createur", SQLType.CHAR(36), false); + public static final SQLField texte = new SQLField<>("texte", SQLType.TEXT, false); + public static final SQLField time = new SQLField<>("time", SQLType.INT, false); + public static final SQLFKField threadId = SQLFKField.idFK("threadId", SQLType.INT, false, + SQLForumThread.class); + public static final SQLField moderated = new SQLField<>("moderated", SQLType.BOOLEAN, false); + + public UUID getCreateurId() { + String id = get(createur); + return (id == null) ? null : UUID.fromString(id); + } + + public void setCreateurId(UUID pName) { + set(createur, (pName == null) ? (String) null : pName.toString()); + } + +} diff --git a/src/fr/pandacube/java/util/db/SQLForumThread.java b/src/fr/pandacube/java/util/db/SQLForumThread.java new file mode 100644 index 0000000..31c7fbb --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLForumThread.java @@ -0,0 +1,45 @@ +package fr.pandacube.java.util.db; + +import java.util.UUID; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLForumThread extends SQLElement { + + public SQLForumThread() { + super(); + } + + public SQLForumThread(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_forum_thread"; + } + + public static final SQLFKField forumId = SQLFKField.idFK("forumId", SQLType.INT, false, + SQLForumForum.class); + public static final SQLField titre = new SQLField<>("titre", SQLType.VARCHAR(60), false); + public static final SQLFKField createur = new SQLFKField<>("createur", SQLType.CHAR(36), false, + SQLPlayer.playerId); + public static final SQLField vu = new SQLField<>("vu", SQLType.INT, false); + public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); + public static final SQLField anchored = new SQLField<>("anchored", SQLType.BOOLEAN, false); + public static final SQLField locked = new SQLField<>("locked", SQLType.BOOLEAN, false); + public static final SQLField nbMessages = new SQLField<>("nbMessages", SQLType.INT, false); + + public UUID getCreateurId() { + String id = get(createur); + return (id == null) ? null : UUID.fromString(id); + } + + public void setCreateurId(UUID pName) { + set(createur, (pName == null) ? (String) null : pName.toString()); + } + +} diff --git a/src/fr/pandacube/java/util/db/SQLLoginHistory.java b/src/fr/pandacube/java/util/db/SQLLoginHistory.java new file mode 100644 index 0000000..0da2ea9 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLLoginHistory.java @@ -0,0 +1,47 @@ +package fr.pandacube.java.util.db; + +import java.util.UUID; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLLoginHistory extends SQLElement { + + public SQLLoginHistory() { + super(); + } + + public SQLLoginHistory(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_login_history"; + } + + public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); + public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, + SQLPlayer.playerId); + public static final SQLField ip = new SQLField<>("ip", SQLType.VARCHAR(128), true); + public static final SQLField actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class), + false); + public static final SQLField nbOnline = new SQLField<>("nbOnline", SQLType.INT, false); + public static final SQLField playerName = new SQLField<>("playerName", SQLType.VARCHAR(16), true); + public static final SQLField minecraftVersion = new SQLField<>("minecraftVersion", SQLType.INT, false, 0); + + public UUID getPlayerId() { + String id = get(playerId); + return (id == null) ? null : UUID.fromString(id); + } + + public void setPlayerId(UUID pName) { + set(playerId, (pName == null) ? (String) null : pName.toString()); + } + + public enum ActionType { + LOGIN, LOGOUT + } +} diff --git a/src/fr/pandacube/java/util/db/SQLMPGroup.java b/src/fr/pandacube/java/util/db/SQLMPGroup.java new file mode 100644 index 0000000..7230167 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLMPGroup.java @@ -0,0 +1,41 @@ +package fr.pandacube.java.util.db; + +import fr.pandacube.java.util.db.sql_tools.ORM; +import fr.pandacube.java.util.db.sql_tools.ORMException; +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLElementList; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLOrderBy; +import fr.pandacube.java.util.db.sql_tools.SQLType; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; + +public class SQLMPGroup extends SQLElement { + + public SQLMPGroup() { + super(); + } + + public SQLMPGroup(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_mp_group"; + } + + public static final SQLField groupName = new SQLField<>("groupName", SQLType.VARCHAR(16), false); + + public SQLElementList getGroupUsers() throws ORMException { + return ORM.getAll(SQLMPGroupUser.class, new SQLWhereComp(SQLMPGroupUser.groupId, SQLComparator.EQ, getId()), + new SQLOrderBy().addField(ORM.getSQLIdField(SQLMPGroupUser.class)), null, null); + } + + public static SQLMPGroup getByName(String name) throws ORMException { + if (name == null) return null; + + return ORM.getFirst(SQLMPGroup.class, new SQLWhereComp(groupName, SQLComparator.EQ, name), null); + } + +} diff --git a/src/fr/pandacube/java/util/db2/SQLMPGroupUser.java b/src/fr/pandacube/java/util/db/SQLMPGroupUser.java similarity index 59% rename from src/fr/pandacube/java/util/db2/SQLMPGroupUser.java rename to src/fr/pandacube/java/util/db/SQLMPGroupUser.java index dfe4825..46e7a67 100644 --- a/src/fr/pandacube/java/util/db2/SQLMPGroupUser.java +++ b/src/fr/pandacube/java/util/db/SQLMPGroupUser.java @@ -1,18 +1,18 @@ -package fr.pandacube.java.util.db2; +package fr.pandacube.java.util.db; import java.sql.SQLException; import java.util.UUID; -import fr.pandacube.java.util.db2.sql_tools.ORM; -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator; +import fr.pandacube.java.util.db.sql_tools.ORM; +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLType; +import fr.pandacube.java.util.db.sql_tools.SQLWhereChain; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; -public class SQLMPGroupUser extends SQLElement { +public class SQLMPGroupUser extends SQLElement { public SQLMPGroupUser() { super(); @@ -27,10 +27,10 @@ public class SQLMPGroupUser extends SQLElement { return "pandacube_mp_group_user"; } - public static final SQLFKField groupId = SQLFKField.idFK("groupId", SQLType.INT, false, + public static final SQLFKField groupId = SQLFKField.idFK("groupId", SQLType.INT, false, SQLMPGroup.class); - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); + public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, + SQLPlayer.playerId); // TODO ajouter un champ qui dit si le joueur est admin du groupe diff --git a/src/fr/pandacube/java/util/db2/SQLMPMessage.java b/src/fr/pandacube/java/util/db/SQLMPMessage.java similarity index 63% rename from src/fr/pandacube/java/util/db2/SQLMPMessage.java rename to src/fr/pandacube/java/util/db/SQLMPMessage.java index 77d6f48..2916810 100644 --- a/src/fr/pandacube/java/util/db2/SQLMPMessage.java +++ b/src/fr/pandacube/java/util/db/SQLMPMessage.java @@ -1,25 +1,25 @@ -package fr.pandacube.java.util.db2; +package fr.pandacube.java.util.db; import java.util.UUID; import fr.pandacube.java.util.PlayerFinder; -import fr.pandacube.java.util.db2.sql_tools.ORM; -import fr.pandacube.java.util.db2.sql_tools.ORMException; -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLElementList; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy; -import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy.Direction; -import fr.pandacube.java.util.db2.sql_tools.SQLType; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereLike; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereNull; +import fr.pandacube.java.util.db.sql_tools.ORM; +import fr.pandacube.java.util.db.sql_tools.ORMException; +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLElementList; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLOrderBy; +import fr.pandacube.java.util.db.sql_tools.SQLType; +import fr.pandacube.java.util.db.sql_tools.SQLWhereChain; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereLike; +import fr.pandacube.java.util.db.sql_tools.SQLWhereNull; +import fr.pandacube.java.util.db.sql_tools.SQLOrderBy.Direction; +import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; -public class SQLMPMessage extends SQLElement { +public class SQLMPMessage extends SQLElement { public SQLMPMessage() { super(); @@ -34,20 +34,20 @@ public class SQLMPMessage extends SQLElement { return "pandacube_mp_message"; } - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLField securityKey = new SQLField<>("securityKey", SQLType.INT, false); - public static final SQLFKField viewerId = new SQLFKField<>("viewerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLFKField sourceId = new SQLFKField<>("sourceId", SQLType.CHAR(36), true, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLFKField destId = new SQLFKField<>("destId", SQLType.CHAR(36), true, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLFKField destGroup = SQLFKField.idFK("destGroup", SQLType.INT, true, + public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); + public static final SQLField securityKey = new SQLField<>("securityKey", SQLType.INT, false); + public static final SQLFKField viewerId = new SQLFKField<>("viewerId", SQLType.CHAR(36), false, + SQLPlayer.playerId); + public static final SQLFKField sourceId = new SQLFKField<>("sourceId", SQLType.CHAR(36), true, + SQLPlayer.playerId); + public static final SQLFKField destId = new SQLFKField<>("destId", SQLType.CHAR(36), true, + SQLPlayer.playerId); + public static final SQLFKField destGroup = SQLFKField.idFK("destGroup", SQLType.INT, true, SQLMPGroup.class); - public static final SQLField message = new SQLField<>("message", SQLType.VARCHAR(512), false); - public static final SQLField wasRead = new SQLField<>("wasRead", SQLType.BOOLEAN, false); - public static final SQLField deleted = new SQLField<>("deleted", SQLType.BOOLEAN, false, (Boolean) false); - public static final SQLField serverSync = new SQLField<>("serverSync", SQLType.BOOLEAN, false); + public static final SQLField message = new SQLField<>("message", SQLType.VARCHAR(512), false); + public static final SQLField wasRead = new SQLField<>("wasRead", SQLType.BOOLEAN, false); + public static final SQLField deleted = new SQLField<>("deleted", SQLType.BOOLEAN, false, (Boolean) false); + public static final SQLField serverSync = new SQLField<>("serverSync", SQLType.BOOLEAN, false); public UUID getViewerId() { String id = get(viewerId); diff --git a/src/fr/pandacube/java/util/db/SQLModoHistory.java b/src/fr/pandacube/java/util/db/SQLModoHistory.java new file mode 100644 index 0000000..328f834 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLModoHistory.java @@ -0,0 +1,57 @@ +package fr.pandacube.java.util.db; + +import java.util.UUID; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLModoHistory extends SQLElement { + + public SQLModoHistory() { + super(); + } + + public SQLModoHistory(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_modo_history"; + } + + public static final SQLFKField modoId = new SQLFKField<>("modoId", SQLType.CHAR(36), true, + SQLPlayer.playerId); + public static final SQLField actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class), + false); + public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); + public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, + SQLPlayer.playerId); + public static final SQLField value = new SQLField<>("value", SQLType.BIGINT, true); + public static final SQLField message = new SQLField<>("message", SQLType.VARCHAR(512), false); + + public UUID getModoId() { + String id = get(modoId); + return (id == null) ? null : UUID.fromString(id); + } + + public void setModoId(UUID pName) { + set(modoId, (pName == null) ? (String) null : pName.toString()); + } + + public UUID getPlayerId() { + String id = get(playerId); + return (id == null) ? null : UUID.fromString(id); + } + + public void setPlayerId(UUID pName) { + set(playerId, (pName == null) ? (String) null : pName.toString()); + } + + public enum ActionType { + BAN, UNBAN, MUTE, UNMUTE, REPORT, KICK + } + +} diff --git a/src/fr/pandacube/java/util/db/SQLOnlineshopHistory.java b/src/fr/pandacube/java/util/db/SQLOnlineshopHistory.java new file mode 100644 index 0000000..16b5b29 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLOnlineshopHistory.java @@ -0,0 +1,65 @@ +package fr.pandacube.java.util.db; + +import java.util.UUID; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLOnlineshopHistory extends SQLElement { + + public SQLOnlineshopHistory() { + super(); + } + + public SQLOnlineshopHistory(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_onlineshop_history"; + } + + public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); + public static final SQLField transactionId = new SQLField<>("transactionId", SQLType.VARCHAR(255), true); + public static final SQLField sourceType = new SQLField<>("sourceType", SQLType.ENUM(SourceType.class), + false); + public static final SQLFKField sourcePlayerId = new SQLFKField<>("sourcePlayerId", + SQLType.CHAR(36), true, SQLPlayer.playerId); + public static final SQLField sourceQuantity = new SQLField<>("sourceQuantity", SQLType.DOUBLE, false); + public static final SQLField sourceName = new SQLField<>("sourceName", SQLType.VARCHAR(64), false); + public static final SQLField destType = new SQLField<>("destType", SQLType.ENUM(DestType.class), false); + public static final SQLFKField destPlayerId = new SQLFKField<>("destPlayerId", SQLType.CHAR(36), + false, SQLPlayer.playerId); + public static final SQLField destQuantity = new SQLField<>("destQuantity", SQLType.DOUBLE, false); + public static final SQLField destName = new SQLField<>("destName", SQLType.VARCHAR(64), false); + + public UUID getSourcePlayerId() { + String id = get(sourcePlayerId); + return (id == null) ? null : UUID.fromString(id); + } + + public void setSourcePlayerId(UUID pName) { + set(sourcePlayerId, (pName == null) ? (String) null : pName.toString()); + } + + public UUID getDestPlayerId() { + String id = get(destPlayerId); + return (id == null) ? null : UUID.fromString(id); + } + + public void setDestPlayerId(UUID pName) { + set(destPlayerId, (pName == null) ? (String) null : pName.toString()); + } + + public static enum SourceType { + REAL_MONEY, BAMBOU + } + + public static enum DestType { + BAMBOU, GRADE + } + +} diff --git a/src/fr/pandacube/java/util/db/SQLPlayer.java b/src/fr/pandacube/java/util/db/SQLPlayer.java new file mode 100644 index 0000000..392ba53 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLPlayer.java @@ -0,0 +1,91 @@ +package fr.pandacube.java.util.db; + +import java.sql.Date; +import java.util.UUID; + +import fr.pandacube.java.util.db.sql_tools.ORM; +import fr.pandacube.java.util.db.sql_tools.ORMException; +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; + +public class SQLPlayer extends SQLElement { + + public SQLPlayer() { + super(); + } + + public SQLPlayer(int id) { + super(id); + } + + /* + * Nom de la table + */ + @Override + protected String tableName() { + return "pandacube_player"; + } + + /* + * Champs de la table + */ + public static final SQLField playerId = new SQLField<>("playerId", SQLType.CHAR(36), false); + public static final SQLField token = new SQLField<>("token", SQLType.CHAR(36), true); + public static final SQLField mailCheck = new SQLField<>("mailCheck", SQLType.VARCHAR(255), true); + public static final SQLField password = new SQLField<>("password", SQLType.VARCHAR(255), true); + public static final SQLField mail = new SQLField<>("mail", SQLType.VARCHAR(255), true); + public static final SQLField playerDisplayName = new SQLField<>("playerDisplayName", SQLType.VARCHAR(255), + false); + public static final SQLField firstTimeInGame = new SQLField<>("firstTimeInGame", SQLType.BIGINT, false, 0L); + public static final SQLField timeWebRegister = new SQLField<>("timeWebRegister", SQLType.BIGINT, true); + public static final SQLField lastTimeInGame = new SQLField<>("lastTimeInGame", SQLType.BIGINT, true); + public static final SQLField lastWebActivity = new SQLField<>("lastWebActivity", SQLType.BIGINT, false, 0L); + public static final SQLField onlineInServer = new SQLField<>("onlineInServer", SQLType.VARCHAR(32), true); + public static final SQLField skinURL = new SQLField<>("skinURL", SQLType.VARCHAR(255), true); + public static final SQLField isVanish = new SQLField<>("isVanish", SQLType.BOOLEAN, false, + (Boolean) false); + public static final SQLField birthday = new SQLField<>("birthday", SQLType.DATE, true); + public static final SQLField lastYearCelebBday = new SQLField<>("lastYearCelebratedBirthday", SQLType.INT, + false, 0); + public static final SQLField banTimeout = new SQLField<>("banTimeout", SQLType.BIGINT, true); + public static final SQLField muteTimeout = new SQLField<>("muteTimeout", SQLType.BIGINT, true); + public static final SQLField isWhitelisted = new SQLField<>("isWhitelisted", SQLType.BOOLEAN, false, + (Boolean) false); + public static final SQLField bambou = new SQLField<>("bambou", SQLType.BIGINT, false, 0L); + public static final SQLField grade = new SQLField<>("grade", SQLType.VARCHAR(36), false, "default"); + + /* + * Getteurs spécifique (encapsulation) + */ + + public UUID getPlayerId() { + String id = get(playerId); + return (id == null) ? null : UUID.fromString(id); + } + + public UUID getToken() { + String id = get(token); + return (id == null) ? null : UUID.fromString(id); + } + + /* + * Setteurs spécifique (encapsulation) + */ + + public void setPlayerId(UUID pName) { + set(playerId, (pName == null) ? (String) null : pName.toString()); + } + + public void setToken(UUID t) { + set(token, (t == null) ? (String) null : t.toString()); + } + + public static SQLPlayer getPlayerFromUUID(UUID playerId) throws ORMException { + return ORM.getFirst(SQLPlayer.class, + new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, playerId.toString()), null); + } + +} diff --git a/src/fr/pandacube/java/util/db2/SQLPlayerIgnore.java b/src/fr/pandacube/java/util/db/SQLPlayerIgnore.java similarity index 69% rename from src/fr/pandacube/java/util/db2/SQLPlayerIgnore.java rename to src/fr/pandacube/java/util/db/SQLPlayerIgnore.java index 1e9dde5..ed6f135 100644 --- a/src/fr/pandacube/java/util/db2/SQLPlayerIgnore.java +++ b/src/fr/pandacube/java/util/db/SQLPlayerIgnore.java @@ -1,20 +1,20 @@ -package fr.pandacube.java.util.db2; +package fr.pandacube.java.util.db; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import fr.pandacube.java.util.db2.sql_tools.ORM; -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy; -import fr.pandacube.java.util.db2.sql_tools.SQLType; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator; +import fr.pandacube.java.util.db.sql_tools.ORM; +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLOrderBy; +import fr.pandacube.java.util.db.sql_tools.SQLType; +import fr.pandacube.java.util.db.sql_tools.SQLWhereChain; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; -public class SQLPlayerIgnore extends SQLElement { +public class SQLPlayerIgnore extends SQLElement { public SQLPlayerIgnore() { super(); @@ -29,10 +29,10 @@ public class SQLPlayerIgnore extends SQLElement { return "pandacube_player_ignore"; } - public static final SQLFKField ignorer = new SQLFKField<>("ignorer", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLFKField ignored = new SQLFKField<>("ignored", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); + public static final SQLFKField ignorer = new SQLFKField<>("ignorer", SQLType.CHAR(36), false, + SQLPlayer.playerId); + public static final SQLFKField ignored = new SQLFKField<>("ignored", SQLType.CHAR(36), false, + SQLPlayer.playerId); public UUID getIgnorerId() { String id = get(ignorer); diff --git a/src/fr/pandacube/java/util/db/SQLShopStock.java b/src/fr/pandacube/java/util/db/SQLShopStock.java new file mode 100644 index 0000000..7536bbd --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLShopStock.java @@ -0,0 +1,27 @@ +package fr.pandacube.java.util.db; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLShopStock extends SQLElement { + + public SQLShopStock() { + super(); + } + + public SQLShopStock(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_shop_stock"; + } + + public static final SQLField material = new SQLField<>("material", SQLType.VARCHAR(50), false); + public static final SQLField damage = new SQLField<>("damage", SQLType.INT, false, 0); + public static final SQLField quantity = new SQLField<>("quantity", SQLType.DOUBLE, false); + public static final SQLField server = new SQLField<>("server", SQLType.VARCHAR(50), false); + +} diff --git a/src/fr/pandacube/java/util/db/SQLStaffTicket.java b/src/fr/pandacube/java/util/db/SQLStaffTicket.java new file mode 100644 index 0000000..f55ae0d --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLStaffTicket.java @@ -0,0 +1,50 @@ +package fr.pandacube.java.util.db; + +import java.util.UUID; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLStaffTicket extends SQLElement { + + public SQLStaffTicket() { + super(); + } + + public SQLStaffTicket(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_staff_ticket"; + } + + public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, + SQLPlayer.playerId); + public static final SQLField message = new SQLField<>("message", SQLType.VARCHAR(1024), false); + public static final SQLField creationTime = new SQLField<>("creationTime", SQLType.BIGINT, false); + public static final SQLFKField staffPlayerId = new SQLFKField<>("staffPlayerId", + SQLType.CHAR(36), true, SQLPlayer.playerId); + + public UUID getPlayerId() { + String id = get(playerId); + return (id == null) ? null : UUID.fromString(id); + } + + public void setPlayerId(UUID id) { + set(playerId, (id == null) ? null : id.toString()); + } + + public UUID getstaffPlayerId() { + String id = get(staffPlayerId); + return (id == null) ? null : UUID.fromString(id); + } + + public void setstaffPlayerId(UUID id) { + set(staffPlayerId, (id == null) ? null : id.toString()); + } + +} diff --git a/src/fr/pandacube/java/util/db/SQLStaticPages.java b/src/fr/pandacube/java/util/db/SQLStaticPages.java new file mode 100644 index 0000000..807b161 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLStaticPages.java @@ -0,0 +1,28 @@ +package fr.pandacube.java.util.db; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLStaticPages extends SQLElement { + + public SQLStaticPages() { + super(); + } + + public SQLStaticPages(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_static_pages"; + } + + public static final SQLField permalink = new SQLField<>("permalink", SQLType.VARCHAR(128), false); + public static final SQLField titreHead = new SQLField<>("titreHead", SQLType.VARCHAR(128), false); + public static final SQLField titreH2 = new SQLField<>("titreH2", SQLType.VARCHAR(255), false); + public static final SQLField texte = new SQLField<>("texte", SQLType.TEXT, false); + public static final SQLField permissions = new SQLField<>("permissions", SQLType.VARCHAR(255), true); + +} diff --git a/src/fr/pandacube/java/util/db/SQLUUIDPlayer.java b/src/fr/pandacube/java/util/db/SQLUUIDPlayer.java new file mode 100644 index 0000000..d43ee7a --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLUUIDPlayer.java @@ -0,0 +1,38 @@ +package fr.pandacube.java.util.db; + +import java.util.UUID; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLUUIDPlayer extends SQLElement { + + public SQLUUIDPlayer() { + super(); + } + + public SQLUUIDPlayer(int id) { + super(id); + } + + @Override + protected String tableName() { + return "bungeeperms_uuidplayer"; + } + + public static final SQLFKField uuid = new SQLFKField<>("uuid", SQLType.CHAR(36), false, + SQLPlayer.playerId); + public static final SQLField player = new SQLField<>("player", SQLType.VARCHAR(16), false); + + public UUID getUUID() { + String id = get(uuid); + return (id == null) ? null : UUID.fromString(id); + } + + public void setUUID(UUID id) { + set(uuid, (id == null) ? null : id.toString()); + } + +} diff --git a/src/fr/pandacube/java/util/db2/sql_tools/DBConnection.java b/src/fr/pandacube/java/util/db/sql_tools/DBConnection.java similarity index 95% rename from src/fr/pandacube/java/util/db2/sql_tools/DBConnection.java rename to src/fr/pandacube/java/util/db/sql_tools/DBConnection.java index 42d7cd1..4368bd3 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/DBConnection.java +++ b/src/fr/pandacube/java/util/db/sql_tools/DBConnection.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.sql.Connection; import java.sql.DriverManager; diff --git a/src/fr/pandacube/java/util/db2/sql_tools/ORM.java b/src/fr/pandacube/java/util/db/sql_tools/ORM.java similarity index 69% rename from src/fr/pandacube/java/util/db2/sql_tools/ORM.java rename to src/fr/pandacube/java/util/db/sql_tools/ORM.java index f7cdcc3..babc396 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/ORM.java +++ b/src/fr/pandacube/java/util/db/sql_tools/ORM.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -10,25 +10,25 @@ import java.util.logging.Level; import fr.pandacube.java.util.EnumUtil; import fr.pandacube.java.util.Log; -import fr.pandacube.java.util.db2.SQLContact; -import fr.pandacube.java.util.db2.SQLForumCategorie; -import fr.pandacube.java.util.db2.SQLForumForum; -import fr.pandacube.java.util.db2.SQLForumPost; -import fr.pandacube.java.util.db2.SQLForumThread; -import fr.pandacube.java.util.db2.SQLLoginHistory; -import fr.pandacube.java.util.db2.SQLMPGroup; -import fr.pandacube.java.util.db2.SQLMPGroupUser; -import fr.pandacube.java.util.db2.SQLMPMessage; -import fr.pandacube.java.util.db2.SQLModoHistory; -import fr.pandacube.java.util.db2.SQLOnlineshopHistory; -import fr.pandacube.java.util.db2.SQLPlayer; -import fr.pandacube.java.util.db2.SQLPlayerIgnore; -import fr.pandacube.java.util.db2.SQLShopStock; -import fr.pandacube.java.util.db2.SQLStaffTicket; -import fr.pandacube.java.util.db2.SQLStaticPages; -import fr.pandacube.java.util.db2.SQLUUIDPlayer; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator; +import fr.pandacube.java.util.db.SQLContact; +import fr.pandacube.java.util.db.SQLForumCategorie; +import fr.pandacube.java.util.db.SQLForumForum; +import fr.pandacube.java.util.db.SQLForumPost; +import fr.pandacube.java.util.db.SQLForumThread; +import fr.pandacube.java.util.db.SQLLoginHistory; +import fr.pandacube.java.util.db.SQLMPGroup; +import fr.pandacube.java.util.db.SQLMPGroupUser; +import fr.pandacube.java.util.db.SQLMPMessage; +import fr.pandacube.java.util.db.SQLModoHistory; +import fr.pandacube.java.util.db.SQLOnlineshopHistory; +import fr.pandacube.java.util.db.SQLPlayer; +import fr.pandacube.java.util.db.SQLPlayerIgnore; +import fr.pandacube.java.util.db.SQLShopStock; +import fr.pandacube.java.util.db.SQLStaffTicket; +import fr.pandacube.java.util.db.SQLStaticPages; +import fr.pandacube.java.util.db.SQLUUIDPlayer; +import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; import javafx.util.Pair; /** @@ -39,7 +39,7 @@ import javafx.util.Pair; */ public final class ORM { - private static List> tables = new ArrayList<>(); + private static List>> tables = new ArrayList<>(); private static DBConnection connection; @@ -81,10 +81,10 @@ public final class ORM { } - /* package */ static void initTable(Class elemClass) throws ORMInitTableException { + /* package */ static > void initTable(Class elemClass) throws ORMInitTableException { if (tables.contains(elemClass)) return; try { - T instance = elemClass.newInstance(); + E instance = elemClass.newInstance(); String tableName = instance.tableName(); if (!tableExist(tableName)) createTable(instance); tables.add(elemClass); @@ -93,14 +93,14 @@ public final class ORM { } } - private static void createTable(T elem) throws SQLException { + private static > void createTable(E elem) throws SQLException { String sql = "CREATE TABLE IF NOT EXISTS " + elem.tableName() + " ("; List params = new ArrayList<>(); - Collection> tableFields = elem.getFields().values(); + Collection> tableFields = elem.getFields().values(); boolean first = true; - for (SQLField f : tableFields) { + for (SQLField f : tableFields) { Pair> statementPart = f.forSQLPreparedStatement(); params.addAll(statementPart.getValue()); @@ -135,40 +135,40 @@ public final class ORM { } @SuppressWarnings("unchecked") - public static SQLField getSQLIdField(Class elemClass) + public static > SQLField getSQLIdField(Class elemClass) throws ORMInitTableException { initTable(elemClass); - return (SQLField) SQLElement.fieldsCache.get(elemClass).get("id"); + return (SQLField) SQLElement.fieldsCache.get(elemClass).get("id"); } - public static List getByIds(Class elemClass, Collection ids) + public static > List getByIds(Class elemClass, Collection ids) throws ORMException { return getByIds(elemClass, ids.toArray(new Integer[ids.size()])); } - public static List getByIds(Class elemClass, Integer... ids) throws ORMException { - SQLField idField = getSQLIdField(elemClass); + public static > List getByIds(Class elemClass, Integer... ids) throws ORMException { + SQLField idField = getSQLIdField(elemClass); SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR); for (Integer id : ids) if (id != null) where.add(new SQLWhereComp(idField, SQLComparator.EQ, id)); return getAll(elemClass, where, new SQLOrderBy().addField(idField), 1, null); } - public static T getById(Class elemClass, int id) throws ORMException { + public static > E getById(Class elemClass, int id) throws ORMException { return getFirst(elemClass, new SQLWhereComp(getSQLIdField(elemClass), SQLComparator.EQ, id), null); } - public static T getFirst(Class elemClass, SQLWhere where, SQLOrderBy orderBy) + public static > E getFirst(Class elemClass, SQLWhere where, SQLOrderBy orderBy) throws ORMException { - SQLElementList elts = getAll(elemClass, where, orderBy, 1, null); + SQLElementList elts = getAll(elemClass, where, orderBy, 1, null); return (elts.size() == 0) ? null : elts.get(0); } - public static SQLElementList getAll(Class elemClass) throws ORMException { + public static > SQLElementList getAll(Class elemClass) throws ORMException { return getAll(elemClass, null, null, null, null); } - public static SQLElementList getAll(Class elemClass, SQLWhere where, + public static > SQLElementList getAll(Class elemClass, SQLWhere where, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException { initTable(elemClass); @@ -187,7 +187,7 @@ public final class ORM { if (offset != null) sql += " OFFSET " + offset; sql += ";"; - SQLElementList elmts = new SQLElementList(); + SQLElementList elmts = new SQLElementList(); PreparedStatement ps = connection.getNativeConnection().prepareStatement(sql); @@ -218,29 +218,18 @@ public final class ORM { } - private static T getElementInstance(ResultSet set, Class elemClass) throws ORMException { + private static > E getElementInstance(ResultSet set, Class elemClass) throws ORMException { try { - T instance = elemClass.getConstructor(int.class).newInstance(set.getInt("id")); + E instance = elemClass.getConstructor(int.class).newInstance(set.getInt("id")); int fieldCount = set.getMetaData().getColumnCount(); for (int c = 1; c <= fieldCount; c++) { String fieldName = set.getMetaData().getColumnLabel(c); - if (!instance.getFields().containsKey(fieldName)) continue; // ignore - // when - // field - // is - // present - // in - // database - // but - // not - // handled - // by - // SQLElement - // instance + if (!instance.getFields().containsKey(fieldName)) continue; + // ignore when field is present in database but not handled by SQLElement instance @SuppressWarnings("unchecked") - SQLField sqlField = (SQLField) instance.getFields().get(fieldName); + SQLField sqlField = (SQLField) instance.getFields().get(fieldName); if (sqlField.type.getJavaType().isEnum()) { // JDBC ne supporte pas les enums String enumStrValue = set.getString(c); diff --git a/src/fr/pandacube/java/util/db2/sql_tools/ORMException.java b/src/fr/pandacube/java/util/db/sql_tools/ORMException.java similarity index 87% rename from src/fr/pandacube/java/util/db2/sql_tools/ORMException.java rename to src/fr/pandacube/java/util/db/sql_tools/ORMException.java index 896c4ac..3ef668d 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/ORMException.java +++ b/src/fr/pandacube/java/util/db/sql_tools/ORMException.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; public class ORMException extends Exception { private static final long serialVersionUID = 1L; diff --git a/src/fr/pandacube/java/util/db2/sql_tools/ORMInitTableException.java b/src/fr/pandacube/java/util/db/sql_tools/ORMInitTableException.java similarity index 52% rename from src/fr/pandacube/java/util/db2/sql_tools/ORMInitTableException.java rename to src/fr/pandacube/java/util/db/sql_tools/ORMInitTableException.java index 6184a8a..30a9165 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/ORMInitTableException.java +++ b/src/fr/pandacube/java/util/db/sql_tools/ORMInitTableException.java @@ -1,13 +1,13 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; public class ORMInitTableException extends ORMException { private static final long serialVersionUID = 1L; - /* package */ ORMInitTableException(Class tableElem) { + /* package */ > ORMInitTableException(Class tableElem) { super("Error while initializing table " + tableElem.getName()); } - /* package */ ORMInitTableException(Class tableElem, Throwable t) { + /* package */ > ORMInitTableException(Class tableElem, Throwable t) { super("Error while initializing table " + tableElem.getName(), t); } diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLElement.java b/src/fr/pandacube/java/util/db/sql_tools/SQLElement.java similarity index 76% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLElement.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLElement.java index eaba34f..f5b20c4 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLElement.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLElement.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.sql.Connection; import java.sql.PreparedStatement; @@ -19,11 +19,11 @@ import java.util.logging.Level; import org.apache.commons.lang.builder.ToStringBuilder; import fr.pandacube.java.util.Log; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; -public abstract class SQLElement { +public abstract class SQLElement> { /** cache for fields for each subclass of SQLElement */ - /* package */ static final Map, SQLFieldMap> fieldsCache = new HashMap<>(); + /* package */ static final Map>, SQLFieldMap>> fieldsCache = new HashMap<>(); DBConnection db = ORM.getConnection(); @@ -31,25 +31,26 @@ public abstract class SQLElement { private int id; private final String tableName; - private final SQLFieldMap fields; + private final SQLFieldMap fields; - private final Map, Object> values; + private final Map, Object> values; /* package */ final Set modifiedSinceLastSave; + @SuppressWarnings("unchecked") public SQLElement() { tableName = tableName(); if (fieldsCache.get(getClass()) == null) { - fields = new SQLFieldMap(getClass()); + fields = new SQLFieldMap<>((Class)getClass()); // le champ id commun à toutes les tables fields.addField(new SQLField<>("id", SQLType.INT, false, true, 0)); generateFields(fields); - fieldsCache.put(getClass(), fields); + fieldsCache.put((Class)getClass(), fields); } else - fields = fieldsCache.get(getClass()); + fields = (SQLFieldMap) fieldsCache.get((Class)getClass()); values = new LinkedHashMap<>(fields.size()); modifiedSinceLastSave = new HashSet<>(fields.size()); @@ -61,7 +62,7 @@ public abstract class SQLElement { protected SQLElement(int id) { this(); @SuppressWarnings("unchecked") - SQLField idField = (SQLField) fields.get("id"); + SQLField idField = (SQLField) fields.get("id"); set(idField, id, false); this.id = id; stored = true; @@ -82,7 +83,7 @@ public abstract class SQLElement { else if (f.canBeNull || (f.autoIncrement && !stored)) set(f, null); } - protected void generateFields(SQLFieldMap listToFill) { + protected void generateFields(SQLFieldMap listToFill) { java.lang.reflect.Field[] declaredFields = getClass().getDeclaredFields(); for (java.lang.reflect.Field field : declaredFields) { @@ -92,7 +93,7 @@ public abstract class SQLElement { Object val = field.get(null); if (val == null || !(val instanceof SQLField)) continue; - listToFill.addField((SQLField) val); + listToFill.addField((SQLField) val); } catch (IllegalArgumentException | IllegalAccessException e) { Log.getLogger().log(Level.SEVERE, "Can't get value of static field " + field.toString(), e); } @@ -100,19 +101,19 @@ public abstract class SQLElement { } - /* package */ Map> getFields() { + /* package */ Map> getFields() { return Collections.unmodifiableMap(fields); } - public Map, Object> getValues() { + public Map, Object> getValues() { return Collections.unmodifiableMap(values); } - public void set(SQLField field, T value) { + public void set(SQLField field, T value) { set(field, value, true); } - /* package */ void set(SQLField sqlField, T value, boolean setModified) { + /* package */ void set(SQLField sqlField, T value, boolean setModified) { if (sqlField == null) throw new IllegalArgumentException("sqlField can't be null"); if (!fields.containsValue(sqlField)) throw new IllegalArgumentException(sqlField.name + " is not a SQLField of " + getClass().getName()); @@ -145,7 +146,7 @@ public abstract class SQLElement { } - public T get(SQLField field) { + public T get(SQLField field) { if (field == null) throw new IllegalArgumentException("field can't be null"); if (values.containsKey(field)) { @SuppressWarnings("unchecked") @@ -156,7 +157,7 @@ public abstract class SQLElement { + " does not exist or is not set"); } - public E getForeign(SQLFKField field) throws ORMException { + public > F getForeign(SQLFKField field) throws ORMException { T fkValue = get(field); if (fkValue == null) return null; return ORM.getFirst(field.getForeignElementClass(), @@ -167,23 +168,24 @@ public abstract class SQLElement { return values.keySet().containsAll(fields.values()); } - private Map, Object> getOnlyModifiedValues() { - Map, Object> modifiedValues = new LinkedHashMap<>(); + private Map, Object> getOnlyModifiedValues() { + Map, Object> modifiedValues = new LinkedHashMap<>(); values.forEach((k, v) -> { if (modifiedSinceLastSave.contains(k.name)) modifiedValues.put(k, v); }); return modifiedValues; } - public boolean isModified(SQLField field) { + public boolean isModified(SQLField field) { return modifiedSinceLastSave.contains(field.name); } + @SuppressWarnings("unchecked") public void save() throws ORMException { if (!isValidForSave()) throw new IllegalStateException(toString() + " has at least one undefined value and can't be saved."); - ORM.initTable(getClass()); + ORM.initTable((Class)getClass()); String toStringStatement = ""; try { @@ -193,18 +195,17 @@ public abstract class SQLElement { // restaurer l'ID au cas il aurait été changé à la main dans // values - @SuppressWarnings("unchecked") - SQLField idField = (SQLField) fields.get("id"); + SQLField idField = (SQLField) fields.get("id"); values.put(idField, id); modifiedSinceLastSave.remove("id"); - Map, Object> modifiedValues = getOnlyModifiedValues(); + Map, Object> modifiedValues = getOnlyModifiedValues(); if (modifiedValues.isEmpty()) return; String sql = ""; List psValues = new ArrayList<>(); - for (Map.Entry, Object> entry : modifiedValues.entrySet()) { + for (Map.Entry, Object> entry : modifiedValues.entrySet()) { sql += entry.getKey().name + " = ? ,"; if (entry.getKey().type.getJavaType().isEnum()) // prise en // charge @@ -244,7 +245,7 @@ public abstract class SQLElement { List psValues = new ArrayList<>(); boolean first = true; - for (Map.Entry, Object> entry : values.entrySet()) { + for (Map.Entry, Object> entry : values.entrySet()) { if (!first) { concat_vals += ","; concat_fields += ","; @@ -305,8 +306,8 @@ public abstract class SQLElement { } @SuppressWarnings("unchecked") - public SQLField getFieldId() { - return (SQLField) getFields().get("id"); + public SQLField getFieldId() { + return (SQLField) fields.get("id"); } public void delete() throws ORMException { @@ -340,21 +341,24 @@ public abstract class SQLElement { values.forEach((k, v) -> modifiedSinceLastSave.add(k.name)); } - protected static class SQLFieldMap extends LinkedHashMap> { + protected static class SQLFieldMap> extends LinkedHashMap> { private static final long serialVersionUID = 1L; - private final Class sqlElemClass; + private final Class sqlElemClass; - private SQLFieldMap(Class elemClass) { + private SQLFieldMap(Class elemClass) { sqlElemClass = elemClass; } - private void addField(SQLField f) { + private void addField(SQLField f) { if (f == null) return; + if (!sqlElemClass.equals(f.getSQLElementType())) return; if (containsKey(f.name)) throw new IllegalArgumentException( "SQLField " + f.name + " already exist in " + sqlElemClass.getName()); - f.setSQLElementType(sqlElemClass); - put(f.name, f); + @SuppressWarnings("unchecked") + SQLField checkedF = (SQLField) f; + checkedF.setSQLElementType(sqlElemClass); + put(checkedF.name, checkedF); } } @@ -363,7 +367,7 @@ public abstract class SQLElement { public String toString() { ToStringBuilder b = new ToStringBuilder(this); - for (SQLField f : fields.values()) + for (SQLField f : fields.values()) try { b.append(f.name, get(f)); } catch (IllegalArgumentException e) { @@ -372,5 +376,18 @@ public abstract class SQLElement { return b.toString(); } + + @Override + public boolean equals(Object o) { + if (o == null || !(getClass().isInstance(o))) return false; + SQLElement oEl = (SQLElement) o; + if (oEl.getId() == null) return false; + return oEl.getId().equals(getId()); + } + + @Override + public int hashCode() { + return super.hashCode(); + } } diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLElementList.java b/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java similarity index 91% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLElementList.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java index 988f2e3..64e423f 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLElementList.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -13,10 +13,10 @@ import fr.pandacube.java.util.Log; * * @param */ -public class SQLElementList extends ArrayList { +public class SQLElementList> extends ArrayList { private static final long serialVersionUID = 1L; - private final Map, Object> modifiedValues = new LinkedHashMap<>(); + private final Map, Object> modifiedValues = new LinkedHashMap<>(); @Override public synchronized boolean add(E e) { @@ -37,11 +37,10 @@ public class SQLElementList extends ArrayList { * @param field le champs à modifier * @param value la valeur à lui appliquer */ - public synchronized void setCommon(SQLField field, T value) { + public synchronized void setCommon(SQLField field, T value) { if (field != null && field.name == "id") throw new IllegalArgumentException("Can't modify id field in a SQLElementList"); - @SuppressWarnings("unchecked") - + Class elemClass = (Class) field.getSQLElementType(); try { E emptyElement = elemClass.newInstance(); @@ -76,7 +75,7 @@ public class SQLElementList extends ArrayList { String sqlSet = ""; List psValues = new ArrayList<>(); - for (Map.Entry, Object> entry : modifiedValues.entrySet()) { + for (Map.Entry, Object> entry : modifiedValues.entrySet()) { sqlSet += entry.getKey().name + " = ? ,"; if (entry.getKey().type.getJavaType().isEnum()) // prise en charge // enum (non prise diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLFKField.java b/src/fr/pandacube/java/util/db/sql_tools/SQLFKField.java similarity index 51% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLFKField.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLFKField.java index f90cf74..4cc1f89 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLFKField.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLFKField.java @@ -1,47 +1,47 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import fr.pandacube.java.util.Log; -public class SQLFKField extends SQLField { +public class SQLFKField, T, F extends SQLElement> extends SQLField { - private SQLField sqlForeignKeyField; - private Class sqlForeignKeyElement; + private SQLField sqlForeignKeyField; + private Class sqlForeignKeyElemClass; - public SQLFKField(String n, SQLType t, boolean nul, Class fkEl, SQLField fkF) { + public SQLFKField(String n, SQLType t, boolean nul, SQLField fkF) { super(n, t, nul); - construct(fkEl, fkF); + construct(fkF); } - public SQLFKField(String n, SQLType t, boolean nul, T deflt, Class fkEl, SQLField fkF) { + public SQLFKField(String n, SQLType t, boolean nul, T deflt, SQLField fkF) { super(n, t, nul, deflt); - construct(fkEl, fkF); + construct(fkF); } - public static SQLFKField idFK(String n, SQLType t, boolean nul, - Class fkEl) { + public static , F extends SQLElement> SQLFKField idFK(String n, SQLType t, boolean nul, + Class fkEl) { if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null"); try { - return new SQLFKField<>(n, t, nul, fkEl, ORM.getSQLIdField(fkEl)); + return new SQLFKField<>(n, t, nul, ORM.getSQLIdField(fkEl)); } catch (ORMInitTableException e) { Log.severe("Can't create Foreign key Field called '" + n + "'", e); return null; } } - public static SQLFKField idFKField(String n, SQLType t, boolean nul, - Integer deflt, Class fkEl) { + public static , F extends SQLElement> SQLFKField idFKField(String n, SQLType t, boolean nul, + Integer deflt, Class fkEl) { if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null"); try { - return new SQLFKField<>(n, t, nul, deflt, fkEl, ORM.getSQLIdField(fkEl)); + return new SQLFKField<>(n, t, nul, deflt, ORM.getSQLIdField(fkEl)); } catch (ORMInitTableException e) { Log.severe("Can't create Foreign key Field called '" + n + "'", e); return null; } } - private void construct(Class fkEl, SQLField fkF) { - if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null"); + private void construct(SQLField fkF) { if (fkF == null) throw new IllegalArgumentException("foreignKeyField can't be null"); + Class fkEl = fkF.getSQLElementType(); try { ORM.initTable(fkEl); } catch (ORMInitTableException e) { @@ -53,15 +53,15 @@ public class SQLFKField extends SQLField { if (!type.equals(fkF.type)) throw new IllegalArgumentException("foreignKeyField and current Field must have the same SQLType"); sqlForeignKeyField = fkF; - sqlForeignKeyElement = fkEl; + sqlForeignKeyElemClass = fkEl; } - public SQLField getForeignField() { + public SQLField getForeignField() { return sqlForeignKeyField; } - public Class getForeignElementClass() { - return sqlForeignKeyElement; + public Class getForeignElementClass() { + return sqlForeignKeyElemClass; } } diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLField.java b/src/fr/pandacube/java/util/db/sql_tools/SQLField.java similarity index 86% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLField.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLField.java index 8093221..2388d2f 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLField.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLField.java @@ -1,13 +1,13 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.util.ArrayList; import java.util.List; import javafx.util.Pair; -public class SQLField { +public class SQLField, T> { - private Class sqlElemClass; + private Class sqlElemClass; public final String name; public final SQLType type; public final boolean canBeNull; @@ -42,11 +42,11 @@ public class SQLField { + ((defaultValue == null || autoIncrement) ? "" : " DEFAULT ?"), params); } - /* package */ void setSQLElementType(Class elemClass) { + /* package */ void setSQLElementType(Class elemClass) { sqlElemClass = elemClass; } - public Class getSQLElementType() { + public Class getSQLElementType() { return sqlElemClass; } @@ -66,7 +66,7 @@ public class SQLField { public boolean equals(Object obj) { if (obj == null) return false; if (!(obj instanceof SQLField)) return false; - SQLField f = (SQLField) obj; + SQLField f = (SQLField) obj; if (!f.name.equals(name)) return false; if (!f.sqlElemClass.equals(sqlElemClass)) return false; return true; diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLOrderBy.java b/src/fr/pandacube/java/util/db/sql_tools/SQLOrderBy.java similarity index 83% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLOrderBy.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLOrderBy.java index 68d0f04..0b02526 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLOrderBy.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLOrderBy.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.util.ArrayList; import java.util.List; @@ -19,7 +19,7 @@ public class SQLOrderBy { * @param d le sens de tri (croissant ASC ou décroissant DESC) * @return l'objet courant (permet de chainer les ajouts de champs) */ - public SQLOrderBy addField(SQLField field, Direction d) { + public SQLOrderBy addField(SQLField field, Direction d) { orderByFields.add(new OBField(field, d)); return this; } @@ -31,7 +31,7 @@ public class SQLOrderBy { * @param field le champ SQL à ordonner dans l'ordre croissant ASC * @return l'objet courant (permet de chainer les ajouts de champs) */ - public SQLOrderBy addField(SQLField field) { + public SQLOrderBy addField(SQLField field) { return addField(field, Direction.ASC); } @@ -52,10 +52,10 @@ public class SQLOrderBy { } private class OBField { - public final SQLField field; + public final SQLField field; public final Direction direction; - public OBField(SQLField f, Direction d) { + public OBField(SQLField f, Direction d) { field = f; direction = d; } diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLType.java b/src/fr/pandacube/java/util/db/sql_tools/SQLType.java similarity index 98% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLType.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLType.java index cba255e..5ef9927 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLType.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLType.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.sql.Date; diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhere.java b/src/fr/pandacube/java/util/db/sql_tools/SQLWhere.java similarity index 82% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLWhere.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLWhere.java index 2233b67..8d88419 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhere.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLWhere.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.util.List; diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhereChain.java b/src/fr/pandacube/java/util/db/sql_tools/SQLWhereChain.java similarity index 96% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLWhereChain.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLWhereChain.java index d55ff7b..7ae68f5 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhereChain.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLWhereChain.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.util.ArrayList; import java.util.List; diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhereComp.java b/src/fr/pandacube/java/util/db/sql_tools/SQLWhereComp.java similarity index 89% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLWhereComp.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLWhereComp.java index 497772e..a2f63a6 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhereComp.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLWhereComp.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.util.ArrayList; import java.util.List; @@ -7,7 +7,7 @@ import javafx.util.Pair; public class SQLWhereComp extends SQLWhere { - private SQLField left; + private SQLField left; private SQLComparator comp; private Object right; @@ -18,7 +18,7 @@ public class SQLWhereComp extends SQLWhere { * @param c the comparison operator, can't be null * @param r the value at right of the comparison operator. Can't be null */ - public SQLWhereComp(SQLField l, SQLComparator c, T r) { + public SQLWhereComp(SQLField l, SQLComparator c, T r) { if (l == null || r == null || c == null) throw new IllegalArgumentException("All arguments for SQLWhereComp constructor can't be null"); left = l; diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhereLike.java b/src/fr/pandacube/java/util/db/sql_tools/SQLWhereLike.java similarity index 82% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLWhereLike.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLWhereLike.java index eabf7b9..f9a8092 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhereLike.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLWhereLike.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.util.ArrayList; import java.util.List; @@ -7,7 +7,7 @@ import javafx.util.Pair; public class SQLWhereLike extends SQLWhere { - private SQLField field; + private SQLField field; private String likeExpr; /** @@ -16,7 +16,7 @@ public class SQLWhereLike extends SQLWhere { * @param f the field at left of the LIKE keyword. Can't be null * @param like the like expression. */ - public SQLWhereLike(SQLField f, String like) { + public SQLWhereLike(SQLField f, String like) { if (f == null || like == null) throw new IllegalArgumentException("All arguments for SQLWhereLike constructor can't be null"); field = f; diff --git a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhereNull.java b/src/fr/pandacube/java/util/db/sql_tools/SQLWhereNull.java similarity index 87% rename from src/fr/pandacube/java/util/db2/sql_tools/SQLWhereNull.java rename to src/fr/pandacube/java/util/db/sql_tools/SQLWhereNull.java index 37c424b..0e6ae6b 100644 --- a/src/fr/pandacube/java/util/db2/sql_tools/SQLWhereNull.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLWhereNull.java @@ -1,4 +1,4 @@ -package fr.pandacube.java.util.db2.sql_tools; +package fr.pandacube.java.util.db.sql_tools; import java.util.ArrayList; import java.util.List; @@ -9,7 +9,7 @@ import javafx.util.Pair; public class SQLWhereNull extends SQLWhere { - private SQLField fild; + private SQLField fild; private boolean nulll; /** @@ -19,7 +19,7 @@ public class SQLWhereNull extends SQLWhere { * @param isNull true if we want to ckeck if "IS NULL", or false to check if * "IS NOT NULL" */ - public SQLWhereNull(SQLField field, boolean isNull) { + public SQLWhereNull(SQLField field, boolean isNull) { if (field == null) throw new IllegalArgumentException("field can't be null"); if (!field.canBeNull) Log.getLogger().log(Level.WARNING, "Useless : Trying to check IS [NOT] NULL on the field " + field.getSQLElementType().getName() + "#" diff --git a/src/fr/pandacube/java/util/db2/SQLContact.java b/src/fr/pandacube/java/util/db2/SQLContact.java deleted file mode 100644 index 176cffd..0000000 --- a/src/fr/pandacube/java/util/db2/SQLContact.java +++ /dev/null @@ -1,43 +0,0 @@ -package fr.pandacube.java.util.db2; - -import java.util.UUID; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLContact extends SQLElement { - - public SQLContact() { - super(); - } - - public SQLContact(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_contact"; - } - - public static final SQLField time = new SQLField<>("time", SQLType.INT, false); - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), true, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField userName = new SQLField<>("userName", SQLType.VARCHAR(50), true); - public static final SQLField userMail = new SQLField<>("userMail", SQLType.VARCHAR(50), true); - public static final SQLField titre = new SQLField<>("titre", SQLType.VARCHAR(100), false); - public static final SQLField texte = new SQLField<>("texte", SQLType.TEXT, false); - public static final SQLField hidden = new SQLField<>("hidden", SQLType.BOOLEAN, false, (Boolean) false); - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID pName) { - set(playerId, (pName == null) ? (String) null : pName.toString()); - } - -} diff --git a/src/fr/pandacube/java/util/db2/SQLForumCategorie.java b/src/fr/pandacube/java/util/db2/SQLForumCategorie.java deleted file mode 100644 index cb01872..0000000 --- a/src/fr/pandacube/java/util/db2/SQLForumCategorie.java +++ /dev/null @@ -1,25 +0,0 @@ -package fr.pandacube.java.util.db2; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLForumCategorie extends SQLElement { - - public SQLForumCategorie() { - super(); - } - - public SQLForumCategorie(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_forum_categorie"; - } - - public static final SQLField nom = new SQLField<>("nom", SQLType.VARCHAR(100), false); - public static final SQLField ordre = new SQLField<>("ordre", SQLType.INT, false); - -} diff --git a/src/fr/pandacube/java/util/db2/SQLForumForum.java b/src/fr/pandacube/java/util/db2/SQLForumForum.java deleted file mode 100644 index f32388e..0000000 --- a/src/fr/pandacube/java/util/db2/SQLForumForum.java +++ /dev/null @@ -1,36 +0,0 @@ -package fr.pandacube.java.util.db2; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLForumForum extends SQLElement { - - public SQLForumForum() { - super(); - } - - public SQLForumForum(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_forum_forum"; - } - - public static final SQLFKField catId = SQLFKField.idFK("catId", SQLType.INT, false, - SQLForumCategorie.class); - public static final SQLField nom = new SQLField<>("nom", SQLType.VARCHAR(100), false); - public static final SQLField description = new SQLField<>("description", SQLType.TEXT, false); - public static final SQLField ordre = new SQLField<>("ordre", SQLType.INT, false); - public static final SQLField authView = new SQLField<>("authView", SQLType.INT, false); - public static final SQLField authPost = new SQLField<>("authPost", SQLType.INT, false); - public static final SQLField authThread = new SQLField<>("authThread", SQLType.INT, false); - public static final SQLField authAnchored = new SQLField<>("authAnchored", SQLType.INT, false); - public static final SQLField authModo = new SQLField<>("authModo", SQLType.INT, false); - public static final SQLField nbThreads = new SQLField<>("nbThreads", SQLType.INT, false); - public static final SQLField nbMessages = new SQLField<>("nbMessages", SQLType.INT, false); - -} diff --git a/src/fr/pandacube/java/util/db2/SQLForumPost.java b/src/fr/pandacube/java/util/db2/SQLForumPost.java deleted file mode 100644 index e4bb779..0000000 --- a/src/fr/pandacube/java/util/db2/SQLForumPost.java +++ /dev/null @@ -1,41 +0,0 @@ -package fr.pandacube.java.util.db2; - -import java.util.UUID; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLForumPost extends SQLElement { - - public SQLForumPost() { - super(); - } - - public SQLForumPost(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_forum_post"; - } - - public static final SQLField createur = new SQLField<>("createur", SQLType.CHAR(36), false); - public static final SQLField texte = new SQLField<>("texte", SQLType.TEXT, false); - public static final SQLField time = new SQLField<>("time", SQLType.INT, false); - public static final SQLFKField threadId = SQLFKField.idFK("threadId", SQLType.INT, false, - SQLForumThread.class); - public static final SQLField moderated = new SQLField<>("moderated", SQLType.BOOLEAN, false); - - public UUID getCreateurId() { - String id = get(createur); - return (id == null) ? null : UUID.fromString(id); - } - - public void setCreateurId(UUID pName) { - set(createur, (pName == null) ? (String) null : pName.toString()); - } - -} diff --git a/src/fr/pandacube/java/util/db2/SQLForumThread.java b/src/fr/pandacube/java/util/db2/SQLForumThread.java deleted file mode 100644 index c50c4e2..0000000 --- a/src/fr/pandacube/java/util/db2/SQLForumThread.java +++ /dev/null @@ -1,45 +0,0 @@ -package fr.pandacube.java.util.db2; - -import java.util.UUID; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLForumThread extends SQLElement { - - public SQLForumThread() { - super(); - } - - public SQLForumThread(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_forum_thread"; - } - - public static final SQLFKField forumId = SQLFKField.idFK("forumId", SQLType.INT, false, - SQLForumForum.class); - public static final SQLField titre = new SQLField<>("titre", SQLType.VARCHAR(60), false); - public static final SQLFKField createur = new SQLFKField<>("createur", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField vu = new SQLField<>("vu", SQLType.INT, false); - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLField anchored = new SQLField<>("anchored", SQLType.BOOLEAN, false); - public static final SQLField locked = new SQLField<>("locked", SQLType.BOOLEAN, false); - public static final SQLField nbMessages = new SQLField<>("nbMessages", SQLType.INT, false); - - public UUID getCreateurId() { - String id = get(createur); - return (id == null) ? null : UUID.fromString(id); - } - - public void setCreateurId(UUID pName) { - set(createur, (pName == null) ? (String) null : pName.toString()); - } - -} diff --git a/src/fr/pandacube/java/util/db2/SQLLoginHistory.java b/src/fr/pandacube/java/util/db2/SQLLoginHistory.java deleted file mode 100644 index 5156b7a..0000000 --- a/src/fr/pandacube/java/util/db2/SQLLoginHistory.java +++ /dev/null @@ -1,47 +0,0 @@ -package fr.pandacube.java.util.db2; - -import java.util.UUID; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLLoginHistory extends SQLElement { - - public SQLLoginHistory() { - super(); - } - - public SQLLoginHistory(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_login_history"; - } - - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField ip = new SQLField<>("ip", SQLType.VARCHAR(128), true); - public static final SQLField actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class), - false); - public static final SQLField nbOnline = new SQLField<>("nbOnline", SQLType.INT, false); - public static final SQLField playerName = new SQLField<>("playerName", SQLType.VARCHAR(16), true); - public static final SQLField minecraftVersion = new SQLField<>("minecraftVersion", SQLType.INT, false, 0); - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID pName) { - set(playerId, (pName == null) ? (String) null : pName.toString()); - } - - public enum ActionType { - LOGIN, LOGOUT - } -} diff --git a/src/fr/pandacube/java/util/db2/SQLMPGroup.java b/src/fr/pandacube/java/util/db2/SQLMPGroup.java deleted file mode 100644 index 6b25376..0000000 --- a/src/fr/pandacube/java/util/db2/SQLMPGroup.java +++ /dev/null @@ -1,41 +0,0 @@ -package fr.pandacube.java.util.db2; - -import fr.pandacube.java.util.db2.sql_tools.ORM; -import fr.pandacube.java.util.db2.sql_tools.ORMException; -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLElementList; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy; -import fr.pandacube.java.util.db2.sql_tools.SQLType; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator; - -public class SQLMPGroup extends SQLElement { - - public SQLMPGroup() { - super(); - } - - public SQLMPGroup(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_mp_group"; - } - - public static final SQLField groupName = new SQLField<>("groupName", SQLType.VARCHAR(16), false); - - public SQLElementList getGroupUsers() throws ORMException { - return ORM.getAll(SQLMPGroupUser.class, new SQLWhereComp(SQLMPGroupUser.groupId, SQLComparator.EQ, getId()), - new SQLOrderBy().addField(ORM.getSQLIdField(SQLMPGroupUser.class)), null, null); - } - - public static SQLMPGroup getByName(String name) throws ORMException { - if (name == null) return null; - - return ORM.getFirst(SQLMPGroup.class, new SQLWhereComp(groupName, SQLComparator.EQ, name), null); - } - -} diff --git a/src/fr/pandacube/java/util/db2/SQLModoHistory.java b/src/fr/pandacube/java/util/db2/SQLModoHistory.java deleted file mode 100644 index e428916..0000000 --- a/src/fr/pandacube/java/util/db2/SQLModoHistory.java +++ /dev/null @@ -1,57 +0,0 @@ -package fr.pandacube.java.util.db2; - -import java.util.UUID; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLModoHistory extends SQLElement { - - public SQLModoHistory() { - super(); - } - - public SQLModoHistory(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_modo_history"; - } - - public static final SQLFKField modoId = new SQLFKField<>("modoId", SQLType.CHAR(36), true, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class), - false); - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField value = new SQLField<>("value", SQLType.BIGINT, true); - public static final SQLField message = new SQLField<>("message", SQLType.VARCHAR(512), false); - - public UUID getModoId() { - String id = get(modoId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setModoId(UUID pName) { - set(modoId, (pName == null) ? (String) null : pName.toString()); - } - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID pName) { - set(playerId, (pName == null) ? (String) null : pName.toString()); - } - - public enum ActionType { - BAN, UNBAN, MUTE, UNMUTE, REPORT, KICK - } - -} diff --git a/src/fr/pandacube/java/util/db2/SQLOnlineshopHistory.java b/src/fr/pandacube/java/util/db2/SQLOnlineshopHistory.java deleted file mode 100644 index 3f78f57..0000000 --- a/src/fr/pandacube/java/util/db2/SQLOnlineshopHistory.java +++ /dev/null @@ -1,65 +0,0 @@ -package fr.pandacube.java.util.db2; - -import java.util.UUID; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLOnlineshopHistory extends SQLElement { - - public SQLOnlineshopHistory() { - super(); - } - - public SQLOnlineshopHistory(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_onlineshop_history"; - } - - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLField transactionId = new SQLField<>("transactionId", SQLType.VARCHAR(255), true); - public static final SQLField sourceType = new SQLField<>("sourceType", SQLType.ENUM(SourceType.class), - false); - public static final SQLFKField sourcePlayerId = new SQLFKField<>("sourcePlayerId", - SQLType.CHAR(36), true, SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField sourceQuantity = new SQLField<>("sourceQuantity", SQLType.DOUBLE, false); - public static final SQLField sourceName = new SQLField<>("sourceName", SQLType.VARCHAR(64), false); - public static final SQLField destType = new SQLField<>("destType", SQLType.ENUM(DestType.class), false); - public static final SQLFKField destPlayerId = new SQLFKField<>("destPlayerId", SQLType.CHAR(36), - false, SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField destQuantity = new SQLField<>("destQuantity", SQLType.DOUBLE, false); - public static final SQLField destName = new SQLField<>("destName", SQLType.VARCHAR(64), false); - - public UUID getSourcePlayerId() { - String id = get(sourcePlayerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setSourcePlayerId(UUID pName) { - set(sourcePlayerId, (pName == null) ? (String) null : pName.toString()); - } - - public UUID getDestPlayerId() { - String id = get(destPlayerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setDestPlayerId(UUID pName) { - set(destPlayerId, (pName == null) ? (String) null : pName.toString()); - } - - public static enum SourceType { - REAL_MONEY, BAMBOU - } - - public static enum DestType { - BAMBOU, GRADE - } - -} diff --git a/src/fr/pandacube/java/util/db2/SQLPlayer.java b/src/fr/pandacube/java/util/db2/SQLPlayer.java deleted file mode 100644 index 8274fbc..0000000 --- a/src/fr/pandacube/java/util/db2/SQLPlayer.java +++ /dev/null @@ -1,91 +0,0 @@ -package fr.pandacube.java.util.db2; - -import java.sql.Date; -import java.util.UUID; - -import fr.pandacube.java.util.db2.sql_tools.ORM; -import fr.pandacube.java.util.db2.sql_tools.ORMException; -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator; - -public class SQLPlayer extends SQLElement { - - public SQLPlayer() { - super(); - } - - public SQLPlayer(int id) { - super(id); - } - - /* - * Nom de la table - */ - @Override - protected String tableName() { - return "pandacube_player"; - } - - /* - * Champs de la table - */ - public static final SQLField playerId = new SQLField<>("playerId", SQLType.CHAR(36), false); - public static final SQLField token = new SQLField<>("token", SQLType.CHAR(36), true); - public static final SQLField mailCheck = new SQLField<>("mailCheck", SQLType.VARCHAR(255), true); - public static final SQLField password = new SQLField<>("password", SQLType.VARCHAR(255), true); - public static final SQLField mail = new SQLField<>("mail", SQLType.VARCHAR(255), true); - public static final SQLField playerDisplayName = new SQLField<>("playerDisplayName", SQLType.VARCHAR(255), - false); - public static final SQLField firstTimeInGame = new SQLField<>("firstTimeInGame", SQLType.BIGINT, false, 0L); - public static final SQLField timeWebRegister = new SQLField<>("timeWebRegister", SQLType.BIGINT, true); - public static final SQLField lastTimeInGame = new SQLField<>("lastTimeInGame", SQLType.BIGINT, true); - public static final SQLField lastWebActivity = new SQLField<>("lastWebActivity", SQLType.BIGINT, false, 0L); - public static final SQLField onlineInServer = new SQLField<>("onlineInServer", SQLType.VARCHAR(32), true); - public static final SQLField skinURL = new SQLField<>("skinURL", SQLType.VARCHAR(255), true); - public static final SQLField isVanish = new SQLField<>("isVanish", SQLType.BOOLEAN, false, - (Boolean) false); - public static final SQLField birthday = new SQLField<>("birthday", SQLType.DATE, true); - public static final SQLField lastYearCelebBday = new SQLField<>("lastYearCelebratedBirthday", SQLType.INT, - false, 0); - public static final SQLField banTimeout = new SQLField<>("banTimeout", SQLType.BIGINT, true); - public static final SQLField muteTimeout = new SQLField<>("muteTimeout", SQLType.BIGINT, true); - public static final SQLField isWhitelisted = new SQLField<>("isWhitelisted", SQLType.BOOLEAN, false, - (Boolean) false); - public static final SQLField bambou = new SQLField<>("bambou", SQLType.BIGINT, false, 0L); - public static final SQLField grade = new SQLField<>("grade", SQLType.VARCHAR(36), false, "default"); - - /* - * Getteurs spécifique (encapsulation) - */ - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public UUID getToken() { - String id = get(token); - return (id == null) ? null : UUID.fromString(id); - } - - /* - * Setteurs spécifique (encapsulation) - */ - - public void setPlayerId(UUID pName) { - set(playerId, (pName == null) ? (String) null : pName.toString()); - } - - public void setToken(UUID t) { - set(token, (t == null) ? (String) null : t.toString()); - } - - public static SQLPlayer getPlayerFromUUID(UUID playerId) throws ORMException { - return ORM.getFirst(SQLPlayer.class, - new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, playerId.toString()), null); - } - -} diff --git a/src/fr/pandacube/java/util/db2/SQLShopStock.java b/src/fr/pandacube/java/util/db2/SQLShopStock.java deleted file mode 100644 index c9b61a7..0000000 --- a/src/fr/pandacube/java/util/db2/SQLShopStock.java +++ /dev/null @@ -1,27 +0,0 @@ -package fr.pandacube.java.util.db2; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLShopStock extends SQLElement { - - public SQLShopStock() { - super(); - } - - public SQLShopStock(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_shop_stock"; - } - - public static final SQLField material = new SQLField<>("material", SQLType.VARCHAR(50), false); - public static final SQLField damage = new SQLField<>("damage", SQLType.INT, false, 0); - public static final SQLField quantity = new SQLField<>("quantity", SQLType.DOUBLE, false); - public static final SQLField server = new SQLField<>("server", SQLType.VARCHAR(50), false); - -} diff --git a/src/fr/pandacube/java/util/db2/SQLStaffTicket.java b/src/fr/pandacube/java/util/db2/SQLStaffTicket.java deleted file mode 100644 index b1bf76f..0000000 --- a/src/fr/pandacube/java/util/db2/SQLStaffTicket.java +++ /dev/null @@ -1,50 +0,0 @@ -package fr.pandacube.java.util.db2; - -import java.util.UUID; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLStaffTicket extends SQLElement { - - public SQLStaffTicket() { - super(); - } - - public SQLStaffTicket(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_staff_ticket"; - } - - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField message = new SQLField<>("message", SQLType.VARCHAR(1024), false); - public static final SQLField creationTime = new SQLField<>("creationTime", SQLType.BIGINT, false); - public static final SQLFKField staffPlayerId = new SQLFKField<>("staffPlayerId", - SQLType.CHAR(36), true, SQLPlayer.class, SQLPlayer.playerId); - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID id) { - set(playerId, (id == null) ? null : id.toString()); - } - - public UUID getstaffPlayerId() { - String id = get(staffPlayerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setstaffPlayerId(UUID id) { - set(staffPlayerId, (id == null) ? null : id.toString()); - } - -} diff --git a/src/fr/pandacube/java/util/db2/SQLStaticPages.java b/src/fr/pandacube/java/util/db2/SQLStaticPages.java deleted file mode 100644 index 8dbedc8..0000000 --- a/src/fr/pandacube/java/util/db2/SQLStaticPages.java +++ /dev/null @@ -1,28 +0,0 @@ -package fr.pandacube.java.util.db2; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLStaticPages extends SQLElement { - - public SQLStaticPages() { - super(); - } - - public SQLStaticPages(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_static_pages"; - } - - public static final SQLField permalink = new SQLField<>("permalink", SQLType.VARCHAR(128), false); - public static final SQLField titreHead = new SQLField<>("titreHead", SQLType.VARCHAR(128), false); - public static final SQLField titreH2 = new SQLField<>("titreH2", SQLType.VARCHAR(255), false); - public static final SQLField texte = new SQLField<>("texte", SQLType.TEXT, false); - public static final SQLField permissions = new SQLField<>("permissions", SQLType.VARCHAR(255), true); - -} diff --git a/src/fr/pandacube/java/util/db2/SQLUUIDPlayer.java b/src/fr/pandacube/java/util/db2/SQLUUIDPlayer.java deleted file mode 100644 index c5ac026..0000000 --- a/src/fr/pandacube/java/util/db2/SQLUUIDPlayer.java +++ /dev/null @@ -1,38 +0,0 @@ -package fr.pandacube.java.util.db2; - -import java.util.UUID; - -import fr.pandacube.java.util.db2.sql_tools.SQLElement; -import fr.pandacube.java.util.db2.sql_tools.SQLFKField; -import fr.pandacube.java.util.db2.sql_tools.SQLField; -import fr.pandacube.java.util.db2.sql_tools.SQLType; - -public class SQLUUIDPlayer extends SQLElement { - - public SQLUUIDPlayer() { - super(); - } - - public SQLUUIDPlayer(int id) { - super(id); - } - - @Override - protected String tableName() { - return "bungeeperms_uuidplayer"; - } - - public static final SQLFKField uuid = new SQLFKField<>("uuid", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField player = new SQLField<>("player", SQLType.VARCHAR(16), false); - - public UUID getUUID() { - String id = get(uuid); - return (id == null) ? null : UUID.fromString(id); - } - - public void setUUID(UUID id) { - set(uuid, (id == null) ? null : id.toString()); - } - -}