Refactoring de l'ORM : package 'db2' -> 'db' + typage plus précis des SQLField

This commit is contained in:
Marc Baloup 2016-07-15 02:05:22 +02:00
parent 724e9ecd6c
commit 805ff052d3
47 changed files with 850 additions and 845 deletions

View File

@ -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;
/*

View File

@ -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<SQLContact> {
public SQLContact() {
super();
}
public SQLContact(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_contact";
}
public static final SQLField<SQLContact, Integer> time = new SQLField<>("time", SQLType.INT, false);
public static final SQLFKField<SQLContact, String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), true,
SQLPlayer.playerId);
public static final SQLField<SQLContact, String> userName = new SQLField<>("userName", SQLType.VARCHAR(50), true);
public static final SQLField<SQLContact, String> userMail = new SQLField<>("userMail", SQLType.VARCHAR(50), true);
public static final SQLField<SQLContact, String> titre = new SQLField<>("titre", SQLType.VARCHAR(100), false);
public static final SQLField<SQLContact, String> texte = new SQLField<>("texte", SQLType.TEXT, false);
public static final SQLField<SQLContact, Boolean> 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());
}
}

View File

@ -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<SQLForumCategorie> {
public SQLForumCategorie() {
super();
}
public SQLForumCategorie(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_forum_categorie";
}
public static final SQLField<SQLForumCategorie, String> nom = new SQLField<>("nom", SQLType.VARCHAR(100), false);
public static final SQLField<SQLForumCategorie, Integer> ordre = new SQLField<>("ordre", SQLType.INT, false);
}

View File

@ -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<SQLForumForum> {
public SQLForumForum() {
super();
}
public SQLForumForum(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_forum_forum";
}
public static final SQLFKField<SQLForumForum, Integer, SQLForumCategorie> catId = SQLFKField.idFK("catId", SQLType.INT, false,
SQLForumCategorie.class);
public static final SQLField<SQLForumForum, String> nom = new SQLField<>("nom", SQLType.VARCHAR(100), false);
public static final SQLField<SQLForumForum, String> description = new SQLField<>("description", SQLType.TEXT, false);
public static final SQLField<SQLForumForum, Integer> ordre = new SQLField<>("ordre", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authView = new SQLField<>("authView", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authPost = new SQLField<>("authPost", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authThread = new SQLField<>("authThread", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authAnchored = new SQLField<>("authAnchored", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authModo = new SQLField<>("authModo", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> nbThreads = new SQLField<>("nbThreads", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> nbMessages = new SQLField<>("nbMessages", SQLType.INT, false);
}

View File

@ -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<SQLForumPost> {
public SQLForumPost() {
super();
}
public SQLForumPost(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_forum_post";
}
public static final SQLField<SQLForumPost, String> createur = new SQLField<>("createur", SQLType.CHAR(36), false);
public static final SQLField<SQLForumPost, String> texte = new SQLField<>("texte", SQLType.TEXT, false);
public static final SQLField<SQLForumPost, Integer> time = new SQLField<>("time", SQLType.INT, false);
public static final SQLFKField<SQLForumPost, Integer, SQLForumThread> threadId = SQLFKField.idFK("threadId", SQLType.INT, false,
SQLForumThread.class);
public static final SQLField<SQLForumPost, Boolean> 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());
}
}

View File

@ -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<SQLForumThread> {
public SQLForumThread() {
super();
}
public SQLForumThread(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_forum_thread";
}
public static final SQLFKField<SQLForumThread, Integer, SQLForumForum> forumId = SQLFKField.idFK("forumId", SQLType.INT, false,
SQLForumForum.class);
public static final SQLField<SQLForumThread, String> titre = new SQLField<>("titre", SQLType.VARCHAR(60), false);
public static final SQLFKField<SQLForumThread, String, SQLPlayer> createur = new SQLFKField<>("createur", SQLType.CHAR(36), false,
SQLPlayer.playerId);
public static final SQLField<SQLForumThread, Integer> vu = new SQLField<>("vu", SQLType.INT, false);
public static final SQLField<SQLForumThread, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLField<SQLForumThread, Boolean> anchored = new SQLField<>("anchored", SQLType.BOOLEAN, false);
public static final SQLField<SQLForumThread, Boolean> locked = new SQLField<>("locked", SQLType.BOOLEAN, false);
public static final SQLField<SQLForumThread, Integer> 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());
}
}

View File

@ -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<SQLLoginHistory> {
public SQLLoginHistory() {
super();
}
public SQLLoginHistory(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_login_history";
}
public static final SQLField<SQLLoginHistory, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLFKField<SQLLoginHistory, String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.playerId);
public static final SQLField<SQLLoginHistory, String> ip = new SQLField<>("ip", SQLType.VARCHAR(128), true);
public static final SQLField<SQLLoginHistory, ActionType> actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class),
false);
public static final SQLField<SQLLoginHistory, Integer> nbOnline = new SQLField<>("nbOnline", SQLType.INT, false);
public static final SQLField<SQLLoginHistory, String> playerName = new SQLField<>("playerName", SQLType.VARCHAR(16), true);
public static final SQLField<SQLLoginHistory, Integer> 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
}
}

View File

@ -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<SQLMPGroup> {
public SQLMPGroup() {
super();
}
public SQLMPGroup(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_mp_group";
}
public static final SQLField<SQLMPGroup, String> groupName = new SQLField<>("groupName", SQLType.VARCHAR(16), false);
public SQLElementList<SQLMPGroupUser> 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);
}
}

View File

@ -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<SQLMPGroupUser> {
public SQLMPGroupUser() {
super();
@ -27,10 +27,10 @@ public class SQLMPGroupUser extends SQLElement {
return "pandacube_mp_group_user";
}
public static final SQLFKField<Integer, SQLMPGroup> groupId = SQLFKField.idFK("groupId", SQLType.INT, false,
public static final SQLFKField<SQLMPGroupUser, Integer, SQLMPGroup> groupId = SQLFKField.idFK("groupId", SQLType.INT, false,
SQLMPGroup.class);
public static final SQLFKField<String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<SQLMPGroupUser, String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.playerId);
// TODO ajouter un champ qui dit si le joueur est admin du groupe

View File

@ -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<SQLMPMessage> {
public SQLMPMessage() {
super();
@ -34,20 +34,20 @@ public class SQLMPMessage extends SQLElement {
return "pandacube_mp_message";
}
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLField<Integer> securityKey = new SQLField<>("securityKey", SQLType.INT, false);
public static final SQLFKField<String, SQLPlayer> viewerId = new SQLFKField<>("viewerId", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<String, SQLPlayer> sourceId = new SQLFKField<>("sourceId", SQLType.CHAR(36), true,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<String, SQLPlayer> destId = new SQLFKField<>("destId", SQLType.CHAR(36), true,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<Integer, SQLMPGroup> destGroup = SQLFKField.idFK("destGroup", SQLType.INT, true,
public static final SQLField<SQLMPMessage, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLField<SQLMPMessage, Integer> securityKey = new SQLField<>("securityKey", SQLType.INT, false);
public static final SQLFKField<SQLMPMessage, String, SQLPlayer> viewerId = new SQLFKField<>("viewerId", SQLType.CHAR(36), false,
SQLPlayer.playerId);
public static final SQLFKField<SQLMPMessage, String, SQLPlayer> sourceId = new SQLFKField<>("sourceId", SQLType.CHAR(36), true,
SQLPlayer.playerId);
public static final SQLFKField<SQLMPMessage, String, SQLPlayer> destId = new SQLFKField<>("destId", SQLType.CHAR(36), true,
SQLPlayer.playerId);
public static final SQLFKField<SQLMPMessage, Integer, SQLMPGroup> destGroup = SQLFKField.idFK("destGroup", SQLType.INT, true,
SQLMPGroup.class);
public static final SQLField<String> message = new SQLField<>("message", SQLType.VARCHAR(512), false);
public static final SQLField<Boolean> wasRead = new SQLField<>("wasRead", SQLType.BOOLEAN, false);
public static final SQLField<Boolean> deleted = new SQLField<>("deleted", SQLType.BOOLEAN, false, (Boolean) false);
public static final SQLField<Boolean> serverSync = new SQLField<>("serverSync", SQLType.BOOLEAN, false);
public static final SQLField<SQLMPMessage, String> message = new SQLField<>("message", SQLType.VARCHAR(512), false);
public static final SQLField<SQLMPMessage, Boolean> wasRead = new SQLField<>("wasRead", SQLType.BOOLEAN, false);
public static final SQLField<SQLMPMessage, Boolean> deleted = new SQLField<>("deleted", SQLType.BOOLEAN, false, (Boolean) false);
public static final SQLField<SQLMPMessage, Boolean> serverSync = new SQLField<>("serverSync", SQLType.BOOLEAN, false);
public UUID getViewerId() {
String id = get(viewerId);

View File

@ -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<SQLModoHistory> {
public SQLModoHistory() {
super();
}
public SQLModoHistory(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_modo_history";
}
public static final SQLFKField<SQLModoHistory, String, SQLPlayer> modoId = new SQLFKField<>("modoId", SQLType.CHAR(36), true,
SQLPlayer.playerId);
public static final SQLField<SQLModoHistory, ActionType> actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class),
false);
public static final SQLField<SQLModoHistory, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLFKField<SQLModoHistory, String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.playerId);
public static final SQLField<SQLModoHistory, Long> value = new SQLField<>("value", SQLType.BIGINT, true);
public static final SQLField<SQLModoHistory, String> 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
}
}

View File

@ -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<SQLOnlineshopHistory> {
public SQLOnlineshopHistory() {
super();
}
public SQLOnlineshopHistory(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_onlineshop_history";
}
public static final SQLField<SQLOnlineshopHistory, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLField<SQLOnlineshopHistory, String> transactionId = new SQLField<>("transactionId", SQLType.VARCHAR(255), true);
public static final SQLField<SQLOnlineshopHistory, SourceType> sourceType = new SQLField<>("sourceType", SQLType.ENUM(SourceType.class),
false);
public static final SQLFKField<SQLOnlineshopHistory, String, SQLPlayer> sourcePlayerId = new SQLFKField<>("sourcePlayerId",
SQLType.CHAR(36), true, SQLPlayer.playerId);
public static final SQLField<SQLOnlineshopHistory, Double> sourceQuantity = new SQLField<>("sourceQuantity", SQLType.DOUBLE, false);
public static final SQLField<SQLOnlineshopHistory, String> sourceName = new SQLField<>("sourceName", SQLType.VARCHAR(64), false);
public static final SQLField<SQLOnlineshopHistory, DestType> destType = new SQLField<>("destType", SQLType.ENUM(DestType.class), false);
public static final SQLFKField<SQLOnlineshopHistory, String, SQLPlayer> destPlayerId = new SQLFKField<>("destPlayerId", SQLType.CHAR(36),
false, SQLPlayer.playerId);
public static final SQLField<SQLOnlineshopHistory, Double> destQuantity = new SQLField<>("destQuantity", SQLType.DOUBLE, false);
public static final SQLField<SQLOnlineshopHistory, String> 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
}
}

View File

@ -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<SQLPlayer> {
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<SQLPlayer, String> playerId = new SQLField<>("playerId", SQLType.CHAR(36), false);
public static final SQLField<SQLPlayer, String> token = new SQLField<>("token", SQLType.CHAR(36), true);
public static final SQLField<SQLPlayer, String> mailCheck = new SQLField<>("mailCheck", SQLType.VARCHAR(255), true);
public static final SQLField<SQLPlayer, String> password = new SQLField<>("password", SQLType.VARCHAR(255), true);
public static final SQLField<SQLPlayer, String> mail = new SQLField<>("mail", SQLType.VARCHAR(255), true);
public static final SQLField<SQLPlayer, String> playerDisplayName = new SQLField<>("playerDisplayName", SQLType.VARCHAR(255),
false);
public static final SQLField<SQLPlayer, Long> firstTimeInGame = new SQLField<>("firstTimeInGame", SQLType.BIGINT, false, 0L);
public static final SQLField<SQLPlayer, Long> timeWebRegister = new SQLField<>("timeWebRegister", SQLType.BIGINT, true);
public static final SQLField<SQLPlayer, Long> lastTimeInGame = new SQLField<>("lastTimeInGame", SQLType.BIGINT, true);
public static final SQLField<SQLPlayer, Long> lastWebActivity = new SQLField<>("lastWebActivity", SQLType.BIGINT, false, 0L);
public static final SQLField<SQLPlayer, String> onlineInServer = new SQLField<>("onlineInServer", SQLType.VARCHAR(32), true);
public static final SQLField<SQLPlayer, String> skinURL = new SQLField<>("skinURL", SQLType.VARCHAR(255), true);
public static final SQLField<SQLPlayer, Boolean> isVanish = new SQLField<>("isVanish", SQLType.BOOLEAN, false,
(Boolean) false);
public static final SQLField<SQLPlayer, Date> birthday = new SQLField<>("birthday", SQLType.DATE, true);
public static final SQLField<SQLPlayer, Integer> lastYearCelebBday = new SQLField<>("lastYearCelebratedBirthday", SQLType.INT,
false, 0);
public static final SQLField<SQLPlayer, Long> banTimeout = new SQLField<>("banTimeout", SQLType.BIGINT, true);
public static final SQLField<SQLPlayer, Long> muteTimeout = new SQLField<>("muteTimeout", SQLType.BIGINT, true);
public static final SQLField<SQLPlayer, Boolean> isWhitelisted = new SQLField<>("isWhitelisted", SQLType.BOOLEAN, false,
(Boolean) false);
public static final SQLField<SQLPlayer, Long> bambou = new SQLField<>("bambou", SQLType.BIGINT, false, 0L);
public static final SQLField<SQLPlayer, String> 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);
}
}

View File

@ -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<SQLPlayerIgnore> {
public SQLPlayerIgnore() {
super();
@ -29,10 +29,10 @@ public class SQLPlayerIgnore extends SQLElement {
return "pandacube_player_ignore";
}
public static final SQLFKField<String, SQLPlayer> ignorer = new SQLFKField<>("ignorer", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<String, SQLPlayer> ignored = new SQLFKField<>("ignored", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<SQLPlayerIgnore, String, SQLPlayer> ignorer = new SQLFKField<>("ignorer", SQLType.CHAR(36), false,
SQLPlayer.playerId);
public static final SQLFKField<SQLPlayerIgnore, String, SQLPlayer> ignored = new SQLFKField<>("ignored", SQLType.CHAR(36), false,
SQLPlayer.playerId);
public UUID getIgnorerId() {
String id = get(ignorer);

View File

@ -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<SQLShopStock> {
public SQLShopStock() {
super();
}
public SQLShopStock(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_shop_stock";
}
public static final SQLField<SQLShopStock, String> material = new SQLField<>("material", SQLType.VARCHAR(50), false);
public static final SQLField<SQLShopStock, Integer> damage = new SQLField<>("damage", SQLType.INT, false, 0);
public static final SQLField<SQLShopStock, Double> quantity = new SQLField<>("quantity", SQLType.DOUBLE, false);
public static final SQLField<SQLShopStock, String> server = new SQLField<>("server", SQLType.VARCHAR(50), false);
}

View File

@ -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<SQLStaffTicket> {
public SQLStaffTicket() {
super();
}
public SQLStaffTicket(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_staff_ticket";
}
public static final SQLFKField<SQLStaffTicket, String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.playerId);
public static final SQLField<SQLStaffTicket, String> message = new SQLField<>("message", SQLType.VARCHAR(1024), false);
public static final SQLField<SQLStaffTicket, Long> creationTime = new SQLField<>("creationTime", SQLType.BIGINT, false);
public static final SQLFKField<SQLStaffTicket, String, SQLPlayer> 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());
}
}

View File

@ -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<SQLStaticPages> {
public SQLStaticPages() {
super();
}
public SQLStaticPages(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_static_pages";
}
public static final SQLField<SQLStaticPages, String> permalink = new SQLField<>("permalink", SQLType.VARCHAR(128), false);
public static final SQLField<SQLStaticPages, String> titreHead = new SQLField<>("titreHead", SQLType.VARCHAR(128), false);
public static final SQLField<SQLStaticPages, String> titreH2 = new SQLField<>("titreH2", SQLType.VARCHAR(255), false);
public static final SQLField<SQLStaticPages, String> texte = new SQLField<>("texte", SQLType.TEXT, false);
public static final SQLField<SQLStaticPages, String> permissions = new SQLField<>("permissions", SQLType.VARCHAR(255), true);
}

View File

@ -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<SQLUUIDPlayer> {
public SQLUUIDPlayer() {
super();
}
public SQLUUIDPlayer(int id) {
super(id);
}
@Override
protected String tableName() {
return "bungeeperms_uuidplayer";
}
public static final SQLFKField<SQLUUIDPlayer, String, SQLPlayer> uuid = new SQLFKField<>("uuid", SQLType.CHAR(36), false,
SQLPlayer.playerId);
public static final SQLField<SQLUUIDPlayer, String> 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());
}
}

View File

@ -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;

View File

@ -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<Class<? extends SQLElement>> tables = new ArrayList<>();
private static List<Class<? extends SQLElement<?>>> tables = new ArrayList<>();
private static DBConnection connection;
@ -81,10 +81,10 @@ public final class ORM {
}
/* package */ static <T extends SQLElement> void initTable(Class<T> elemClass) throws ORMInitTableException {
/* package */ static <E extends SQLElement<E>> void initTable(Class<E> 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 <T extends SQLElement> void createTable(T elem) throws SQLException {
private static <E extends SQLElement<E>> void createTable(E elem) throws SQLException {
String sql = "CREATE TABLE IF NOT EXISTS " + elem.tableName() + " (";
List<Object> params = new ArrayList<>();
Collection<SQLField<?>> tableFields = elem.getFields().values();
Collection<SQLField<E, ?>> tableFields = elem.getFields().values();
boolean first = true;
for (SQLField<?> f : tableFields) {
for (SQLField<E, ?> f : tableFields) {
Pair<String, List<Object>> statementPart = f.forSQLPreparedStatement();
params.addAll(statementPart.getValue());
@ -135,40 +135,40 @@ public final class ORM {
}
@SuppressWarnings("unchecked")
public static <T extends SQLElement> SQLField<Integer> getSQLIdField(Class<T> elemClass)
public static <E extends SQLElement<E>> SQLField<E, Integer> getSQLIdField(Class<E> elemClass)
throws ORMInitTableException {
initTable(elemClass);
return (SQLField<Integer>) SQLElement.fieldsCache.get(elemClass).get("id");
return (SQLField<E, Integer>) SQLElement.fieldsCache.get(elemClass).get("id");
}
public static <T extends SQLElement> List<T> getByIds(Class<T> elemClass, Collection<Integer> ids)
public static <E extends SQLElement<E>> List<E> getByIds(Class<E> elemClass, Collection<Integer> ids)
throws ORMException {
return getByIds(elemClass, ids.toArray(new Integer[ids.size()]));
}
public static <T extends SQLElement> List<T> getByIds(Class<T> elemClass, Integer... ids) throws ORMException {
SQLField<Integer> idField = getSQLIdField(elemClass);
public static <E extends SQLElement<E>> List<E> getByIds(Class<E> elemClass, Integer... ids) throws ORMException {
SQLField<E, Integer> 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 extends SQLElement> T getById(Class<T> elemClass, int id) throws ORMException {
public static <E extends SQLElement<E>> E getById(Class<E> elemClass, int id) throws ORMException {
return getFirst(elemClass, new SQLWhereComp(getSQLIdField(elemClass), SQLComparator.EQ, id), null);
}
public static <T extends SQLElement> T getFirst(Class<T> elemClass, SQLWhere where, SQLOrderBy orderBy)
public static <E extends SQLElement<E>> E getFirst(Class<E> elemClass, SQLWhere where, SQLOrderBy orderBy)
throws ORMException {
SQLElementList<T> elts = getAll(elemClass, where, orderBy, 1, null);
SQLElementList<E> elts = getAll(elemClass, where, orderBy, 1, null);
return (elts.size() == 0) ? null : elts.get(0);
}
public static <T extends SQLElement> SQLElementList<T> getAll(Class<T> elemClass) throws ORMException {
public static <E extends SQLElement<E>> SQLElementList<E> getAll(Class<E> elemClass) throws ORMException {
return getAll(elemClass, null, null, null, null);
}
public static <T extends SQLElement> SQLElementList<T> getAll(Class<T> elemClass, SQLWhere where,
public static <E extends SQLElement<E>> SQLElementList<E> getAll(Class<E> 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<T> elmts = new SQLElementList<T>();
SQLElementList<E> elmts = new SQLElementList<E>();
PreparedStatement ps = connection.getNativeConnection().prepareStatement(sql);
@ -218,29 +218,18 @@ public final class ORM {
}
private static <T extends SQLElement> T getElementInstance(ResultSet set, Class<T> elemClass) throws ORMException {
private static <E extends SQLElement<E>> E getElementInstance(ResultSet set, Class<E> 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<Object> sqlField = (SQLField<Object>) instance.getFields().get(fieldName);
SQLField<E, Object> sqlField = (SQLField<E, Object>) instance.getFields().get(fieldName);
if (sqlField.type.getJavaType().isEnum()) {
// JDBC ne supporte pas les enums
String enumStrValue = set.getString(c);

View File

@ -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;

View File

@ -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 */ <T extends SQLElement> ORMInitTableException(Class<T> tableElem) {
/* package */ <E extends SQLElement<E>> ORMInitTableException(Class<E> tableElem) {
super("Error while initializing table " + tableElem.getName());
}
/* package */ <T extends SQLElement> ORMInitTableException(Class<T> tableElem, Throwable t) {
/* package */ <E extends SQLElement<E>> ORMInitTableException(Class<E> tableElem, Throwable t) {
super("Error while initializing table " + tableElem.getName(), t);
}

View File

@ -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<E extends SQLElement<E>> {
/** cache for fields for each subclass of SQLElement */
/* package */ static final Map<Class<? extends SQLElement>, SQLFieldMap> fieldsCache = new HashMap<>();
/* package */ static final Map<Class<? extends SQLElement<?>>, SQLFieldMap<? extends SQLElement<?>>> 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<E> fields;
private final Map<SQLField<?>, Object> values;
private final Map<SQLField<E, ?>, Object> values;
/* package */ final Set<String> modifiedSinceLastSave;
@SuppressWarnings("unchecked")
public SQLElement() {
tableName = tableName();
if (fieldsCache.get(getClass()) == null) {
fields = new SQLFieldMap(getClass());
fields = new SQLFieldMap<>((Class<E>)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<E>)getClass(), fields);
}
else
fields = fieldsCache.get(getClass());
fields = (SQLFieldMap<E>) fieldsCache.get((Class<E>)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<Integer> idField = (SQLField<Integer>) fields.get("id");
SQLField<E, Integer> idField = (SQLField<E, Integer>) 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<E> 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<String, SQLField<?>> getFields() {
/* package */ Map<String, SQLField<E, ?>> getFields() {
return Collections.unmodifiableMap(fields);
}
public Map<SQLField<?>, Object> getValues() {
public Map<SQLField<E, ?>, Object> getValues() {
return Collections.unmodifiableMap(values);
}
public <T> void set(SQLField<T> field, T value) {
public <T> void set(SQLField<E, T> field, T value) {
set(field, value, true);
}
/* package */ <T> void set(SQLField<T> sqlField, T value, boolean setModified) {
/* package */ <T> void set(SQLField<E, T> 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> T get(SQLField<T> field) {
public <T> T get(SQLField<E, T> 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 <T, E extends SQLElement> E getForeign(SQLFKField<T, E> field) throws ORMException {
public <T, F extends SQLElement<F>> F getForeign(SQLFKField<E, T, F> 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<SQLField<?>, Object> getOnlyModifiedValues() {
Map<SQLField<?>, Object> modifiedValues = new LinkedHashMap<>();
private Map<SQLField<E, ?>, Object> getOnlyModifiedValues() {
Map<SQLField<E, ?>, 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<E, ?> 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<E>)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<Integer> idField = (SQLField<Integer>) fields.get("id");
SQLField<E, Integer> idField = (SQLField<E, Integer>) fields.get("id");
values.put(idField, id);
modifiedSinceLastSave.remove("id");
Map<SQLField<?>, Object> modifiedValues = getOnlyModifiedValues();
Map<SQLField<E, ?>, Object> modifiedValues = getOnlyModifiedValues();
if (modifiedValues.isEmpty()) return;
String sql = "";
List<Object> psValues = new ArrayList<>();
for (Map.Entry<SQLField<?>, Object> entry : modifiedValues.entrySet()) {
for (Map.Entry<SQLField<E, ?>, 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<Object> psValues = new ArrayList<>();
boolean first = true;
for (Map.Entry<SQLField<?>, Object> entry : values.entrySet()) {
for (Map.Entry<SQLField<E, ?>, Object> entry : values.entrySet()) {
if (!first) {
concat_vals += ",";
concat_fields += ",";
@ -305,8 +306,8 @@ public abstract class SQLElement {
}
@SuppressWarnings("unchecked")
public SQLField<Integer> getFieldId() {
return (SQLField<Integer>) getFields().get("id");
public SQLField<E, Integer> getFieldId() {
return (SQLField<E, Integer>) 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<String, SQLField<?>> {
protected static class SQLFieldMap<E extends SQLElement<E>> extends LinkedHashMap<String, SQLField<E, ?>> {
private static final long serialVersionUID = 1L;
private final Class<? extends SQLElement> sqlElemClass;
private final Class<E> sqlElemClass;
private SQLFieldMap(Class<? extends SQLElement> elemClass) {
private SQLFieldMap(Class<E> 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<E, ?> checkedF = (SQLField<E, ?>) 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<E, ?> 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();
}
}

View File

@ -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 <E>
*/
public class SQLElementList<E extends SQLElement> extends ArrayList<E> {
public class SQLElementList<E extends SQLElement<E>> extends ArrayList<E> {
private static final long serialVersionUID = 1L;
private final Map<SQLField<?>, Object> modifiedValues = new LinkedHashMap<>();
private final Map<SQLField<E, ?>, Object> modifiedValues = new LinkedHashMap<>();
@Override
public synchronized boolean add(E e) {
@ -37,11 +37,10 @@ public class SQLElementList<E extends SQLElement> extends ArrayList<E> {
* @param field le champs à modifier
* @param value la valeur à lui appliquer
*/
public synchronized <T> void setCommon(SQLField<T> field, T value) {
public synchronized <T> void setCommon(SQLField<E, T> field, T value) {
if (field != null && field.name == "id")
throw new IllegalArgumentException("Can't modify id field in a SQLElementList");
@SuppressWarnings("unchecked")
Class<E> elemClass = (Class<E>) field.getSQLElementType();
try {
E emptyElement = elemClass.newInstance();
@ -76,7 +75,7 @@ public class SQLElementList<E extends SQLElement> extends ArrayList<E> {
String sqlSet = "";
List<Object> psValues = new ArrayList<>();
for (Map.Entry<SQLField<?>, Object> entry : modifiedValues.entrySet()) {
for (Map.Entry<SQLField<E, ?>, Object> entry : modifiedValues.entrySet()) {
sqlSet += entry.getKey().name + " = ? ,";
if (entry.getKey().type.getJavaType().isEnum()) // prise en charge
// enum (non prise

View File

@ -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<T, E extends SQLElement> extends SQLField<T> {
public class SQLFKField<E extends SQLElement<E>, T, F extends SQLElement<F>> extends SQLField<E, T> {
private SQLField<T> sqlForeignKeyField;
private Class<E> sqlForeignKeyElement;
private SQLField<F, T> sqlForeignKeyField;
private Class<F> sqlForeignKeyElemClass;
public SQLFKField(String n, SQLType<T> t, boolean nul, Class<E> fkEl, SQLField<T> fkF) {
public SQLFKField(String n, SQLType<T> t, boolean nul, SQLField<F, T> fkF) {
super(n, t, nul);
construct(fkEl, fkF);
construct(fkF);
}
public SQLFKField(String n, SQLType<T> t, boolean nul, T deflt, Class<E> fkEl, SQLField<T> fkF) {
public SQLFKField(String n, SQLType<T> t, boolean nul, T deflt, SQLField<F, T> fkF) {
super(n, t, nul, deflt);
construct(fkEl, fkF);
construct(fkF);
}
public static <E extends SQLElement> SQLFKField<Integer, E> idFK(String n, SQLType<Integer> t, boolean nul,
Class<E> fkEl) {
public static <E extends SQLElement<E>, F extends SQLElement<F>> SQLFKField<E, Integer, F> idFK(String n, SQLType<Integer> t, boolean nul,
Class<F> 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 <E extends SQLElement> SQLFKField<Integer, E> idFKField(String n, SQLType<Integer> t, boolean nul,
Integer deflt, Class<E> fkEl) {
public static <E extends SQLElement<E>, F extends SQLElement<F>> SQLFKField<E, Integer, F> idFKField(String n, SQLType<Integer> t, boolean nul,
Integer deflt, Class<F> 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<E> fkEl, SQLField<T> fkF) {
if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null");
private void construct(SQLField<F, T> fkF) {
if (fkF == null) throw new IllegalArgumentException("foreignKeyField can't be null");
Class<F> fkEl = fkF.getSQLElementType();
try {
ORM.initTable(fkEl);
} catch (ORMInitTableException e) {
@ -53,15 +53,15 @@ public class SQLFKField<T, E extends SQLElement> extends SQLField<T> {
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<T> getForeignField() {
public SQLField<F, T> getForeignField() {
return sqlForeignKeyField;
}
public Class<E> getForeignElementClass() {
return sqlForeignKeyElement;
public Class<F> getForeignElementClass() {
return sqlForeignKeyElemClass;
}
}

View File

@ -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<T> {
public class SQLField<E extends SQLElement<E>, T> {
private Class<? extends SQLElement> sqlElemClass;
private Class<E> sqlElemClass;
public final String name;
public final SQLType<T> type;
public final boolean canBeNull;
@ -42,11 +42,11 @@ public class SQLField<T> {
+ ((defaultValue == null || autoIncrement) ? "" : " DEFAULT ?"), params);
}
/* package */ void setSQLElementType(Class<? extends SQLElement> elemClass) {
/* package */ void setSQLElementType(Class<E> elemClass) {
sqlElemClass = elemClass;
}
public Class<? extends SQLElement> getSQLElementType() {
public Class<E> getSQLElementType() {
return sqlElemClass;
}
@ -66,7 +66,7 @@ public class SQLField<T> {
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;

View File

@ -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;
}

View File

@ -1,4 +1,4 @@
package fr.pandacube.java.util.db2.sql_tools;
package fr.pandacube.java.util.db.sql_tools;
import java.sql.Date;

View File

@ -1,4 +1,4 @@
package fr.pandacube.java.util.db2.sql_tools;
package fr.pandacube.java.util.db.sql_tools;
import java.util.List;

View File

@ -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;

View File

@ -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 <T> SQLWhereComp(SQLField<T> l, SQLComparator c, T r) {
public <T> SQLWhereComp(SQLField<?, T> 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;

View File

@ -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<String> field;
private SQLField<?, String> 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<String> f, String like) {
public SQLWhereLike(SQLField<?, String> f, String like) {
if (f == null || like == null)
throw new IllegalArgumentException("All arguments for SQLWhereLike constructor can't be null");
field = f;

View File

@ -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() + "#"

View File

@ -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<Integer> time = new SQLField<>("time", SQLType.INT, false);
public static final SQLFKField<String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), true,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<String> userName = new SQLField<>("userName", SQLType.VARCHAR(50), true);
public static final SQLField<String> userMail = new SQLField<>("userMail", SQLType.VARCHAR(50), true);
public static final SQLField<String> titre = new SQLField<>("titre", SQLType.VARCHAR(100), false);
public static final SQLField<String> texte = new SQLField<>("texte", SQLType.TEXT, false);
public static final SQLField<Boolean> 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());
}
}

View File

@ -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<String> nom = new SQLField<>("nom", SQLType.VARCHAR(100), false);
public static final SQLField<Integer> ordre = new SQLField<>("ordre", SQLType.INT, false);
}

View File

@ -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<Integer, SQLForumCategorie> catId = SQLFKField.idFK("catId", SQLType.INT, false,
SQLForumCategorie.class);
public static final SQLField<String> nom = new SQLField<>("nom", SQLType.VARCHAR(100), false);
public static final SQLField<String> description = new SQLField<>("description", SQLType.TEXT, false);
public static final SQLField<Integer> ordre = new SQLField<>("ordre", SQLType.INT, false);
public static final SQLField<Integer> authView = new SQLField<>("authView", SQLType.INT, false);
public static final SQLField<Integer> authPost = new SQLField<>("authPost", SQLType.INT, false);
public static final SQLField<Integer> authThread = new SQLField<>("authThread", SQLType.INT, false);
public static final SQLField<Integer> authAnchored = new SQLField<>("authAnchored", SQLType.INT, false);
public static final SQLField<Integer> authModo = new SQLField<>("authModo", SQLType.INT, false);
public static final SQLField<Integer> nbThreads = new SQLField<>("nbThreads", SQLType.INT, false);
public static final SQLField<Integer> nbMessages = new SQLField<>("nbMessages", SQLType.INT, false);
}

View File

@ -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<String> createur = new SQLField<>("createur", SQLType.CHAR(36), false);
public static final SQLField<String> texte = new SQLField<>("texte", SQLType.TEXT, false);
public static final SQLField<Integer> time = new SQLField<>("time", SQLType.INT, false);
public static final SQLFKField<Integer, SQLForumThread> threadId = SQLFKField.idFK("threadId", SQLType.INT, false,
SQLForumThread.class);
public static final SQLField<Boolean> 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());
}
}

View File

@ -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<Integer, SQLForumForum> forumId = SQLFKField.idFK("forumId", SQLType.INT, false,
SQLForumForum.class);
public static final SQLField<String> titre = new SQLField<>("titre", SQLType.VARCHAR(60), false);
public static final SQLFKField<String, SQLPlayer> createur = new SQLFKField<>("createur", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<Integer> vu = new SQLField<>("vu", SQLType.INT, false);
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLField<Boolean> anchored = new SQLField<>("anchored", SQLType.BOOLEAN, false);
public static final SQLField<Boolean> locked = new SQLField<>("locked", SQLType.BOOLEAN, false);
public static final SQLField<Integer> 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());
}
}

View File

@ -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<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLFKField<String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<String> ip = new SQLField<>("ip", SQLType.VARCHAR(128), true);
public static final SQLField<ActionType> actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class),
false);
public static final SQLField<Integer> nbOnline = new SQLField<>("nbOnline", SQLType.INT, false);
public static final SQLField<String> playerName = new SQLField<>("playerName", SQLType.VARCHAR(16), true);
public static final SQLField<Integer> 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
}
}

View File

@ -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<String> groupName = new SQLField<>("groupName", SQLType.VARCHAR(16), false);
public SQLElementList<SQLMPGroupUser> 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);
}
}

View File

@ -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<String, SQLPlayer> modoId = new SQLFKField<>("modoId", SQLType.CHAR(36), true,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<ActionType> actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class),
false);
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLFKField<String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<Long> value = new SQLField<>("value", SQLType.BIGINT, true);
public static final SQLField<String> 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
}
}

View File

@ -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<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLField<String> transactionId = new SQLField<>("transactionId", SQLType.VARCHAR(255), true);
public static final SQLField<SourceType> sourceType = new SQLField<>("sourceType", SQLType.ENUM(SourceType.class),
false);
public static final SQLFKField<String, SQLPlayer> sourcePlayerId = new SQLFKField<>("sourcePlayerId",
SQLType.CHAR(36), true, SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<Double> sourceQuantity = new SQLField<>("sourceQuantity", SQLType.DOUBLE, false);
public static final SQLField<String> sourceName = new SQLField<>("sourceName", SQLType.VARCHAR(64), false);
public static final SQLField<DestType> destType = new SQLField<>("destType", SQLType.ENUM(DestType.class), false);
public static final SQLFKField<String, SQLPlayer> destPlayerId = new SQLFKField<>("destPlayerId", SQLType.CHAR(36),
false, SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<Double> destQuantity = new SQLField<>("destQuantity", SQLType.DOUBLE, false);
public static final SQLField<String> 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
}
}

View File

@ -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<String> playerId = new SQLField<>("playerId", SQLType.CHAR(36), false);
public static final SQLField<String> token = new SQLField<>("token", SQLType.CHAR(36), true);
public static final SQLField<String> mailCheck = new SQLField<>("mailCheck", SQLType.VARCHAR(255), true);
public static final SQLField<String> password = new SQLField<>("password", SQLType.VARCHAR(255), true);
public static final SQLField<String> mail = new SQLField<>("mail", SQLType.VARCHAR(255), true);
public static final SQLField<String> playerDisplayName = new SQLField<>("playerDisplayName", SQLType.VARCHAR(255),
false);
public static final SQLField<Long> firstTimeInGame = new SQLField<>("firstTimeInGame", SQLType.BIGINT, false, 0L);
public static final SQLField<Long> timeWebRegister = new SQLField<>("timeWebRegister", SQLType.BIGINT, true);
public static final SQLField<Long> lastTimeInGame = new SQLField<>("lastTimeInGame", SQLType.BIGINT, true);
public static final SQLField<Long> lastWebActivity = new SQLField<>("lastWebActivity", SQLType.BIGINT, false, 0L);
public static final SQLField<String> onlineInServer = new SQLField<>("onlineInServer", SQLType.VARCHAR(32), true);
public static final SQLField<String> skinURL = new SQLField<>("skinURL", SQLType.VARCHAR(255), true);
public static final SQLField<Boolean> isVanish = new SQLField<>("isVanish", SQLType.BOOLEAN, false,
(Boolean) false);
public static final SQLField<Date> birthday = new SQLField<>("birthday", SQLType.DATE, true);
public static final SQLField<Integer> lastYearCelebBday = new SQLField<>("lastYearCelebratedBirthday", SQLType.INT,
false, 0);
public static final SQLField<Long> banTimeout = new SQLField<>("banTimeout", SQLType.BIGINT, true);
public static final SQLField<Long> muteTimeout = new SQLField<>("muteTimeout", SQLType.BIGINT, true);
public static final SQLField<Boolean> isWhitelisted = new SQLField<>("isWhitelisted", SQLType.BOOLEAN, false,
(Boolean) false);
public static final SQLField<Long> bambou = new SQLField<>("bambou", SQLType.BIGINT, false, 0L);
public static final SQLField<String> 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);
}
}

View File

@ -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<String> material = new SQLField<>("material", SQLType.VARCHAR(50), false);
public static final SQLField<Integer> damage = new SQLField<>("damage", SQLType.INT, false, 0);
public static final SQLField<Double> quantity = new SQLField<>("quantity", SQLType.DOUBLE, false);
public static final SQLField<String> server = new SQLField<>("server", SQLType.VARCHAR(50), false);
}

View File

@ -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<String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<String> message = new SQLField<>("message", SQLType.VARCHAR(1024), false);
public static final SQLField<Long> creationTime = new SQLField<>("creationTime", SQLType.BIGINT, false);
public static final SQLFKField<String, SQLPlayer> 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());
}
}

View File

@ -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<String> permalink = new SQLField<>("permalink", SQLType.VARCHAR(128), false);
public static final SQLField<String> titreHead = new SQLField<>("titreHead", SQLType.VARCHAR(128), false);
public static final SQLField<String> titreH2 = new SQLField<>("titreH2", SQLType.VARCHAR(255), false);
public static final SQLField<String> texte = new SQLField<>("texte", SQLType.TEXT, false);
public static final SQLField<String> permissions = new SQLField<>("permissions", SQLType.VARCHAR(255), true);
}

View File

@ -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<String, SQLPlayer> uuid = new SQLFKField<>("uuid", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<String> 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());
}
}