Refactoring de l'ORM : package 'db2' -> 'db' + typage plus précis des SQLField
This commit is contained in:
parent
724e9ecd6c
commit
805ff052d3
@ -4,15 +4,15 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.SQLLoginHistory;
|
import fr.pandacube.java.util.db.SQLLoginHistory;
|
||||||
import fr.pandacube.java.util.db2.SQLPlayer;
|
import fr.pandacube.java.util.db.SQLPlayer;
|
||||||
import fr.pandacube.java.util.db2.SQLUUIDPlayer;
|
import fr.pandacube.java.util.db.SQLUUIDPlayer;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.ORM;
|
import fr.pandacube.java.util.db.sql_tools.ORM;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy;
|
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy.Direction;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereLike;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy.Direction;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereLike;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
import net.alpenblock.bungeeperms.BungeePerms;
|
import net.alpenblock.bungeeperms.BungeePerms;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
43
src/fr/pandacube/java/util/db/SQLContact.java
Normal file
43
src/fr/pandacube/java/util/db/SQLContact.java
Normal 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
src/fr/pandacube/java/util/db/SQLForumCategorie.java
Normal file
25
src/fr/pandacube/java/util/db/SQLForumCategorie.java
Normal 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);
|
||||||
|
|
||||||
|
}
|
36
src/fr/pandacube/java/util/db/SQLForumForum.java
Normal file
36
src/fr/pandacube/java/util/db/SQLForumForum.java
Normal 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);
|
||||||
|
|
||||||
|
}
|
41
src/fr/pandacube/java/util/db/SQLForumPost.java
Normal file
41
src/fr/pandacube/java/util/db/SQLForumPost.java
Normal 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
45
src/fr/pandacube/java/util/db/SQLForumThread.java
Normal file
45
src/fr/pandacube/java/util/db/SQLForumThread.java
Normal 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
src/fr/pandacube/java/util/db/SQLLoginHistory.java
Normal file
47
src/fr/pandacube/java/util/db/SQLLoginHistory.java
Normal 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
|
||||||
|
}
|
||||||
|
}
|
41
src/fr/pandacube/java/util/db/SQLMPGroup.java
Normal file
41
src/fr/pandacube/java/util/db/SQLMPGroup.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,18 +1,18 @@
|
|||||||
package fr.pandacube.java.util.db2;
|
package fr.pandacube.java.util.db;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.ORM;
|
import fr.pandacube.java.util.db.sql_tools.ORM;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
import fr.pandacube.java.util.db.sql_tools.SQLElement;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLFKField;
|
import fr.pandacube.java.util.db.sql_tools.SQLFKField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db.sql_tools.SQLType;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
|
|
||||||
public class SQLMPGroupUser extends SQLElement {
|
public class SQLMPGroupUser extends SQLElement<SQLMPGroupUser> {
|
||||||
|
|
||||||
public SQLMPGroupUser() {
|
public SQLMPGroupUser() {
|
||||||
super();
|
super();
|
||||||
@ -27,10 +27,10 @@ public class SQLMPGroupUser extends SQLElement {
|
|||||||
return "pandacube_mp_group_user";
|
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);
|
SQLMPGroup.class);
|
||||||
public static final SQLFKField<String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
|
public static final SQLFKField<SQLMPGroupUser, String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
|
||||||
SQLPlayer.class, SQLPlayer.playerId);
|
SQLPlayer.playerId);
|
||||||
|
|
||||||
// TODO ajouter un champ qui dit si le joueur est admin du groupe
|
// TODO ajouter un champ qui dit si le joueur est admin du groupe
|
||||||
|
|
@ -1,25 +1,25 @@
|
|||||||
package fr.pandacube.java.util.db2;
|
package fr.pandacube.java.util.db;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.PlayerFinder;
|
import fr.pandacube.java.util.PlayerFinder;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.ORM;
|
import fr.pandacube.java.util.db.sql_tools.ORM;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.ORMException;
|
import fr.pandacube.java.util.db.sql_tools.ORMException;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
import fr.pandacube.java.util.db.sql_tools.SQLElement;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElementList;
|
import fr.pandacube.java.util.db.sql_tools.SQLElementList;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLFKField;
|
import fr.pandacube.java.util.db.sql_tools.SQLFKField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLField;
|
import fr.pandacube.java.util.db.sql_tools.SQLField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy;
|
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy.Direction;
|
import fr.pandacube.java.util.db.sql_tools.SQLType;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereLike;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereNull;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy.Direction;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereLike;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereNull;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
|
|
||||||
public class SQLMPMessage extends SQLElement {
|
public class SQLMPMessage extends SQLElement<SQLMPMessage> {
|
||||||
|
|
||||||
public SQLMPMessage() {
|
public SQLMPMessage() {
|
||||||
super();
|
super();
|
||||||
@ -34,20 +34,20 @@ public class SQLMPMessage extends SQLElement {
|
|||||||
return "pandacube_mp_message";
|
return "pandacube_mp_message";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
|
public static final SQLField<SQLMPMessage, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
|
||||||
public static final SQLField<Integer> securityKey = new SQLField<>("securityKey", SQLType.INT, false);
|
public static final SQLField<SQLMPMessage, Integer> securityKey = new SQLField<>("securityKey", SQLType.INT, false);
|
||||||
public static final SQLFKField<String, SQLPlayer> viewerId = new SQLFKField<>("viewerId", SQLType.CHAR(36), false,
|
public static final SQLFKField<SQLMPMessage, String, SQLPlayer> viewerId = new SQLFKField<>("viewerId", SQLType.CHAR(36), false,
|
||||||
SQLPlayer.class, SQLPlayer.playerId);
|
SQLPlayer.playerId);
|
||||||
public static final SQLFKField<String, SQLPlayer> sourceId = new SQLFKField<>("sourceId", SQLType.CHAR(36), true,
|
public static final SQLFKField<SQLMPMessage, String, SQLPlayer> sourceId = new SQLFKField<>("sourceId", SQLType.CHAR(36), true,
|
||||||
SQLPlayer.class, SQLPlayer.playerId);
|
SQLPlayer.playerId);
|
||||||
public static final SQLFKField<String, SQLPlayer> destId = new SQLFKField<>("destId", SQLType.CHAR(36), true,
|
public static final SQLFKField<SQLMPMessage, String, SQLPlayer> destId = new SQLFKField<>("destId", SQLType.CHAR(36), true,
|
||||||
SQLPlayer.class, SQLPlayer.playerId);
|
SQLPlayer.playerId);
|
||||||
public static final SQLFKField<Integer, SQLMPGroup> destGroup = SQLFKField.idFK("destGroup", SQLType.INT, true,
|
public static final SQLFKField<SQLMPMessage, Integer, SQLMPGroup> destGroup = SQLFKField.idFK("destGroup", SQLType.INT, true,
|
||||||
SQLMPGroup.class);
|
SQLMPGroup.class);
|
||||||
public static final SQLField<String> message = new SQLField<>("message", SQLType.VARCHAR(512), false);
|
public static final SQLField<SQLMPMessage, 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<SQLMPMessage, 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<SQLMPMessage, 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, Boolean> serverSync = new SQLField<>("serverSync", SQLType.BOOLEAN, false);
|
||||||
|
|
||||||
public UUID getViewerId() {
|
public UUID getViewerId() {
|
||||||
String id = get(viewerId);
|
String id = get(viewerId);
|
57
src/fr/pandacube/java/util/db/SQLModoHistory.java
Normal file
57
src/fr/pandacube/java/util/db/SQLModoHistory.java
Normal 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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
65
src/fr/pandacube/java/util/db/SQLOnlineshopHistory.java
Normal file
65
src/fr/pandacube/java/util/db/SQLOnlineshopHistory.java
Normal 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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
91
src/fr/pandacube/java/util/db/SQLPlayer.java
Normal file
91
src/fr/pandacube/java/util/db/SQLPlayer.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,20 +1,20 @@
|
|||||||
package fr.pandacube.java.util.db2;
|
package fr.pandacube.java.util.db;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.ORM;
|
import fr.pandacube.java.util.db.sql_tools.ORM;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
import fr.pandacube.java.util.db.sql_tools.SQLElement;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLFKField;
|
import fr.pandacube.java.util.db.sql_tools.SQLFKField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy;
|
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db.sql_tools.SQLType;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
|
|
||||||
public class SQLPlayerIgnore extends SQLElement {
|
public class SQLPlayerIgnore extends SQLElement<SQLPlayerIgnore> {
|
||||||
|
|
||||||
public SQLPlayerIgnore() {
|
public SQLPlayerIgnore() {
|
||||||
super();
|
super();
|
||||||
@ -29,10 +29,10 @@ public class SQLPlayerIgnore extends SQLElement {
|
|||||||
return "pandacube_player_ignore";
|
return "pandacube_player_ignore";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final SQLFKField<String, SQLPlayer> ignorer = new SQLFKField<>("ignorer", SQLType.CHAR(36), false,
|
public static final SQLFKField<SQLPlayerIgnore, String, SQLPlayer> ignorer = new SQLFKField<>("ignorer", SQLType.CHAR(36), false,
|
||||||
SQLPlayer.class, SQLPlayer.playerId);
|
SQLPlayer.playerId);
|
||||||
public static final SQLFKField<String, SQLPlayer> ignored = new SQLFKField<>("ignored", SQLType.CHAR(36), false,
|
public static final SQLFKField<SQLPlayerIgnore, String, SQLPlayer> ignored = new SQLFKField<>("ignored", SQLType.CHAR(36), false,
|
||||||
SQLPlayer.class, SQLPlayer.playerId);
|
SQLPlayer.playerId);
|
||||||
|
|
||||||
public UUID getIgnorerId() {
|
public UUID getIgnorerId() {
|
||||||
String id = get(ignorer);
|
String id = get(ignorer);
|
27
src/fr/pandacube/java/util/db/SQLShopStock.java
Normal file
27
src/fr/pandacube/java/util/db/SQLShopStock.java
Normal 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);
|
||||||
|
|
||||||
|
}
|
50
src/fr/pandacube/java/util/db/SQLStaffTicket.java
Normal file
50
src/fr/pandacube/java/util/db/SQLStaffTicket.java
Normal 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
src/fr/pandacube/java/util/db/SQLStaticPages.java
Normal file
28
src/fr/pandacube/java/util/db/SQLStaticPages.java
Normal 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);
|
||||||
|
|
||||||
|
}
|
38
src/fr/pandacube/java/util/db/SQLUUIDPlayer.java
Normal file
38
src/fr/pandacube/java/util/db/SQLUUIDPlayer.java
Normal 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
@ -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.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -10,25 +10,25 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
import fr.pandacube.java.util.EnumUtil;
|
import fr.pandacube.java.util.EnumUtil;
|
||||||
import fr.pandacube.java.util.Log;
|
import fr.pandacube.java.util.Log;
|
||||||
import fr.pandacube.java.util.db2.SQLContact;
|
import fr.pandacube.java.util.db.SQLContact;
|
||||||
import fr.pandacube.java.util.db2.SQLForumCategorie;
|
import fr.pandacube.java.util.db.SQLForumCategorie;
|
||||||
import fr.pandacube.java.util.db2.SQLForumForum;
|
import fr.pandacube.java.util.db.SQLForumForum;
|
||||||
import fr.pandacube.java.util.db2.SQLForumPost;
|
import fr.pandacube.java.util.db.SQLForumPost;
|
||||||
import fr.pandacube.java.util.db2.SQLForumThread;
|
import fr.pandacube.java.util.db.SQLForumThread;
|
||||||
import fr.pandacube.java.util.db2.SQLLoginHistory;
|
import fr.pandacube.java.util.db.SQLLoginHistory;
|
||||||
import fr.pandacube.java.util.db2.SQLMPGroup;
|
import fr.pandacube.java.util.db.SQLMPGroup;
|
||||||
import fr.pandacube.java.util.db2.SQLMPGroupUser;
|
import fr.pandacube.java.util.db.SQLMPGroupUser;
|
||||||
import fr.pandacube.java.util.db2.SQLMPMessage;
|
import fr.pandacube.java.util.db.SQLMPMessage;
|
||||||
import fr.pandacube.java.util.db2.SQLModoHistory;
|
import fr.pandacube.java.util.db.SQLModoHistory;
|
||||||
import fr.pandacube.java.util.db2.SQLOnlineshopHistory;
|
import fr.pandacube.java.util.db.SQLOnlineshopHistory;
|
||||||
import fr.pandacube.java.util.db2.SQLPlayer;
|
import fr.pandacube.java.util.db.SQLPlayer;
|
||||||
import fr.pandacube.java.util.db2.SQLPlayerIgnore;
|
import fr.pandacube.java.util.db.SQLPlayerIgnore;
|
||||||
import fr.pandacube.java.util.db2.SQLShopStock;
|
import fr.pandacube.java.util.db.SQLShopStock;
|
||||||
import fr.pandacube.java.util.db2.SQLStaffTicket;
|
import fr.pandacube.java.util.db.SQLStaffTicket;
|
||||||
import fr.pandacube.java.util.db2.SQLStaticPages;
|
import fr.pandacube.java.util.db.SQLStaticPages;
|
||||||
import fr.pandacube.java.util.db2.SQLUUIDPlayer;
|
import fr.pandacube.java.util.db.SQLUUIDPlayer;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +39,7 @@ import javafx.util.Pair;
|
|||||||
*/
|
*/
|
||||||
public final class ORM {
|
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;
|
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;
|
if (tables.contains(elemClass)) return;
|
||||||
try {
|
try {
|
||||||
T instance = elemClass.newInstance();
|
E instance = elemClass.newInstance();
|
||||||
String tableName = instance.tableName();
|
String tableName = instance.tableName();
|
||||||
if (!tableExist(tableName)) createTable(instance);
|
if (!tableExist(tableName)) createTable(instance);
|
||||||
tables.add(elemClass);
|
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() + " (";
|
String sql = "CREATE TABLE IF NOT EXISTS " + elem.tableName() + " (";
|
||||||
List<Object> params = new ArrayList<>();
|
List<Object> params = new ArrayList<>();
|
||||||
|
|
||||||
Collection<SQLField<?>> tableFields = elem.getFields().values();
|
Collection<SQLField<E, ?>> tableFields = elem.getFields().values();
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (SQLField<?> f : tableFields) {
|
for (SQLField<E, ?> f : tableFields) {
|
||||||
Pair<String, List<Object>> statementPart = f.forSQLPreparedStatement();
|
Pair<String, List<Object>> statementPart = f.forSQLPreparedStatement();
|
||||||
params.addAll(statementPart.getValue());
|
params.addAll(statementPart.getValue());
|
||||||
|
|
||||||
@ -135,40 +135,40 @@ public final class ORM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@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 {
|
throws ORMInitTableException {
|
||||||
initTable(elemClass);
|
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 {
|
throws ORMException {
|
||||||
return getByIds(elemClass, ids.toArray(new Integer[ids.size()]));
|
return getByIds(elemClass, ids.toArray(new Integer[ids.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends SQLElement> List<T> getByIds(Class<T> elemClass, Integer... ids) throws ORMException {
|
public static <E extends SQLElement<E>> List<E> getByIds(Class<E> elemClass, Integer... ids) throws ORMException {
|
||||||
SQLField<Integer> idField = getSQLIdField(elemClass);
|
SQLField<E, Integer> idField = getSQLIdField(elemClass);
|
||||||
SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR);
|
SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR);
|
||||||
for (Integer id : ids)
|
for (Integer id : ids)
|
||||||
if (id != null) where.add(new SQLWhereComp(idField, SQLComparator.EQ, id));
|
if (id != null) where.add(new SQLWhereComp(idField, SQLComparator.EQ, id));
|
||||||
return getAll(elemClass, where, new SQLOrderBy().addField(idField), 1, null);
|
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);
|
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 {
|
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);
|
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);
|
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 {
|
SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException {
|
||||||
initTable(elemClass);
|
initTable(elemClass);
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ public final class ORM {
|
|||||||
if (offset != null) sql += " OFFSET " + offset;
|
if (offset != null) sql += " OFFSET " + offset;
|
||||||
sql += ";";
|
sql += ";";
|
||||||
|
|
||||||
SQLElementList<T> elmts = new SQLElementList<T>();
|
SQLElementList<E> elmts = new SQLElementList<E>();
|
||||||
|
|
||||||
PreparedStatement ps = connection.getNativeConnection().prepareStatement(sql);
|
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 {
|
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();
|
int fieldCount = set.getMetaData().getColumnCount();
|
||||||
|
|
||||||
for (int c = 1; c <= fieldCount; c++) {
|
for (int c = 1; c <= fieldCount; c++) {
|
||||||
String fieldName = set.getMetaData().getColumnLabel(c);
|
String fieldName = set.getMetaData().getColumnLabel(c);
|
||||||
if (!instance.getFields().containsKey(fieldName)) continue; // ignore
|
if (!instance.getFields().containsKey(fieldName)) continue;
|
||||||
// when
|
// ignore when field is present in database but not handled by SQLElement instance
|
||||||
// field
|
|
||||||
// is
|
|
||||||
// present
|
|
||||||
// in
|
|
||||||
// database
|
|
||||||
// but
|
|
||||||
// not
|
|
||||||
// handled
|
|
||||||
// by
|
|
||||||
// SQLElement
|
|
||||||
// instance
|
|
||||||
@SuppressWarnings("unchecked")
|
@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()) {
|
if (sqlField.type.getJavaType().isEnum()) {
|
||||||
// JDBC ne supporte pas les enums
|
// JDBC ne supporte pas les enums
|
||||||
String enumStrValue = set.getString(c);
|
String enumStrValue = set.getString(c);
|
@ -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 {
|
public class ORMException extends Exception {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
@ -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 {
|
public class ORMInitTableException extends ORMException {
|
||||||
private static final long serialVersionUID = 1L;
|
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());
|
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);
|
super("Error while initializing table " + tableElem.getName(), t);
|
||||||
}
|
}
|
||||||
|
|
@ -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.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -19,11 +19,11 @@ import java.util.logging.Level;
|
|||||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||||
|
|
||||||
import fr.pandacube.java.util.Log;
|
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 */
|
/** 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();
|
DBConnection db = ORM.getConnection();
|
||||||
|
|
||||||
@ -31,25 +31,26 @@ public abstract class SQLElement {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
private final String tableName;
|
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;
|
/* package */ final Set<String> modifiedSinceLastSave;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public SQLElement() {
|
public SQLElement() {
|
||||||
tableName = tableName();
|
tableName = tableName();
|
||||||
|
|
||||||
if (fieldsCache.get(getClass()) == null) {
|
if (fieldsCache.get(getClass()) == null) {
|
||||||
fields = new SQLFieldMap(getClass());
|
fields = new SQLFieldMap<>((Class<E>)getClass());
|
||||||
|
|
||||||
// le champ id commun à toutes les tables
|
// le champ id commun à toutes les tables
|
||||||
fields.addField(new SQLField<>("id", SQLType.INT, false, true, 0));
|
fields.addField(new SQLField<>("id", SQLType.INT, false, true, 0));
|
||||||
|
|
||||||
generateFields(fields);
|
generateFields(fields);
|
||||||
fieldsCache.put(getClass(), fields);
|
fieldsCache.put((Class<E>)getClass(), fields);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fields = fieldsCache.get(getClass());
|
fields = (SQLFieldMap<E>) fieldsCache.get((Class<E>)getClass());
|
||||||
|
|
||||||
values = new LinkedHashMap<>(fields.size());
|
values = new LinkedHashMap<>(fields.size());
|
||||||
modifiedSinceLastSave = new HashSet<>(fields.size());
|
modifiedSinceLastSave = new HashSet<>(fields.size());
|
||||||
@ -61,7 +62,7 @@ public abstract class SQLElement {
|
|||||||
protected SQLElement(int id) {
|
protected SQLElement(int id) {
|
||||||
this();
|
this();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
SQLField<Integer> idField = (SQLField<Integer>) fields.get("id");
|
SQLField<E, Integer> idField = (SQLField<E, Integer>) fields.get("id");
|
||||||
set(idField, id, false);
|
set(idField, id, false);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
stored = true;
|
stored = true;
|
||||||
@ -82,7 +83,7 @@ public abstract class SQLElement {
|
|||||||
else if (f.canBeNull || (f.autoIncrement && !stored)) set(f, null);
|
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();
|
java.lang.reflect.Field[] declaredFields = getClass().getDeclaredFields();
|
||||||
for (java.lang.reflect.Field field : declaredFields) {
|
for (java.lang.reflect.Field field : declaredFields) {
|
||||||
@ -92,7 +93,7 @@ public abstract class SQLElement {
|
|||||||
Object val = field.get(null);
|
Object val = field.get(null);
|
||||||
if (val == null || !(val instanceof SQLField)) continue;
|
if (val == null || !(val instanceof SQLField)) continue;
|
||||||
|
|
||||||
listToFill.addField((SQLField<?>) val);
|
listToFill.addField((SQLField<?, ?>) val);
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
Log.getLogger().log(Level.SEVERE, "Can't get value of static field " + field.toString(), 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);
|
return Collections.unmodifiableMap(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<SQLField<?>, Object> getValues() {
|
public Map<SQLField<E, ?>, Object> getValues() {
|
||||||
return Collections.unmodifiableMap(values);
|
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);
|
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 (sqlField == null) throw new IllegalArgumentException("sqlField can't be null");
|
||||||
if (!fields.containsValue(sqlField))
|
if (!fields.containsValue(sqlField))
|
||||||
throw new IllegalArgumentException(sqlField.name + " is not a SQLField of " + getClass().getName());
|
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 (field == null) throw new IllegalArgumentException("field can't be null");
|
||||||
if (values.containsKey(field)) {
|
if (values.containsKey(field)) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -156,7 +157,7 @@ public abstract class SQLElement {
|
|||||||
+ " does not exist or is not set");
|
+ " 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);
|
T fkValue = get(field);
|
||||||
if (fkValue == null) return null;
|
if (fkValue == null) return null;
|
||||||
return ORM.getFirst(field.getForeignElementClass(),
|
return ORM.getFirst(field.getForeignElementClass(),
|
||||||
@ -167,23 +168,24 @@ public abstract class SQLElement {
|
|||||||
return values.keySet().containsAll(fields.values());
|
return values.keySet().containsAll(fields.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<SQLField<?>, Object> getOnlyModifiedValues() {
|
private Map<SQLField<E, ?>, Object> getOnlyModifiedValues() {
|
||||||
Map<SQLField<?>, Object> modifiedValues = new LinkedHashMap<>();
|
Map<SQLField<E, ?>, Object> modifiedValues = new LinkedHashMap<>();
|
||||||
values.forEach((k, v) -> {
|
values.forEach((k, v) -> {
|
||||||
if (modifiedSinceLastSave.contains(k.name)) modifiedValues.put(k, v);
|
if (modifiedSinceLastSave.contains(k.name)) modifiedValues.put(k, v);
|
||||||
});
|
});
|
||||||
return modifiedValues;
|
return modifiedValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isModified(SQLField<?> field) {
|
public boolean isModified(SQLField<E, ?> field) {
|
||||||
return modifiedSinceLastSave.contains(field.name);
|
return modifiedSinceLastSave.contains(field.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void save() throws ORMException {
|
public void save() throws ORMException {
|
||||||
if (!isValidForSave())
|
if (!isValidForSave())
|
||||||
throw new IllegalStateException(toString() + " has at least one undefined value and can't be saved.");
|
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 = "";
|
String toStringStatement = "";
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -193,18 +195,17 @@ public abstract class SQLElement {
|
|||||||
|
|
||||||
// restaurer l'ID au cas il aurait été changé à la main dans
|
// restaurer l'ID au cas il aurait été changé à la main dans
|
||||||
// values
|
// values
|
||||||
@SuppressWarnings("unchecked")
|
SQLField<E, Integer> idField = (SQLField<E, Integer>) fields.get("id");
|
||||||
SQLField<Integer> idField = (SQLField<Integer>) fields.get("id");
|
|
||||||
values.put(idField, id);
|
values.put(idField, id);
|
||||||
modifiedSinceLastSave.remove("id");
|
modifiedSinceLastSave.remove("id");
|
||||||
Map<SQLField<?>, Object> modifiedValues = getOnlyModifiedValues();
|
Map<SQLField<E, ?>, Object> modifiedValues = getOnlyModifiedValues();
|
||||||
|
|
||||||
if (modifiedValues.isEmpty()) return;
|
if (modifiedValues.isEmpty()) return;
|
||||||
|
|
||||||
String sql = "";
|
String sql = "";
|
||||||
List<Object> psValues = new ArrayList<>();
|
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 + " = ? ,";
|
sql += entry.getKey().name + " = ? ,";
|
||||||
if (entry.getKey().type.getJavaType().isEnum()) // prise en
|
if (entry.getKey().type.getJavaType().isEnum()) // prise en
|
||||||
// charge
|
// charge
|
||||||
@ -244,7 +245,7 @@ public abstract class SQLElement {
|
|||||||
List<Object> psValues = new ArrayList<>();
|
List<Object> psValues = new ArrayList<>();
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Map.Entry<SQLField<?>, Object> entry : values.entrySet()) {
|
for (Map.Entry<SQLField<E, ?>, Object> entry : values.entrySet()) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
concat_vals += ",";
|
concat_vals += ",";
|
||||||
concat_fields += ",";
|
concat_fields += ",";
|
||||||
@ -305,8 +306,8 @@ public abstract class SQLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public SQLField<Integer> getFieldId() {
|
public SQLField<E, Integer> getFieldId() {
|
||||||
return (SQLField<Integer>) getFields().get("id");
|
return (SQLField<E, Integer>) fields.get("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() throws ORMException {
|
public void delete() throws ORMException {
|
||||||
@ -340,21 +341,24 @@ public abstract class SQLElement {
|
|||||||
values.forEach((k, v) -> modifiedSinceLastSave.add(k.name));
|
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 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;
|
sqlElemClass = elemClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addField(SQLField<?> f) {
|
private void addField(SQLField<?, ?> f) {
|
||||||
if (f == null) return;
|
if (f == null) return;
|
||||||
|
if (!sqlElemClass.equals(f.getSQLElementType())) return;
|
||||||
if (containsKey(f.name)) throw new IllegalArgumentException(
|
if (containsKey(f.name)) throw new IllegalArgumentException(
|
||||||
"SQLField " + f.name + " already exist in " + sqlElemClass.getName());
|
"SQLField " + f.name + " already exist in " + sqlElemClass.getName());
|
||||||
f.setSQLElementType(sqlElemClass);
|
@SuppressWarnings("unchecked")
|
||||||
put(f.name, f);
|
SQLField<E, ?> checkedF = (SQLField<E, ?>) f;
|
||||||
|
checkedF.setSQLElementType(sqlElemClass);
|
||||||
|
put(checkedF.name, checkedF);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -363,7 +367,7 @@ public abstract class SQLElement {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
ToStringBuilder b = new ToStringBuilder(this);
|
ToStringBuilder b = new ToStringBuilder(this);
|
||||||
|
|
||||||
for (SQLField<?> f : fields.values())
|
for (SQLField<E, ?> f : fields.values())
|
||||||
try {
|
try {
|
||||||
b.append(f.name, get(f));
|
b.append(f.name, get(f));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -373,4 +377,17 @@ public abstract class SQLElement {
|
|||||||
return b.toString();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -13,10 +13,10 @@ import fr.pandacube.java.util.Log;
|
|||||||
*
|
*
|
||||||
* @param <E>
|
* @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 static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final Map<SQLField<?>, Object> modifiedValues = new LinkedHashMap<>();
|
private final Map<SQLField<E, ?>, Object> modifiedValues = new LinkedHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean add(E e) {
|
public synchronized boolean add(E e) {
|
||||||
@ -37,10 +37,9 @@ public class SQLElementList<E extends SQLElement> extends ArrayList<E> {
|
|||||||
* @param field le champs à modifier
|
* @param field le champs à modifier
|
||||||
* @param value la valeur à lui appliquer
|
* @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")
|
if (field != null && field.name == "id")
|
||||||
throw new IllegalArgumentException("Can't modify id field in a SQLElementList");
|
throw new IllegalArgumentException("Can't modify id field in a SQLElementList");
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
|
|
||||||
Class<E> elemClass = (Class<E>) field.getSQLElementType();
|
Class<E> elemClass = (Class<E>) field.getSQLElementType();
|
||||||
try {
|
try {
|
||||||
@ -76,7 +75,7 @@ public class SQLElementList<E extends SQLElement> extends ArrayList<E> {
|
|||||||
String sqlSet = "";
|
String sqlSet = "";
|
||||||
List<Object> psValues = new ArrayList<>();
|
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 + " = ? ,";
|
sqlSet += entry.getKey().name + " = ? ,";
|
||||||
if (entry.getKey().type.getJavaType().isEnum()) // prise en charge
|
if (entry.getKey().type.getJavaType().isEnum()) // prise en charge
|
||||||
// enum (non prise
|
// enum (non prise
|
@ -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;
|
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 SQLField<F, T> sqlForeignKeyField;
|
||||||
private Class<E> sqlForeignKeyElement;
|
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);
|
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);
|
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,
|
public static <E extends SQLElement<E>, F extends SQLElement<F>> SQLFKField<E, Integer, F> idFK(String n, SQLType<Integer> t, boolean nul,
|
||||||
Class<E> fkEl) {
|
Class<F> fkEl) {
|
||||||
if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null");
|
if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null");
|
||||||
try {
|
try {
|
||||||
return new SQLFKField<>(n, t, nul, fkEl, ORM.getSQLIdField(fkEl));
|
return new SQLFKField<>(n, t, nul, ORM.getSQLIdField(fkEl));
|
||||||
} catch (ORMInitTableException e) {
|
} catch (ORMInitTableException e) {
|
||||||
Log.severe("Can't create Foreign key Field called '" + n + "'", e);
|
Log.severe("Can't create Foreign key Field called '" + n + "'", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <E extends SQLElement> SQLFKField<Integer, E> idFKField(String n, SQLType<Integer> t, boolean nul,
|
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<E> fkEl) {
|
Integer deflt, Class<F> fkEl) {
|
||||||
if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null");
|
if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null");
|
||||||
try {
|
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) {
|
} catch (ORMInitTableException e) {
|
||||||
Log.severe("Can't create Foreign key Field called '" + n + "'", e);
|
Log.severe("Can't create Foreign key Field called '" + n + "'", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void construct(Class<E> fkEl, SQLField<T> fkF) {
|
private void construct(SQLField<F, T> fkF) {
|
||||||
if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null");
|
|
||||||
if (fkF == null) throw new IllegalArgumentException("foreignKeyField can't be null");
|
if (fkF == null) throw new IllegalArgumentException("foreignKeyField can't be null");
|
||||||
|
Class<F> fkEl = fkF.getSQLElementType();
|
||||||
try {
|
try {
|
||||||
ORM.initTable(fkEl);
|
ORM.initTable(fkEl);
|
||||||
} catch (ORMInitTableException e) {
|
} catch (ORMInitTableException e) {
|
||||||
@ -53,15 +53,15 @@ public class SQLFKField<T, E extends SQLElement> extends SQLField<T> {
|
|||||||
if (!type.equals(fkF.type))
|
if (!type.equals(fkF.type))
|
||||||
throw new IllegalArgumentException("foreignKeyField and current Field must have the same SQLType");
|
throw new IllegalArgumentException("foreignKeyField and current Field must have the same SQLType");
|
||||||
sqlForeignKeyField = fkF;
|
sqlForeignKeyField = fkF;
|
||||||
sqlForeignKeyElement = fkEl;
|
sqlForeignKeyElemClass = fkEl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SQLField<T> getForeignField() {
|
public SQLField<F, T> getForeignField() {
|
||||||
return sqlForeignKeyField;
|
return sqlForeignKeyField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<E> getForeignElementClass() {
|
public Class<F> getForeignElementClass() {
|
||||||
return sqlForeignKeyElement;
|
return sqlForeignKeyElemClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javafx.util.Pair;
|
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 String name;
|
||||||
public final SQLType<T> type;
|
public final SQLType<T> type;
|
||||||
public final boolean canBeNull;
|
public final boolean canBeNull;
|
||||||
@ -42,11 +42,11 @@ public class SQLField<T> {
|
|||||||
+ ((defaultValue == null || autoIncrement) ? "" : " DEFAULT ?"), params);
|
+ ((defaultValue == null || autoIncrement) ? "" : " DEFAULT ?"), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void setSQLElementType(Class<? extends SQLElement> elemClass) {
|
/* package */ void setSQLElementType(Class<E> elemClass) {
|
||||||
sqlElemClass = elemClass;
|
sqlElemClass = elemClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<? extends SQLElement> getSQLElementType() {
|
public Class<E> getSQLElementType() {
|
||||||
return sqlElemClass;
|
return sqlElemClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public class SQLField<T> {
|
|||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj == null) return false;
|
if (obj == null) return false;
|
||||||
if (!(obj instanceof SQLField)) 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.name.equals(name)) return false;
|
||||||
if (!f.sqlElemClass.equals(sqlElemClass)) return false;
|
if (!f.sqlElemClass.equals(sqlElemClass)) return false;
|
||||||
return true;
|
return true;
|
@ -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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -19,7 +19,7 @@ public class SQLOrderBy {
|
|||||||
* @param d le sens de tri (croissant ASC ou décroissant DESC)
|
* @param d le sens de tri (croissant ASC ou décroissant DESC)
|
||||||
* @return l'objet courant (permet de chainer les ajouts de champs)
|
* @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));
|
orderByFields.add(new OBField(field, d));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ public class SQLOrderBy {
|
|||||||
* @param field le champ SQL à ordonner dans l'ordre croissant ASC
|
* @param field le champ SQL à ordonner dans l'ordre croissant ASC
|
||||||
* @return l'objet courant (permet de chainer les ajouts de champs)
|
* @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);
|
return addField(field, Direction.ASC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,10 +52,10 @@ public class SQLOrderBy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class OBField {
|
private class OBField {
|
||||||
public final SQLField<?> field;
|
public final SQLField<?, ?> field;
|
||||||
public final Direction direction;
|
public final Direction direction;
|
||||||
|
|
||||||
public OBField(SQLField<?> f, Direction d) {
|
public OBField(SQLField<?, ?> f, Direction d) {
|
||||||
field = f;
|
field = f;
|
||||||
direction = d;
|
direction = d;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package fr.pandacube.java.util.db2.sql_tools;
|
package fr.pandacube.java.util.db.sql_tools;
|
||||||
|
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package fr.pandacube.java.util.db2.sql_tools;
|
package fr.pandacube.java.util.db.sql_tools;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -7,7 +7,7 @@ import javafx.util.Pair;
|
|||||||
|
|
||||||
public class SQLWhereComp extends SQLWhere {
|
public class SQLWhereComp extends SQLWhere {
|
||||||
|
|
||||||
private SQLField<?> left;
|
private SQLField<?, ?> left;
|
||||||
private SQLComparator comp;
|
private SQLComparator comp;
|
||||||
private Object right;
|
private Object right;
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ public class SQLWhereComp extends SQLWhere {
|
|||||||
* @param c the comparison operator, can't be null
|
* @param c the comparison operator, can't be null
|
||||||
* @param r the value at right of 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)
|
if (l == null || r == null || c == null)
|
||||||
throw new IllegalArgumentException("All arguments for SQLWhereComp constructor can't be null");
|
throw new IllegalArgumentException("All arguments for SQLWhereComp constructor can't be null");
|
||||||
left = l;
|
left = l;
|
@ -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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -7,7 +7,7 @@ import javafx.util.Pair;
|
|||||||
|
|
||||||
public class SQLWhereLike extends SQLWhere {
|
public class SQLWhereLike extends SQLWhere {
|
||||||
|
|
||||||
private SQLField<String> field;
|
private SQLField<?, String> field;
|
||||||
private String likeExpr;
|
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 f the field at left of the LIKE keyword. Can't be null
|
||||||
* @param like the like expression.
|
* @param like the like expression.
|
||||||
*/
|
*/
|
||||||
public SQLWhereLike(SQLField<String> f, String like) {
|
public SQLWhereLike(SQLField<?, String> f, String like) {
|
||||||
if (f == null || like == null)
|
if (f == null || like == null)
|
||||||
throw new IllegalArgumentException("All arguments for SQLWhereLike constructor can't be null");
|
throw new IllegalArgumentException("All arguments for SQLWhereLike constructor can't be null");
|
||||||
field = f;
|
field = f;
|
@ -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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -9,7 +9,7 @@ import javafx.util.Pair;
|
|||||||
|
|
||||||
public class SQLWhereNull extends SQLWhere {
|
public class SQLWhereNull extends SQLWhere {
|
||||||
|
|
||||||
private SQLField<?> fild;
|
private SQLField<?, ?> fild;
|
||||||
private boolean nulll;
|
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
|
* @param isNull true if we want to ckeck if "IS NULL", or false to check if
|
||||||
* "IS NOT NULL"
|
* "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 == null) throw new IllegalArgumentException("field can't be null");
|
||||||
if (!field.canBeNull) Log.getLogger().log(Level.WARNING,
|
if (!field.canBeNull) Log.getLogger().log(Level.WARNING,
|
||||||
"Useless : Trying to check IS [NOT] NULL on the field " + field.getSQLElementType().getName() + "#"
|
"Useless : Trying to check IS [NOT] NULL on the field " + field.getSQLElementType().getName() + "#"
|
@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
|
||||||
|
|
||||||
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
|
||||||
|
|
||||||
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
|
||||||
|
|
||||||
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user