Suppression de l'imprementation de l'ORM pour la basede données Pandacube.

Les classes sont transféré dans un module privé.
This commit is contained in:
Marc Baloup 2016-12-28 00:54:06 +01:00
parent 37593e26f8
commit de056a35a5
24 changed files with 7 additions and 1363 deletions

View File

@ -27,13 +27,6 @@
<version>1.11-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>fr.pandacube.local_dependencies</groupId>
<artifactId>bungeeperms</artifactId>
<version>3.0-alpha1-modif</version>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/BungeePerms-3.0-alpha1-modif.jar</systemPath>
</dependency>
<dependency> <dependency>
<groupId>org.javatuples</groupId> <groupId>org.javatuples</groupId>
<artifactId>javatuples</artifactId> <artifactId>javatuples</artifactId>

View File

@ -1,4 +1,4 @@
package com.earth2me.essentials.utils; package fr.pandacube.java.util;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
@ -6,6 +6,10 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class DateUtil { public class DateUtil {
/**
* @see {@link com.earth2me.essentials.utils.DateUtil#parseDateDiff(String, boolean)}
*/
public static long parseDateDiff(String time, boolean future) throws Exception { public static long parseDateDiff(String time, boolean future) throws Exception {
Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?"
+ "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?"
@ -53,45 +57,4 @@ public class DateUtil {
return c.getTimeInMillis(); return c.getTimeInMillis();
} }
static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future) {
int diff = 0;
long savedDate = fromDate.getTimeInMillis();
while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate))) {
savedDate = fromDate.getTimeInMillis();
fromDate.add(type, future ? 1 : -1);
diff++;
}
diff--;
fromDate.setTimeInMillis(savedDate);
return diff;
}
public static String formatDateDiff(long date) {
Calendar c = new GregorianCalendar();
c.setTimeInMillis(date);
Calendar now = new GregorianCalendar();
return DateUtil.formatDateDiff(now, c);
}
public static String formatDateDiff(Calendar fromDate, Calendar toDate) {
boolean future = false;
if (toDate.equals(fromDate)) return "now";
if (toDate.after(fromDate)) future = true;
StringBuilder sb = new StringBuilder();
int[] types = new int[] { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY,
Calendar.MINUTE, Calendar.SECOND };
String[] names = new String[] { "year", "years", "month", "months", "day", "days", "hour", "hours", "minute",
"minutes", "second", "seconds" };
int accuracy = 0;
for (int i = 0; i < types.length; i++) {
if (accuracy > 2) break;
int diff = dateDiff(types[i], fromDate, toDate, future);
if (diff > 0) {
accuracy++;
sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
}
}
if (sb.length() == 0) return "now";
return sb.toString().trim();
}
} }

View File

@ -1,208 +0,0 @@
package fr.pandacube.java.util;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import fr.pandacube.java.util.db.SQLLoginHistory;
import fr.pandacube.java.util.db.SQLPlayer;
import fr.pandacube.java.util.db.SQLUUIDPlayer;
import fr.pandacube.java.util.db.sql_tools.ORM;
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereLike;
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy.Direction;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
import net.alpenblock.bungeeperms.BungeePerms;
/*
* Etape de recherche de joueur :
* Passer par bungeeperms (si accessible)
* utiliser directement la table pseudo <-> uuid
* chercher dans l'historique de login
*/
public class PlayerFinder {
private static BungeePerms getPermPlugin() {
try {
return BungeePerms.getInstance();
} catch (NoClassDefFoundError | Exception e) {
return null;
}
}
public static String getLastKnownName(UUID id) {
if (id == null) return null;
// on passe par le plugin de permission (mise en cache ? )
BungeePerms pl = getPermPlugin();
if (pl != null) return pl.getPermissionsManager().getUUIDPlayerDB().getPlayerName(id);
// on tente en accédant directement à la table des identifiants
try {
SQLUUIDPlayer el = ORM.getFirst(SQLUUIDPlayer.class,
new SQLWhereComp(SQLUUIDPlayer.uuid, SQLComparator.EQ, id.toString()), null);
if (el != null) return el.get(SQLUUIDPlayer.player);
} catch (Exception e) {
Log.severe("Can't search for player name from uuid in database", e);
}
// le pseudo est introuvable
return null;
}
public static List<String> getLocalNameHistory(UUID id) {
List<String> ret = new ArrayList<>();
if (id == null) return ret;
String last = getLastKnownName(id);
if (last != null) ret.add(last);
try {
List<SQLLoginHistory> els = ORM.getAll(SQLLoginHistory.class,
new SQLWhereComp(SQLLoginHistory.playerId, SQLComparator.EQ, id.toString()),
new SQLOrderBy().addField(SQLLoginHistory.time, Direction.DESC), null, null);
for (SQLLoginHistory el : els) {
String name = el.get(SQLLoginHistory.playerName);
if (ret.contains(name)) continue;
ret.add(name);
}
} catch (Exception e) {
Log.severe("Can't search for olds players names from uuid in database", e);
}
return ret;
}
/**
* Cherche un identifiant de compte en se basant sur le pseudo passé en
* paramètre. La méthode
* cherchera d'abord dans les derniers pseudos connus. Puis, cherchera la
* dernière personne à
* s'être connecté avec ce pseudo sur le serveur.
*
* @param exactName le pseudo complet, insensible à la casse, et dans un
* format de pseudo valide
* @param old si on doit chercher dans les anciens pseudos de joueurs
* @return l'UUID du joueur si trouvé, null sinon
*/
public static UUID getPlayerId(String exactName, boolean old) {
if (!isValidPlayerName(exactName)) return null; // évite une recherche
// inutile dans la base
// de donnée
// on tente d'abord via le plugin de permission
BungeePerms pl = getPermPlugin();
if (pl != null) return pl.getPermissionsManager().getUUIDPlayerDB().getUUID(exactName);
// on tente en accédant directement à la table des identifiants
try {
SQLUUIDPlayer el = ORM.getFirst(SQLUUIDPlayer.class,
new SQLWhereLike(SQLUUIDPlayer.player, exactName.replace("_", "\\_")), null);
if (el != null) return el.getUUID();
} catch (Exception e) {
Log.severe("Can't search for uuid from player name in database", e);
}
if (!old) return null;
// on recherche dans les anciens pseudos
try {
SQLLoginHistory el = ORM.getFirst(SQLLoginHistory.class,
new SQLWhereLike(SQLLoginHistory.playerName, exactName.replace("_", "\\_")),
new SQLOrderBy().addField(SQLLoginHistory.time, Direction.DESC));
if (el != null) return el.getPlayerId();
} catch (Exception e) {
Log.severe("Can't search for uuid from old player name in database", e);
}
// on a pas trouvé
return null;
}
/**
*
* @param query le pseudo, partiel ou complet, insensible à la casse, qu'on
* recherche
* @param old si on cherche aussi dans les anciens pseudos
* @return
*/
public static List<PlayerSearchResult> searchForPlayers(String query, boolean old) {
List<PlayerSearchResult> res = new ArrayList<>();
if (!isValidPlayerName(query)) return res;
// rechercher parmis les derniers pseudos connus de chaque joueurs
try {
List<SQLUUIDPlayer> els = ORM.getAll(SQLUUIDPlayer.class,
new SQLWhereLike(SQLUUIDPlayer.player, "%" + query.replace("_", "\\_") + "%"), null, null, null);
for (SQLUUIDPlayer el : els)
res.add(new PlayerSearchResult(el.getUUID(), el.get(SQLUUIDPlayer.player), null));
} catch (Exception e) {
Log.severe("Can't search for players names in database", e);
}
if (!old) return res;
// rechercher parmi les anciens pseudos de joueurs
try {
List<SQLLoginHistory> els = ORM.getAll(SQLLoginHistory.class,
new SQLWhereLike(SQLLoginHistory.playerName, "%" + query.replace("_", "\\_") + "%"),
new SQLOrderBy().addField(SQLLoginHistory.time, Direction.DESC), null, null);
for (SQLLoginHistory el : els) {
if (res.contains(new PlayerSearchResult(el.getPlayerId(), null, null))) continue;
res.add(new PlayerSearchResult(el.getPlayerId(), getLastKnownName(el.getPlayerId()),
el.get(SQLLoginHistory.playerName)));
}
} catch (Exception e) {
Log.severe("Can't search for uuid from player name in database", e);
}
return res;
}
public static class PlayerSearchResult {
public final UUID uuid;
public String lastName;
public final String nameFound;
PlayerSearchResult(UUID id, String last, String found) {
uuid = id;
lastName = last;
nameFound = found;
}
@Override
public boolean equals(Object o) {
if (o == null || !(o instanceof PlayerSearchResult)) return false;
return uuid.equals(((PlayerSearchResult) o).uuid);
}
@Override
public int hashCode() {
return uuid.hashCode();
}
}
public static boolean isValidPlayerName(String name) {
if (name == null) return false;
return name.matches("[0-9a-zA-Z_]{2,16}");
}
public static SQLPlayer getDBPlayer(UUID id) throws Exception {
if (id == null) return null;
return ORM.getFirst(SQLPlayer.class, new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, id.toString()),
null);
}
}

View File

@ -1,43 +0,0 @@
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.class, SQLPlayer.playerId);
public static final SQLField<SQLContact, String> userName = new SQLField<>("userName", SQLType.VARCHAR(50), true);
public static final SQLField<SQLContact, String> userMail = new SQLField<>("userMail", SQLType.VARCHAR(50), true);
public static final SQLField<SQLContact, String> titre = new SQLField<>("titre", SQLType.VARCHAR(100), false);
public static final SQLField<SQLContact, String> texte = new SQLField<>("texte", SQLType.TEXT, false);
public static final SQLField<SQLContact, Boolean> hidden = new SQLField<>("hidden", SQLType.BOOLEAN, false, (Boolean) false);
public UUID getPlayerId() {
String id = get(playerId);
return (id == null) ? null : UUID.fromString(id);
}
public void setPlayerId(UUID pName) {
set(playerId, (pName == null) ? (String) null : pName.toString());
}
}

View File

@ -1,25 +0,0 @@
package fr.pandacube.java.util.db;
import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLField;
import fr.pandacube.java.util.db.sql_tools.SQLType;
public class SQLForumCategorie extends SQLElement<SQLForumCategorie> {
public SQLForumCategorie() {
super();
}
public SQLForumCategorie(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_forum_categorie";
}
public static final SQLField<SQLForumCategorie, String> nom = new SQLField<>("nom", SQLType.VARCHAR(100), false);
public static final SQLField<SQLForumCategorie, Integer> ordre = new SQLField<>("ordre", SQLType.INT, false);
}

View File

@ -1,36 +0,0 @@
package fr.pandacube.java.util.db;
import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLFKField;
import fr.pandacube.java.util.db.sql_tools.SQLField;
import fr.pandacube.java.util.db.sql_tools.SQLType;
public class SQLForumForum extends SQLElement<SQLForumForum> {
public SQLForumForum() {
super();
}
public SQLForumForum(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_forum_forum";
}
public static final SQLFKField<SQLForumForum, Integer, SQLForumCategorie> catId = SQLFKField.idFK("catId", SQLType.INT, false,
SQLForumCategorie.class);
public static final SQLField<SQLForumForum, String> nom = new SQLField<>("nom", SQLType.VARCHAR(100), false);
public static final SQLField<SQLForumForum, String> description = new SQLField<>("description", SQLType.TEXT, false);
public static final SQLField<SQLForumForum, Integer> ordre = new SQLField<>("ordre", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authView = new SQLField<>("authView", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authPost = new SQLField<>("authPost", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authThread = new SQLField<>("authThread", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authAnchored = new SQLField<>("authAnchored", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> authModo = new SQLField<>("authModo", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> nbThreads = new SQLField<>("nbThreads", SQLType.INT, false);
public static final SQLField<SQLForumForum, Integer> nbMessages = new SQLField<>("nbMessages", SQLType.INT, false);
}

View File

@ -1,41 +0,0 @@
package fr.pandacube.java.util.db;
import java.util.UUID;
import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLFKField;
import fr.pandacube.java.util.db.sql_tools.SQLField;
import fr.pandacube.java.util.db.sql_tools.SQLType;
public class SQLForumPost extends SQLElement<SQLForumPost> {
public SQLForumPost() {
super();
}
public SQLForumPost(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_forum_post";
}
public static final SQLField<SQLForumPost, String> createur = new SQLField<>("createur", SQLType.CHAR(36), false);
public static final SQLField<SQLForumPost, String> texte = new SQLField<>("texte", SQLType.TEXT, false);
public static final SQLField<SQLForumPost, Integer> time = new SQLField<>("time", SQLType.INT, false);
public static final SQLFKField<SQLForumPost, Integer, SQLForumThread> threadId = SQLFKField.idFK("threadId", SQLType.INT, false,
SQLForumThread.class);
public static final SQLField<SQLForumPost, Boolean> moderated = new SQLField<>("moderated", SQLType.BOOLEAN, false);
public UUID getCreateurId() {
String id = get(createur);
return (id == null) ? null : UUID.fromString(id);
}
public void setCreateurId(UUID pName) {
set(createur, (pName == null) ? (String) null : pName.toString());
}
}

View File

@ -1,45 +0,0 @@
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.class, SQLPlayer.playerId);
public static final SQLField<SQLForumThread, Integer> vu = new SQLField<>("vu", SQLType.INT, false);
public static final SQLField<SQLForumThread, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLField<SQLForumThread, Boolean> anchored = new SQLField<>("anchored", SQLType.BOOLEAN, false);
public static final SQLField<SQLForumThread, Boolean> locked = new SQLField<>("locked", SQLType.BOOLEAN, false);
public static final SQLField<SQLForumThread, Integer> nbMessages = new SQLField<>("nbMessages", SQLType.INT, false);
public UUID getCreateurId() {
String id = get(createur);
return (id == null) ? null : UUID.fromString(id);
}
public void setCreateurId(UUID pName) {
set(createur, (pName == null) ? (String) null : pName.toString());
}
}

View File

@ -1,48 +0,0 @@
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.class, 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 static final SQLField<SQLLoginHistory, String> hostName = new SQLField<>("hostName", SQLType.VARCHAR(128), true);
public UUID getPlayerId() {
String id = get(playerId);
return (id == null) ? null : UUID.fromString(id);
}
public void setPlayerId(UUID pName) {
set(playerId, (pName == null) ? (String) null : pName.toString());
}
public enum ActionType {
LOGIN, LOGOUT
}
}

View File

@ -1,42 +0,0 @@
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 SQLLoginKickHistory extends SQLElement<SQLLoginKickHistory> {
public SQLLoginKickHistory() {
super();
}
public SQLLoginKickHistory(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_loginkick_history";
}
public static final SQLField<SQLLoginKickHistory, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLFKField<SQLLoginKickHistory, String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<SQLLoginKickHistory, String> ip = new SQLField<>("ip", SQLType.VARCHAR(128), true);
public static final SQLField<SQLLoginKickHistory, String> playerName = new SQLField<>("playerName", SQLType.VARCHAR(16), true);
public static final SQLField<SQLLoginKickHistory, Integer> minecraftVersion = new SQLField<>("minecraftVersion", SQLType.INT, false, 0);
public static final SQLField<SQLLoginKickHistory, String> hostName = new SQLField<>("hostName", SQLType.VARCHAR(128), true);
public static final SQLField<SQLLoginKickHistory, String> kickReason = new SQLField<>("kickReason", SQLType.VARCHAR(512), true);
public UUID getPlayerId() {
String id = get(playerId);
return (id == null) ? null : UUID.fromString(id);
}
public void setPlayerId(UUID pName) {
set(playerId, (pName == null) ? (String) null : pName.toString());
}
}

View File

@ -1,41 +0,0 @@
package fr.pandacube.java.util.db;
import fr.pandacube.java.util.db.sql_tools.ORM;
import fr.pandacube.java.util.db.sql_tools.ORMException;
import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLElementList;
import fr.pandacube.java.util.db.sql_tools.SQLField;
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy;
import fr.pandacube.java.util.db.sql_tools.SQLType;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
public class SQLMPGroup extends SQLElement<SQLMPGroup> {
public SQLMPGroup() {
super();
}
public SQLMPGroup(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_mp_group";
}
public static final SQLField<SQLMPGroup, String> groupName = new SQLField<>("groupName", SQLType.VARCHAR(16), false);
public SQLElementList<SQLMPGroupUser> getGroupUsers() throws ORMException {
return ORM.getAll(SQLMPGroupUser.class, new SQLWhereComp(SQLMPGroupUser.groupId, SQLComparator.EQ, getId()),
new SQLOrderBy().addField(ORM.getSQLIdField(SQLMPGroupUser.class)), null, null);
}
public static SQLMPGroup getByName(String name) throws ORMException {
if (name == null) return null;
return ORM.getFirst(SQLMPGroup.class, new SQLWhereComp(groupName, SQLComparator.EQ, name), null);
}
}

View File

@ -1,63 +0,0 @@
package fr.pandacube.java.util.db;
import java.sql.SQLException;
import java.util.UUID;
import fr.pandacube.java.util.db.sql_tools.ORM;
import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLFKField;
import fr.pandacube.java.util.db.sql_tools.SQLType;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
public class SQLMPGroupUser extends SQLElement<SQLMPGroupUser> {
public SQLMPGroupUser() {
super();
}
public SQLMPGroupUser(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_mp_group_user";
}
public static final SQLFKField<SQLMPGroupUser, Integer, SQLMPGroup> groupId = SQLFKField.idFK("groupId", SQLType.INT, false,
SQLMPGroup.class);
public static final SQLFKField<SQLMPGroupUser, String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
// TODO ajouter un champ qui dit si le joueur est admin du groupe
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());
}
/**
* Retourne l'instance de SQLMPGroupUser correcpondant à la présence d'un
* joueur dans un groupe
*
* @param group le groupe concerné, sous forme d'instance de SQLMPGroup
* @param player l'identifiant du joueur
* @return null si la correspondance n'a pas été trouvée
* @throws SQLException
*/
public static SQLMPGroupUser getPlayerInGroup(SQLMPGroup group, UUID player) throws Exception {
if (player == null || group == null) return null;
return ORM.getFirst(SQLMPGroupUser.class,
new SQLWhereChain(SQLBoolOp.AND).add(new SQLWhereComp(groupId, SQLComparator.EQ, group.getId()))
.add(new SQLWhereComp(playerId, SQLComparator.EQ, player.toString())),
null);
}
}

View File

@ -1,137 +0,0 @@
package fr.pandacube.java.util.db;
import java.util.UUID;
import fr.pandacube.java.util.PlayerFinder;
import fr.pandacube.java.util.db.sql_tools.ORM;
import fr.pandacube.java.util.db.sql_tools.ORMException;
import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLElementList;
import fr.pandacube.java.util.db.sql_tools.SQLFKField;
import fr.pandacube.java.util.db.sql_tools.SQLField;
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy;
import fr.pandacube.java.util.db.sql_tools.SQLType;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereLike;
import fr.pandacube.java.util.db.sql_tools.SQLWhereNull;
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy.Direction;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
public class SQLMPMessage extends SQLElement<SQLMPMessage> {
public SQLMPMessage() {
super();
}
public SQLMPMessage(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_mp_message";
}
public static final SQLField<SQLMPMessage, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLField<SQLMPMessage, Integer> securityKey = new SQLField<>("securityKey", SQLType.INT, false);
public static final SQLFKField<SQLMPMessage, String, SQLPlayer> viewerId = new SQLFKField<>("viewerId", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<SQLMPMessage, String, SQLPlayer> sourceId = new SQLFKField<>("sourceId", SQLType.CHAR(36), true,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<SQLMPMessage, String, SQLPlayer> destId = new SQLFKField<>("destId", SQLType.CHAR(36), true,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<SQLMPMessage, Integer, SQLMPGroup> destGroup = SQLFKField.idFK("destGroup", SQLType.INT, true,
SQLMPGroup.class);
public static final SQLField<SQLMPMessage, String> message = new SQLField<>("message", SQLType.VARCHAR(512), false);
public static final SQLField<SQLMPMessage, Boolean> wasRead = new SQLField<>("wasRead", SQLType.BOOLEAN, false);
public static final SQLField<SQLMPMessage, Boolean> deleted = new SQLField<>("deleted", SQLType.BOOLEAN, false, (Boolean) false);
public static final SQLField<SQLMPMessage, Boolean> serverSync = new SQLField<>("serverSync", SQLType.BOOLEAN, false);
public UUID getViewerId() {
String id = get(viewerId);
return (id == null) ? null : UUID.fromString(id);
}
public void setViewerId(UUID id) {
set(viewerId, (id == null) ? null : id.toString());
}
public UUID getSourceId() {
String id = get(sourceId);
return (id == null) ? null : UUID.fromString(id);
}
public void setSourceId(UUID id) {
set(sourceId, (id == null) ? null : id.toString());
}
public UUID getDestId() {
String id = get(destId);
return (id == null) ? null : UUID.fromString(id);
}
public void setDestId(UUID id) {
set(destId, (id == null) ? null : id.toString());
}
public static SQLElementList<SQLMPMessage> getAllUnsyncMessage() throws ORMException {
return ORM.getAll(SQLMPMessage.class, new SQLWhereComp(SQLMPMessage.serverSync, SQLComparator.EQ, false),
new SQLOrderBy().addField(SQLMPMessage.time), null, null);
}
public static SQLElementList<SQLMPMessage> getAllUnreadForPlayer(UUID player) throws ORMException {
return getForPlayer(player, true, null, false);
}
public static SQLElementList<SQLMPMessage> getOneDiscussionForPlayer(UUID player, Object discussion,
Integer numberLast, boolean revert) throws ORMException {
if (player == null) return null;
if (discussion != null && !(discussion instanceof String) && !(discussion instanceof UUID)) return null;
if (discussion != null && discussion instanceof String
&& !PlayerFinder.isValidPlayerName(discussion.toString()))
return null;
SQLWhereChain where = new SQLWhereChain(SQLBoolOp.AND)
.add(new SQLWhereComp(SQLMPMessage.viewerId, SQLComparator.EQ, player.toString()));
if (discussion == null) // message de système
where.add(new SQLWhereNull(SQLMPMessage.sourceId, true))
.add(new SQLWhereNull(SQLMPMessage.destGroup, true));
else if (discussion instanceof String) { // message de groupe
SQLMPGroup groupEl = ORM.getFirst(SQLMPGroup.class,
new SQLWhereComp(SQLMPGroup.groupName, SQLComparator.EQ, (String) discussion), null);
if (groupEl == null) return null;
where.add(new SQLWhereComp(SQLMPMessage.destGroup, SQLComparator.EQ, groupEl.getId()));
}
else if (discussion instanceof UUID && discussion.equals(player)) // message
// à
// lui
// même
where.add(new SQLWhereLike(SQLMPMessage.destId, discussion.toString()))
.add(new SQLWhereLike(SQLMPMessage.sourceId, discussion.toString()))
.add(new SQLWhereNull(SQLMPMessage.destGroup, true));
else // discussion instanceof UUID
where.add(new SQLWhereChain(SQLBoolOp.OR).add(new SQLWhereLike(SQLMPMessage.destId, discussion.toString()))
.add(new SQLWhereLike(SQLMPMessage.sourceId, discussion.toString())))
.add(new SQLWhereNull(SQLMPMessage.destGroup, true));
SQLOrderBy orderBy = new SQLOrderBy().addField(SQLMPMessage.time, revert ? Direction.DESC : Direction.ASC);
return ORM.getAll(SQLMPMessage.class, where, orderBy, numberLast, null);
}
public static SQLElementList<SQLMPMessage> getForPlayer(UUID player, boolean onlyUnread, Integer numberLast,
boolean revert) throws ORMException {
if (player == null) return null;
SQLWhereChain where = new SQLWhereChain(SQLBoolOp.AND);
where.add(new SQLWhereComp(SQLMPMessage.viewerId, SQLComparator.EQ, player.toString()));
if (onlyUnread) where.add(new SQLWhereComp(SQLMPMessage.wasRead, SQLComparator.EQ, false));
SQLOrderBy orderBy = new SQLOrderBy().addField(SQLMPMessage.time, revert ? Direction.DESC : Direction.ASC);
return ORM.getAll(SQLMPMessage.class, where, orderBy, numberLast, null);
}
}

View File

@ -1,57 +0,0 @@
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.class, 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.class, 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(2048), false);
public UUID getModoId() {
String id = get(modoId);
return (id == null) ? null : UUID.fromString(id);
}
public void setModoId(UUID pName) {
set(modoId, (pName == null) ? (String) null : pName.toString());
}
public UUID getPlayerId() {
String id = get(playerId);
return (id == null) ? null : UUID.fromString(id);
}
public void setPlayerId(UUID pName) {
set(playerId, (pName == null) ? (String) null : pName.toString());
}
public enum ActionType {
BAN, UNBAN, MUTE, UNMUTE, REPORT, KICK
}
}

View File

@ -1,65 +0,0 @@
package fr.pandacube.java.util.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.class, 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.class, SQLPlayer.playerId);
public static final SQLField<SQLOnlineshopHistory, Double> destQuantity = new SQLField<>("destQuantity", SQLType.DOUBLE, false);
public static final SQLField<SQLOnlineshopHistory, String> destName = new SQLField<>("destName", SQLType.VARCHAR(64), false);
public UUID getSourcePlayerId() {
String id = get(sourcePlayerId);
return (id == null) ? null : UUID.fromString(id);
}
public void setSourcePlayerId(UUID pName) {
set(sourcePlayerId, (pName == null) ? (String) null : pName.toString());
}
public UUID getDestPlayerId() {
String id = get(destPlayerId);
return (id == null) ? null : UUID.fromString(id);
}
public void setDestPlayerId(UUID pName) {
set(destPlayerId, (pName == null) ? (String) null : pName.toString());
}
public static enum SourceType {
REAL_MONEY, BAMBOU
}
public static enum DestType {
BAMBOU, GRADE
}
}

View File

@ -1,30 +0,0 @@
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 SQLPingHistory extends SQLElement<SQLPingHistory> {
public SQLPingHistory() {
super();
}
public SQLPingHistory(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_ping_history";
}
public static final SQLField<SQLPingHistory, Long> time = new SQLField<>("time", SQLType.BIGINT, false);
public static final SQLField<SQLPingHistory, String> ip = new SQLField<>("ip", SQLType.VARCHAR(128), true);
public static final SQLField<SQLPingHistory, Integer> minecraftVersion = new SQLField<>("minecraftVersion", SQLType.INT, false, 0);
public static final SQLField<SQLPingHistory, String> hostName = new SQLField<>("hostName", SQLType.VARCHAR(128), true);
}

View File

@ -1,119 +0,0 @@
package fr.pandacube.java.util.db;
import java.sql.Date;
import java.util.HashSet;
import java.util.Set;
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.SQLElementList;
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.SQLWhereChain;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
public class 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);
}
public static SQLElementList<SQLPlayer> getPlayersFromUUIDs(Set<UUID> playerIds) throws ORMException {
Set<String> uuidsString = new HashSet<>();
for (UUID id : playerIds)
uuidsString.add(id.toString());
return getPlayersFromUUIDStr(uuidsString);
}
public static SQLElementList<SQLPlayer> getPlayersFromUUIDStr(Set<String> playerIds) throws ORMException {
SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR);
for (String userId : playerIds) {
where.add(new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, userId));
}
return ORM.getAll(SQLPlayer.class, where, null, null, null);
}
}

View File

@ -1,91 +0,0 @@
package fr.pandacube.java.util.db;
import java.util.Map;
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.SQLElementList;
import fr.pandacube.java.util.db.sql_tools.SQLFKField;
import fr.pandacube.java.util.db.sql_tools.SQLType;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
public class SQLPlayerIgnore extends SQLElement<SQLPlayerIgnore> {
public SQLPlayerIgnore() {
super();
}
public SQLPlayerIgnore(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_player_ignore";
}
public static final SQLFKField<SQLPlayerIgnore, String, SQLPlayer> ignorer = new SQLFKField<>("ignorer", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLFKField<SQLPlayerIgnore, String, SQLPlayer> ignored = new SQLFKField<>("ignored", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public UUID getIgnorerId() {
String id = get(ignorer);
return (id == null) ? null : UUID.fromString(id);
}
public void setIgnorerId(UUID pName) {
set(ignorer, (pName == null) ? (String) null : pName.toString());
}
public UUID getIgnoredId() {
String id = get(ignored);
return (id == null) ? null : UUID.fromString(id);
}
public void setIgnoredId(UUID pName) {
set(ignored, (pName == null) ? (String) null : pName.toString());
}
public static SQLPlayerIgnore getPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws ORMException {
return ORM.getFirst(SQLPlayerIgnore.class,
new SQLWhereChain(SQLBoolOp.AND)
.add(new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString()))
.add(new SQLWhereComp(SQLPlayerIgnore.ignored, SQLComparator.EQ, ignored.toString())),
null);
}
public static boolean isPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws ORMException {
return getPlayerIgnoringPlayer(ignorer, ignored) != null;
}
public static void setPlayerIgnorePlayer(UUID ignorer, UUID ignored, boolean newIgnoreState) throws ORMException {
SQLPlayerIgnore el = getPlayerIgnoringPlayer(ignorer, ignored);
if (el == null && newIgnoreState) {
el = new SQLPlayerIgnore();
el.setIgnorerId(ignorer);
el.setIgnoredId(ignored);
el.save();
return;
}
if (el != null && !newIgnoreState) {
el.delete();
return;
}
}
public static Map<String, SQLPlayer> getIgnoredPlayer(UUID ignorer) throws ORMException {
SQLElementList<SQLPlayerIgnore> els = ORM.getAll(SQLPlayerIgnore.class,
new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString()),
null, null, null);
return els.getAllForeign(SQLPlayerIgnore.ignored);
}
}

View File

@ -1,29 +0,0 @@
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 SQLPlayerTexture extends SQLElement<SQLPlayerTexture> {
public SQLPlayerTexture() {
super();
}
public SQLPlayerTexture(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_player_texture";
}
public static final SQLFKField<SQLPlayerTexture, String, SQLPlayer> playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false,
SQLPlayer.class, SQLPlayer.playerId);
public static final SQLField<SQLPlayerTexture, String> alias = new SQLField<>("alias", SQLType.VARCHAR(64), false);
public static final SQLField<SQLPlayerTexture, String> textureData = new SQLField<>("textureData", SQLType.TEXT, false);
public static final SQLField<SQLPlayerTexture, String> textureSignature = new SQLField<>("textureSignature", SQLType.VARCHAR(8192), false);
}

View File

@ -1,27 +0,0 @@
package fr.pandacube.java.util.db;
import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLField;
import fr.pandacube.java.util.db.sql_tools.SQLType;
public class SQLShopStock extends SQLElement<SQLShopStock> {
public SQLShopStock() {
super();
}
public SQLShopStock(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_shop_stock";
}
public static final SQLField<SQLShopStock, String> material = new SQLField<>("material", SQLType.VARCHAR(50), false);
public static final SQLField<SQLShopStock, Integer> damage = new SQLField<>("damage", SQLType.INT, false, 0);
public static final SQLField<SQLShopStock, Double> quantity = new SQLField<>("quantity", SQLType.DOUBLE, false);
public static final SQLField<SQLShopStock, String> server = new SQLField<>("server", SQLType.VARCHAR(50), false);
}

View File

@ -1,50 +0,0 @@
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.class, 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.class, SQLPlayer.playerId);
public UUID getPlayerId() {
String id = get(playerId);
return (id == null) ? null : UUID.fromString(id);
}
public void setPlayerId(UUID id) {
set(playerId, (id == null) ? null : id.toString());
}
public UUID getstaffPlayerId() {
String id = get(staffPlayerId);
return (id == null) ? null : UUID.fromString(id);
}
public void setstaffPlayerId(UUID id) {
set(staffPlayerId, (id == null) ? null : id.toString());
}
}

View File

@ -1,28 +0,0 @@
package fr.pandacube.java.util.db;
import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLField;
import fr.pandacube.java.util.db.sql_tools.SQLType;
public class SQLStaticPages extends SQLElement<SQLStaticPages> {
public SQLStaticPages() {
super();
}
public SQLStaticPages(int id) {
super(id);
}
@Override
protected String tableName() {
return "pandacube_static_pages";
}
public static final SQLField<SQLStaticPages, String> permalink = new SQLField<>("permalink", SQLType.VARCHAR(128), false);
public static final SQLField<SQLStaticPages, String> titreHead = new SQLField<>("titreHead", SQLType.VARCHAR(128), false);
public static final SQLField<SQLStaticPages, String> titreH2 = new SQLField<>("titreH2", SQLType.VARCHAR(255), false);
public static final SQLField<SQLStaticPages, String> texte = new SQLField<>("texte", SQLType.TEXT, false);
public static final SQLField<SQLStaticPages, String> permissions = new SQLField<>("permissions", SQLType.VARCHAR(255), true);
}

View File

@ -1,38 +0,0 @@
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.class, SQLPlayer.playerId);
public static final SQLField<SQLUUIDPlayer, String> player = new SQLField<>("player", SQLType.VARCHAR(16), false);
public UUID getUUID() {
String id = get(uuid);
return (id == null) ? null : UUID.fromString(id);
}
public void setUUID(UUID id) {
set(uuid, (id == null) ? null : id.toString());
}
}

View File

@ -6,29 +6,9 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
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.db.SQLContact;
import fr.pandacube.java.util.db.SQLForumCategorie;
import fr.pandacube.java.util.db.SQLForumForum;
import fr.pandacube.java.util.db.SQLForumPost;
import fr.pandacube.java.util.db.SQLForumThread;
import fr.pandacube.java.util.db.SQLLoginHistory;
import fr.pandacube.java.util.db.SQLLoginKickHistory;
import fr.pandacube.java.util.db.SQLMPGroup;
import fr.pandacube.java.util.db.SQLMPGroupUser;
import fr.pandacube.java.util.db.SQLMPMessage;
import fr.pandacube.java.util.db.SQLModoHistory;
import fr.pandacube.java.util.db.SQLOnlineshopHistory;
import fr.pandacube.java.util.db.SQLPingHistory;
import fr.pandacube.java.util.db.SQLPlayer;
import fr.pandacube.java.util.db.SQLPlayerIgnore;
import fr.pandacube.java.util.db.SQLShopStock;
import fr.pandacube.java.util.db.SQLStaffTicket;
import fr.pandacube.java.util.db.SQLStaticPages;
import fr.pandacube.java.util.db.SQLUUIDPlayer;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
import org.javatuples.Pair; import org.javatuples.Pair;
@ -49,43 +29,14 @@ public final class ORM {
return connection; return connection;
} }
public synchronized static void init(DBConnection conn) { public synchronized static <E extends SQLElement<E>> void init(DBConnection conn) {
connection = conn; connection = conn;
/*
* Les tables à initialiser
* utile des les initialiser ici, car on peut tout de suite déceler les
* bugs ou erreurs dans la déclaration des SQLFields
*/
try {
initTable(SQLContact.class);
initTable(SQLForumCategorie.class);
initTable(SQLForumForum.class);
initTable(SQLForumPost.class);
initTable(SQLForumThread.class);
initTable(SQLLoginHistory.class);
initTable(SQLLoginKickHistory.class);
initTable(SQLModoHistory.class);
initTable(SQLMPGroup.class);
initTable(SQLMPGroupUser.class);
initTable(SQLMPMessage.class);
initTable(SQLOnlineshopHistory.class);
initTable(SQLPingHistory.class);
initTable(SQLPlayer.class);
initTable(SQLPlayerIgnore.class);
initTable(SQLShopStock.class);
initTable(SQLStaffTicket.class);
initTable(SQLStaticPages.class);
initTable(SQLUUIDPlayer.class);
} catch (ORMInitTableException e) {
Log.getLogger().log(Level.SEVERE, "Erreur d'initialisation d'une table dans l'ORM", e);
}
} }
/* package */ static synchronized <E extends SQLElement<E>> void initTable(Class<E> elemClass) throws ORMInitTableException { public static synchronized <E extends SQLElement<E>> void initTable(Class<E> elemClass) throws ORMInitTableException {
if (tables.contains(elemClass)) return; if (tables.contains(elemClass)) return;
try { try {
tables.add(elemClass); tables.add(elemClass);