Mise à jour ORM + Utilisation plus simple des logs
- toute la base de données fonctionne en utf8mb4 - Le PlayerFinder gère l'historique des pseudos - Fin de l'utilisation de l'ancien ORM
This commit is contained in:
parent
159cbe52af
commit
b2a19e09c1
16
src/fr/pandacube/java/Pandacube.java
Normal file
16
src/fr/pandacube/java/Pandacube.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package fr.pandacube.java;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
public class Pandacube {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static final Charset NETWORK_CHARSET = Charset.forName("UTF-8");
|
||||||
|
|
||||||
|
public static final int NETWORK_TCP_BUFFER_SIZE = 1024*1024;
|
||||||
|
|
||||||
|
public static final int NETWORK_TIMEOUT = 30*1000; // 30 secondes
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,45 +0,0 @@
|
|||||||
package fr.pandacube.java;
|
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class PandacubeUtil {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final Charset NETWORK_CHARSET = Charset.forName("UTF-8");
|
|
||||||
|
|
||||||
public static final int NETWORK_TCP_BUFFER_SIZE = 1024*1024;
|
|
||||||
|
|
||||||
public static final int NETWORK_TIMEOUT = 30*1000; // 30 secondes
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Représente le logger du serveur Spigot ou de Bungee,selon l'environnement
|
|
||||||
*/
|
|
||||||
private static Logger masterLogger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Représente le logger de PandacubeUtil, mais défini selon l'environnement Spigot ou Bungee.
|
|
||||||
*/
|
|
||||||
private static Logger pluginLogger;
|
|
||||||
|
|
||||||
public static Logger getMasterLogger() {
|
|
||||||
return masterLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setMasterLogger(Logger masterLogger) {
|
|
||||||
PandacubeUtil.masterLogger = masterLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Logger getPluginLogger() {
|
|
||||||
return pluginLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setPluginLogger(Logger pluginLogger) {
|
|
||||||
PandacubeUtil.pluginLogger = pluginLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
46
src/fr/pandacube/java/util/Log.java
Normal file
46
src/fr/pandacube/java/util/Log.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package fr.pandacube.java.util;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class Log {
|
||||||
|
|
||||||
|
private static Logger logger;
|
||||||
|
|
||||||
|
public static Logger getLogger() {
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLogger(Logger l) {
|
||||||
|
logger = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info(String message) {
|
||||||
|
logger.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(String message, Throwable t) {
|
||||||
|
logger.log(Level.WARNING, message, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(Throwable t) {
|
||||||
|
logger.log(Level.WARNING, "", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(String message) {
|
||||||
|
logger.warning(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void severe(String message, Throwable t) {
|
||||||
|
logger.log(Level.SEVERE, message, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void severe(Throwable t) {
|
||||||
|
logger.log(Level.SEVERE, "", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void severe(String message) {
|
||||||
|
logger.severe(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,26 @@
|
|||||||
package fr.pandacube.java.util;
|
package fr.pandacube.java.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import fr.pandacube.java.util.db2.SQLLoginHistory;
|
||||||
|
import fr.pandacube.java.util.db2.SQLPlayer;
|
||||||
|
import fr.pandacube.java.util.db2.SQLUUIDPlayer;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.ORM;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy.Direction;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereLike;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
import net.alpenblock.bungeeperms.BungeePerms;
|
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 {
|
public class PlayerFinder {
|
||||||
|
|
||||||
private static BungeePerms getPermPlugin() {
|
private static BungeePerms getPermPlugin() {
|
||||||
@ -17,22 +34,104 @@ public class PlayerFinder {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static String getLastKnownName(UUID id) {
|
||||||
|
if (id == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
public static String getPlayerName(UUID id) {
|
// on passe par le plugin de permission (mise en cache ? )
|
||||||
BungeePerms pl = getPermPlugin();
|
BungeePerms pl = getPermPlugin();
|
||||||
if (pl == null) return null;
|
if (pl != null)
|
||||||
|
|
||||||
return pl.getPermissionsManager().getUUIDPlayerDB().getPlayerName(id);
|
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 UUID getPlayerId(String name) {
|
|
||||||
if (!isValidPlayerName(name)) return null; // évite une recherche inutile dans la base de donnée
|
|
||||||
|
|
||||||
|
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();
|
BungeePerms pl = getPermPlugin();
|
||||||
if (pl == null) return null;
|
if (pl != null)
|
||||||
|
return pl.getPermissionsManager().getUUIDPlayerDB().getUUID(exactName);
|
||||||
|
|
||||||
return pl.getPermissionsManager().getUUIDPlayerDB().getUUID(name);
|
// 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +139,81 @@ public class PlayerFinder {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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) {
|
public static boolean isValidPlayerName(String name) {
|
||||||
if (name == null) return false;
|
if (name == null) return false;
|
||||||
@ -49,4 +223,16 @@ public class PlayerFinder {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
package fr.pandacube.java.util.db;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
public class DBConnection {
|
|
||||||
Connection conn;
|
|
||||||
private String url;
|
|
||||||
private String login;
|
|
||||||
private String pass;
|
|
||||||
|
|
||||||
public DBConnection(String host, int port, String dbname, String l, String p) throws ClassNotFoundException, SQLException {
|
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
|
||||||
url = "jdbc:mysql://"+host+":"+port+"/"+dbname;
|
|
||||||
login = l;
|
|
||||||
pass = p;
|
|
||||||
conn = DriverManager.getConnection(url, login, pass);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void reconnectIfNecessary() throws SQLException
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Statement stmt = conn.createStatement();
|
|
||||||
stmt.close();
|
|
||||||
}
|
|
||||||
catch(SQLException e)
|
|
||||||
{
|
|
||||||
close();
|
|
||||||
conn = DriverManager.getConnection(url, login, pass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection getConnection() throws SQLException
|
|
||||||
{
|
|
||||||
if (!conn.isValid(1))
|
|
||||||
reconnectIfNecessary();
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
try {
|
|
||||||
conn.close();
|
|
||||||
} catch (Exception e) { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -4,6 +4,8 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.DBConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <b>ORM = Object-Relational Mapping</b><br/>
|
* <b>ORM = Object-Relational Mapping</b><br/>
|
||||||
* Liste des tables avec leur classes :
|
* Liste des tables avec leur classes :
|
||||||
|
@ -8,6 +8,8 @@ import java.sql.Statement;
|
|||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.DBConnection;
|
||||||
|
|
||||||
public abstract class SQLElement {
|
public abstract class SQLElement {
|
||||||
|
|
||||||
DBConnection db = ORM.connection;
|
DBConnection db = ORM.connection;
|
||||||
@ -40,7 +42,7 @@ public abstract class SQLElement {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
conn = db.getConnection();
|
conn = db.getNativeConnection();
|
||||||
|
|
||||||
String[] fields = getFieldsName(), values = getValues();
|
String[] fields = getFieldsName(), values = getValues();
|
||||||
|
|
||||||
@ -118,7 +120,7 @@ public abstract class SQLElement {
|
|||||||
try {
|
try {
|
||||||
if (saved)
|
if (saved)
|
||||||
{ // supprimer la ligne de la base
|
{ // supprimer la ligne de la base
|
||||||
PreparedStatement st = db.getConnection().prepareStatement("DELETE FROM "+tableName+" WHERE id="+id);
|
PreparedStatement st = db.getNativeConnection().prepareStatement("DELETE FROM "+tableName+" WHERE id="+id);
|
||||||
try {
|
try {
|
||||||
st.executeUpdate();
|
st.executeUpdate();
|
||||||
saved = false;
|
saved = false;
|
||||||
|
@ -6,6 +6,8 @@ import java.sql.Statement;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.DBConnection;
|
||||||
|
|
||||||
public abstract class SQLTable<T extends SQLElement> {
|
public abstract class SQLTable<T extends SQLElement> {
|
||||||
|
|
||||||
DBConnection db = ORM.connection;
|
DBConnection db = ORM.connection;
|
||||||
@ -24,7 +26,7 @@ public abstract class SQLTable<T extends SQLElement> {
|
|||||||
|
|
||||||
|
|
||||||
private void createTable() throws SQLException {
|
private void createTable() throws SQLException {
|
||||||
Statement stmt = db.getConnection().createStatement();
|
Statement stmt = db.getNativeConnection().createStatement();
|
||||||
String sql = "CREATE TABLE IF NOT EXISTS "+tableName+" " +
|
String sql = "CREATE TABLE IF NOT EXISTS "+tableName+" " +
|
||||||
"("+createTableParameters()+")";
|
"("+createTableParameters()+")";
|
||||||
try {
|
try {
|
||||||
@ -39,7 +41,7 @@ public abstract class SQLTable<T extends SQLElement> {
|
|||||||
ResultSet set = null;
|
ResultSet set = null;
|
||||||
boolean exist = false;
|
boolean exist = false;
|
||||||
try {
|
try {
|
||||||
set = db.getConnection().getMetaData().getTables(null, null, tableName, null);
|
set = db.getNativeConnection().getMetaData().getTables(null, null, tableName, null);
|
||||||
exist = set.next();
|
exist = set.next();
|
||||||
} finally {
|
} finally {
|
||||||
if (set != null)
|
if (set != null)
|
||||||
@ -77,7 +79,7 @@ public abstract class SQLTable<T extends SQLElement> {
|
|||||||
|
|
||||||
public T get(int id) throws SQLException {
|
public T get(int id) throws SQLException {
|
||||||
T elementInstance = null;
|
T elementInstance = null;
|
||||||
Statement stmt = db.getConnection().createStatement();
|
Statement stmt = db.getNativeConnection().createStatement();
|
||||||
try {
|
try {
|
||||||
String sql = "SELECT * FROM "+tableName+" WHERE id = "+id+";";
|
String sql = "SELECT * FROM "+tableName+" WHERE id = "+id+";";
|
||||||
|
|
||||||
@ -109,7 +111,7 @@ public abstract class SQLTable<T extends SQLElement> {
|
|||||||
|
|
||||||
|
|
||||||
public List<T> getAll(String where, String orderBy, Integer limit, Integer offset) throws SQLException {
|
public List<T> getAll(String where, String orderBy, Integer limit, Integer offset) throws SQLException {
|
||||||
Statement stmt = db.getConnection().createStatement();
|
Statement stmt = db.getNativeConnection().createStatement();
|
||||||
String sql = "SELECT * FROM "+tableName;
|
String sql = "SELECT * FROM "+tableName;
|
||||||
|
|
||||||
if (where != null)
|
if (where != null)
|
||||||
|
2
src/fr/pandacube/java/util/db/package-info.java
Normal file
2
src/fr/pandacube/java/util/db/package-info.java
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
@java.lang.Deprecated
|
||||||
|
package fr.pandacube.java.util.db;
|
@ -4,6 +4,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
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.SQLField;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLFKField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
|
||||||
public class SQLContact extends SQLElement {
|
public class SQLContact extends SQLElement {
|
||||||
@ -18,13 +19,13 @@ public class SQLContact extends SQLElement {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final SQLField<Integer> time = new SQLField<>("time", SQLType.INT, false);
|
public static final SQLField<Integer> time = new SQLField<>( "time", SQLType.INT, false);
|
||||||
public static final SQLField<String> playerId = new SQLField<>("playerId", SQLType.CHAR(36), true);
|
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> 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> 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> titre = new SQLField<>( "titre", SQLType.VARCHAR(100), false);
|
||||||
public static final SQLField<String> texte = new SQLField<>("texte", SQLType.TEXT, 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 static final SQLField<Boolean> hidden = new SQLField<>( "hidden", SQLType.BOOLEAN, false, (Boolean)false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.pandacube.java.util.db2;
|
package fr.pandacube.java.util.db2;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
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.SQLField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ public class SQLForumForum extends SQLElement {
|
|||||||
protected String tableName() { return "pandacube_forum_forum"; }
|
protected String tableName() { return "pandacube_forum_forum"; }
|
||||||
|
|
||||||
|
|
||||||
public static final SQLField<Integer> catId = new SQLField<>("catId", SQLType.INT, false);
|
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> nom = new SQLField<>("nom", SQLType.VARCHAR(100), false);
|
||||||
public static final SQLField<String> description = new SQLField<>("description", SQLType.TEXT, 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> ordre = new SQLField<>("ordre", SQLType.INT, false);
|
||||||
|
@ -3,6 +3,7 @@ package fr.pandacube.java.util.db2;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
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.SQLField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ public class SQLForumPost extends SQLElement {
|
|||||||
public static final SQLField<String> createur = new SQLField<>("createur", SQLType.CHAR(36), false);
|
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<String> texte = new SQLField<>("texte", SQLType.TEXT, false);
|
||||||
public static final SQLField<Integer> time = new SQLField<>("time", SQLType.INT, false);
|
public static final SQLField<Integer> time = new SQLField<>("time", SQLType.INT, false);
|
||||||
public static final SQLField<Integer> threadId = new SQLField<>("threadId", 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 static final SQLField<Boolean> moderated = new SQLField<>("moderated", SQLType.BOOLEAN, false);
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package fr.pandacube.java.util.db2;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
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.SQLField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
|
||||||
@ -16,9 +17,9 @@ public class SQLForumThread extends SQLElement {
|
|||||||
protected String tableName() { return "pandacube_forum_thread"; }
|
protected String tableName() { return "pandacube_forum_thread"; }
|
||||||
|
|
||||||
|
|
||||||
public static final SQLField<Integer> forumId = new SQLField<>("forumId", SQLType.INT, false);
|
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 SQLField<String> titre = new SQLField<>("titre", SQLType.VARCHAR(60), false);
|
||||||
public static final SQLField<String> createur = new SQLField<>("createur", SQLType.CHAR(36), 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<Integer> vu = new SQLField<>("vu", SQLType.INT, false);
|
||||||
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, 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> anchored = new SQLField<>("anchored", SQLType.BOOLEAN, false);
|
||||||
|
@ -3,6 +3,7 @@ package fr.pandacube.java.util.db2;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
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.SQLField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ public class SQLLoginHistory extends SQLElement {
|
|||||||
|
|
||||||
|
|
||||||
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
|
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
|
||||||
public static final SQLField<String> playerId = new SQLField<>("playerId", SQLType.CHAR(36), 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<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<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<Integer> nbOnline = new SQLField<>("nbOnline", SQLType.INT, false);
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
package fr.pandacube.java.util.db2;
|
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.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.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.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 class SQLMPGroup extends SQLElement {
|
||||||
|
|
||||||
@ -16,4 +22,24 @@ public class SQLMPGroup extends SQLElement {
|
|||||||
|
|
||||||
public static final SQLField<String> groupName = new SQLField<>("groupName", SQLType.VARCHAR(16), false);
|
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,10 +1,16 @@
|
|||||||
package fr.pandacube.java.util.db2;
|
package fr.pandacube.java.util.db2;
|
||||||
|
|
||||||
|
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.db2.sql_tools.SQLElement;
|
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.SQLFKField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
|
|
||||||
public class SQLMPGroupUser extends SQLElement {
|
public class SQLMPGroupUser extends SQLElement {
|
||||||
|
|
||||||
@ -16,8 +22,8 @@ public class SQLMPGroupUser extends SQLElement {
|
|||||||
protected String tableName() { return "pandacube_mp_group_user"; }
|
protected String tableName() { return "pandacube_mp_group_user"; }
|
||||||
|
|
||||||
|
|
||||||
public static final SQLField<Integer> groupId = new SQLField<>("groupId", SQLType.INT, false);
|
public static final SQLFKField<Integer, SQLMPGroup> groupId = SQLFKField.idFK( "groupId", SQLType.INT, false, SQLMPGroup.class);
|
||||||
public static final SQLField<String> playerId = new SQLField<>("playerId", SQLType.CHAR(36), false);
|
public static final SQLFKField<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
|
// TODO ajouter un champ qui dit si le joueur est admin du groupe
|
||||||
|
|
||||||
@ -34,4 +40,27 @@ public class SQLMPGroupUser extends SQLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,22 @@ package fr.pandacube.java.util.db2;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import fr.pandacube.java.util.PlayerFinder;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.ORM;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.ORMException;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLElementList;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLFKField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLField;
|
import fr.pandacube.java.util.db2.sql_tools.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.SQLType;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereLike;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy.Direction;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereNull;
|
||||||
|
|
||||||
public class SQLMPMessage extends SQLElement {
|
public class SQLMPMessage extends SQLElement {
|
||||||
|
|
||||||
@ -18,13 +31,13 @@ public class SQLMPMessage extends SQLElement {
|
|||||||
|
|
||||||
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
|
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
|
||||||
public static final SQLField<Integer> securityKey = new SQLField<>("securityKey", SQLType.INT, false);
|
public static final SQLField<Integer> securityKey = new SQLField<>("securityKey", SQLType.INT, false);
|
||||||
public static final SQLField<String> viewerId = new SQLField<>("viewerId", SQLType.CHAR(36), false);
|
public static final SQLFKField<String, SQLPlayer> viewerId = new SQLFKField<>("viewerId", SQLType.CHAR(36), false, SQLPlayer.class, SQLPlayer.playerId);
|
||||||
public static final SQLField<String> sourceId = new SQLField<>("sourceId", SQLType.CHAR(36), true);
|
public static final SQLFKField<String, SQLPlayer> sourceId = new SQLFKField<>("sourceId", SQLType.CHAR(36), true, SQLPlayer.class, SQLPlayer.playerId);
|
||||||
public static final SQLField<String> destId = new SQLField<>("destId", SQLType.CHAR(36), true);
|
public static final SQLFKField<String, SQLPlayer> destId = new SQLFKField<>("destId", SQLType.CHAR(36), true, SQLPlayer.class, SQLPlayer.playerId);
|
||||||
public static final SQLField<Integer> destGroup = new SQLField<>("destGroup", SQLType.INT, true);
|
public static final SQLFKField<Integer, SQLMPGroup> destGroup = SQLFKField.idFK("destGroup", SQLType.INT, true, SQLMPGroup.class);
|
||||||
public static final SQLField<String> message = new SQLField<>("message", SQLType.VARCHAR(512), false);
|
public static final SQLField<String> message = new SQLField<>("message", SQLType.VARCHAR(512), false);
|
||||||
public static final SQLField<Boolean> wasRead = new SQLField<>("wasRead", SQLType.BOOLEAN, false);
|
public static final SQLField<Boolean> wasRead = new SQLField<>("wasRead", SQLType.BOOLEAN, false);
|
||||||
public static final SQLField<Boolean> deleted = new SQLField<>("deleted", SQLType.BOOLEAN, false);
|
public static final SQLField<Boolean> deleted = new SQLField<>("deleted", SQLType.BOOLEAN, false, (Boolean) false);
|
||||||
public static final SQLField<Boolean> serverSync = new SQLField<>("serverSync", SQLType.BOOLEAN, false);
|
public static final SQLField<Boolean> serverSync = new SQLField<>("serverSync", SQLType.BOOLEAN, false);
|
||||||
|
|
||||||
|
|
||||||
@ -53,4 +66,79 @@ public class SQLMPMessage extends SQLElement {
|
|||||||
public void setDestId(UUID id) {
|
public void setDestId(UUID id) {
|
||||||
set(destId, (id == null) ? null : id.toString());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package fr.pandacube.java.util.db2;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
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.SQLField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
|
||||||
@ -16,10 +17,10 @@ public class SQLModoHistory extends SQLElement {
|
|||||||
protected String tableName() { return "pandacube_modo_history"; }
|
protected String tableName() { return "pandacube_modo_history"; }
|
||||||
|
|
||||||
|
|
||||||
public static final SQLField<String> modoId = new SQLField<>("modoId", SQLType.CHAR(36), true);
|
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<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 SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
|
||||||
public static final SQLField<String> playerId = new SQLField<>("playerId", SQLType.CHAR(36), 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<Long> value = new SQLField<>("value", SQLType.BIGINT, true);
|
||||||
public static final SQLField<String> message = new SQLField<>("message", SQLType.VARCHAR(512), false);
|
public static final SQLField<String> message = new SQLField<>("message", SQLType.VARCHAR(512), false);
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package fr.pandacube.java.util.db2;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
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.SQLField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
|
||||||
@ -19,11 +20,11 @@ public class SQLOnlineshopHistory extends SQLElement {
|
|||||||
public static final SQLField<Long> time = new SQLField<>("time", SQLType.BIGINT, false);
|
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<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 SQLField<SourceType> sourceType = new SQLField<>("sourceType", SQLType.ENUM(SourceType.class), false);
|
||||||
public static final SQLField<String> sourcePlayerId = new SQLField<>("sourcePlayerId", SQLType.CHAR(36), true);
|
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<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<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 SQLField<DestType> destType = new SQLField<>("destType", SQLType.ENUM(DestType.class), false);
|
||||||
public static final SQLField<String> destPlayerId = new SQLField<>("destPlayerId", SQLType.CHAR(36), 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<Double> destQuantity = new SQLField<>("destQuantity", SQLType.DOUBLE, false);
|
||||||
public static final SQLField<String> destName = new SQLField<>("destName", SQLType.VARCHAR(64), false);
|
public static final SQLField<String> destName = new SQLField<>("destName", SQLType.VARCHAR(64), false);
|
||||||
|
|
||||||
|
@ -3,9 +3,12 @@ package fr.pandacube.java.util.db2;
|
|||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.ORM;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLField;
|
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.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 class SQLPlayer extends SQLElement {
|
||||||
@ -29,10 +32,10 @@ public class SQLPlayer extends SQLElement {
|
|||||||
public static final SQLField<String> password = new SQLField<>("password", 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> 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<String> playerDisplayName = new SQLField<>("playerDisplayName", SQLType.VARCHAR(255), false);
|
||||||
public static final SQLField<Long> firstTimeInGame = new SQLField<>("firstTimeInGame", SQLType.BIGINT, 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> timeWebRegister = new SQLField<>("timeWebRegister", SQLType.BIGINT, true);
|
||||||
public static final SQLField<Long> lastTimeInGame = new SQLField<>("lastTimeInGame", 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);
|
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> 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<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<Boolean> isVanish = new SQLField<>("isVanish", SQLType.BOOLEAN, false, (Boolean)false);
|
||||||
@ -78,4 +81,19 @@ public class SQLPlayer extends SQLElement {
|
|||||||
set(token, (t == null) ? (String)null : t.toString());
|
set(token, (t == null) ? (String)null : t.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static SQLPlayer getPlayerFromUUID(UUID playerId) throws Exception {
|
||||||
|
return ORM.getFirst(SQLPlayer.class,
|
||||||
|
new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, playerId.toString()),
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
package fr.pandacube.java.util.db2;
|
package fr.pandacube.java.util.db2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
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.db2.sql_tools.SQLElement;
|
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.SQLFKField;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLOrderBy;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
|
|
||||||
public class SQLPlayerIgnore extends SQLElement {
|
public class SQLPlayerIgnore extends SQLElement {
|
||||||
|
|
||||||
@ -16,8 +24,8 @@ public class SQLPlayerIgnore extends SQLElement {
|
|||||||
protected String tableName() { return "pandacube_player_ignore"; }
|
protected String tableName() { return "pandacube_player_ignore"; }
|
||||||
|
|
||||||
|
|
||||||
public static final SQLField<String> ignorer = new SQLField<>("ignorer", SQLType.CHAR(36), false);
|
public static final SQLFKField<String, SQLPlayer> ignorer = new SQLFKField<>("ignorer", SQLType.CHAR(36), false, SQLPlayer.class, SQLPlayer.playerId);
|
||||||
public static final SQLField<String> ignored = new SQLField<>("ignored", SQLType.CHAR(36), false);
|
public static final SQLFKField<String, SQLPlayer> ignored = new SQLFKField<>("ignored", SQLType.CHAR(36), false, SQLPlayer.class, SQLPlayer.playerId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -45,4 +53,46 @@ public class SQLPlayerIgnore extends SQLElement {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static SQLPlayerIgnore getPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws Exception {
|
||||||
|
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 Exception {
|
||||||
|
return getPlayerIgnoringPlayer(ignorer, ignored) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setPlayerIgnorePlayer(UUID ignorer, UUID ignored, boolean newIgnoreState) throws Exception {
|
||||||
|
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 List<UUID> getListIgnoredPlayer(UUID ignorer) throws Exception {
|
||||||
|
List<SQLPlayerIgnore> els = ORM.getAll(SQLPlayerIgnore.class,
|
||||||
|
new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString()),
|
||||||
|
new SQLOrderBy().addField(ORM.getSQLIdField(SQLPlayerIgnore.class)), null, null);
|
||||||
|
List<UUID> ret = new ArrayList<>(els.size());
|
||||||
|
for (SQLPlayerIgnore el : els) {
|
||||||
|
ret.add(el.getIgnoredId());
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package fr.pandacube.java.util.db2;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLElement;
|
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.SQLField;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
import fr.pandacube.java.util.db2.sql_tools.SQLType;
|
||||||
|
|
||||||
@ -16,11 +17,10 @@ public class SQLStaffTicket extends SQLElement {
|
|||||||
protected String tableName() { return "pandacube_staff_ticket"; }
|
protected String tableName() { return "pandacube_staff_ticket"; }
|
||||||
|
|
||||||
|
|
||||||
public static final SQLField<String> playerId = new SQLField<>("playerId", SQLType.CHAR(36), false);
|
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<String> message = new SQLField<>("message", SQLType.VARCHAR(1024), false);
|
||||||
public static final SQLField<Long> creationTime = new SQLField<>("creationTime", SQLType.BIGINT, false);
|
public static final SQLField<Long> creationTime = new SQLField<>("creationTime", SQLType.BIGINT, false);
|
||||||
public static final SQLField<String> staffPlayerId = new SQLField<>("staffPlayerId", SQLType.CHAR(36), true);
|
public static final SQLFKField<String, SQLPlayer> staffPlayerId = new SQLFKField<>("staffPlayerId", SQLType.CHAR(36), true, SQLPlayer.class, SQLPlayer.playerId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
36
src/fr/pandacube/java/util/db2/SQLUUIDPlayer.java
Normal file
36
src/fr/pandacube/java/util/db2/SQLUUIDPlayer.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,9 +16,7 @@ public class DBConnection {
|
|||||||
url = "jdbc:mysql://"+host+":"+port+"/"+dbname;
|
url = "jdbc:mysql://"+host+":"+port+"/"+dbname;
|
||||||
login = l;
|
login = l;
|
||||||
pass = p;
|
pass = p;
|
||||||
conn = DriverManager.getConnection(url, login, pass);
|
connect();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -31,8 +29,8 @@ public class DBConnection {
|
|||||||
}
|
}
|
||||||
catch(SQLException e)
|
catch(SQLException e)
|
||||||
{
|
{
|
||||||
close();
|
try { close(); } catch(Exception ex) { }
|
||||||
conn = DriverManager.getConnection(url, login, pass);
|
connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +42,11 @@ public class DBConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void connect() throws SQLException {
|
||||||
|
conn = DriverManager.getConnection(url, login, pass);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
conn.close();
|
conn.close();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package fr.pandacube.java.util.db2.sql_tools;
|
package fr.pandacube.java.util.db2.sql_tools;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -9,8 +8,24 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import fr.pandacube.java.PandacubeUtil;
|
import fr.pandacube.java.util.Log;
|
||||||
|
import fr.pandacube.java.util.db2.SQLContact;
|
||||||
|
import fr.pandacube.java.util.db2.SQLForumCategorie;
|
||||||
|
import fr.pandacube.java.util.db2.SQLForumForum;
|
||||||
|
import fr.pandacube.java.util.db2.SQLForumPost;
|
||||||
|
import fr.pandacube.java.util.db2.SQLForumThread;
|
||||||
|
import fr.pandacube.java.util.db2.SQLLoginHistory;
|
||||||
|
import fr.pandacube.java.util.db2.SQLMPGroup;
|
||||||
|
import fr.pandacube.java.util.db2.SQLMPGroupUser;
|
||||||
|
import fr.pandacube.java.util.db2.SQLMPMessage;
|
||||||
|
import fr.pandacube.java.util.db2.SQLModoHistory;
|
||||||
|
import fr.pandacube.java.util.db2.SQLOnlineshopHistory;
|
||||||
import fr.pandacube.java.util.db2.SQLPlayer;
|
import fr.pandacube.java.util.db2.SQLPlayer;
|
||||||
|
import fr.pandacube.java.util.db2.SQLPlayerIgnore;
|
||||||
|
import fr.pandacube.java.util.db2.SQLShopStock;
|
||||||
|
import fr.pandacube.java.util.db2.SQLStaffTicket;
|
||||||
|
import fr.pandacube.java.util.db2.SQLStaticPages;
|
||||||
|
import fr.pandacube.java.util.db2.SQLUUIDPlayer;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp;
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereChain.SQLBoolOp;
|
||||||
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
@ -41,14 +56,35 @@ public final class ORM {
|
|||||||
* utile des les initialiser ici, car on peut tout de suite déceler les bugs ou erreurs dans la déclaration des SQLFields
|
* 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(SQLModoHistory.class);
|
||||||
|
initTable(SQLMPGroup.class);
|
||||||
|
initTable(SQLMPGroupUser.class);
|
||||||
|
initTable(SQLMPMessage.class);
|
||||||
|
initTable(SQLOnlineshopHistory.class);
|
||||||
initTable(SQLPlayer.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 <T extends SQLElement> void initTable(Class<T> elemClass) {
|
/* package */ static <T extends SQLElement> void initTable(Class<T> elemClass) throws ORMInitTableException {
|
||||||
if (tables.contains(elemClass))
|
if (tables.contains(elemClass))
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
@ -58,7 +94,7 @@ public final class ORM {
|
|||||||
createTable(instance);
|
createTable(instance);
|
||||||
tables.add(elemClass);
|
tables.add(elemClass);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PandacubeUtil.getMasterLogger().log(Level.SEVERE, "Can't init table " + elemClass.getName(), e);
|
throw new ORMInitTableException(elemClass, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,16 +159,17 @@ public final class ORM {
|
|||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends SQLElement> SQLField<Integer> getSQLIdField(Class<T> elemClass) {
|
public static <T extends SQLElement> SQLField<Integer> getSQLIdField(Class<T> elemClass) throws ORMInitTableException {
|
||||||
|
initTable(elemClass);
|
||||||
return (SQLField<Integer>) SQLElement.fieldsCache.get(elemClass).get("id");
|
return (SQLField<Integer>) SQLElement.fieldsCache.get(elemClass).get("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static <T extends SQLElement> List<T> getByIds(Class<T> elemClass, Collection<Integer> ids) throws Exception {
|
public static <T extends SQLElement> List<T> getByIds(Class<T> elemClass, Collection<Integer> ids) 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 Exception {
|
public static <T extends SQLElement> List<T> getByIds(Class<T> elemClass, Integer... ids) throws ORMException {
|
||||||
SQLField<Integer> idField = getSQLIdField(elemClass);
|
SQLField<Integer> idField = getSQLIdField(elemClass);
|
||||||
SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR);
|
SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR);
|
||||||
for (Integer id : ids)
|
for (Integer id : ids)
|
||||||
@ -141,24 +178,27 @@ public final class ORM {
|
|||||||
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 Exception {
|
public static <T extends SQLElement> T getById(Class<T> 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) throws Exception {
|
public static <T extends SQLElement> T getFirst(Class<T> elemClass, SQLWhere where, SQLOrderBy orderBy) throws ORMException {
|
||||||
SQLElementList<T> elts = getAll(elemClass, where, orderBy, 1, null);
|
SQLElementList<T> 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 Exception {
|
public static <T extends SQLElement> SQLElementList<T> getAll(Class<T> 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, SQLOrderBy orderBy, Integer limit, Integer offset) throws Exception {
|
public static <T extends SQLElement> SQLElementList<T> getAll(Class<T> elemClass, SQLWhere where, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException {
|
||||||
initTable(elemClass);
|
initTable(elemClass);
|
||||||
|
|
||||||
|
try {
|
||||||
String sql = "SELECT * FROM "+elemClass.newInstance().tableName();
|
String sql = "SELECT * FROM "+elemClass.newInstance().tableName();
|
||||||
|
|
||||||
List<Object> params = new ArrayList<>();
|
List<Object> params = new ArrayList<>();
|
||||||
|
|
||||||
if (where != null) {
|
if (where != null) {
|
||||||
@ -200,6 +240,10 @@ public final class ORM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return elmts;
|
return elmts;
|
||||||
|
} catch (ReflectiveOperationException | SQLException e) {
|
||||||
|
throw new ORMException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -215,7 +259,7 @@ public final class ORM {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static <T extends SQLElement> T getElementInstance(ResultSet set, Class<T> elemClass) throws Exception {
|
private static <T extends SQLElement> T getElementInstance(ResultSet set, Class<T> elemClass) throws ReflectiveOperationException, SQLException {
|
||||||
try {
|
try {
|
||||||
T instance = elemClass.getConstructor(int.class).newInstance(set.getInt("id"));
|
T instance = elemClass.getConstructor(int.class).newInstance(set.getInt("id"));
|
||||||
|
|
||||||
@ -231,11 +275,8 @@ public final class ORM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
} catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) {
|
||||||
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
throw new ReflectiveOperationException("Can't instanciate " + elemClass.getName(), e);
|
||||||
throw new Exception("Can't instanciate " + elemClass.getName(), e);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new Exception("Error reading ResultSet for creating instance of " + elemClass.getName(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/fr/pandacube/java/util/db2/sql_tools/ORMException.java
Normal file
18
src/fr/pandacube/java/util/db2/sql_tools/ORMException.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package fr.pandacube.java.util.db2.sql_tools;
|
||||||
|
|
||||||
|
public class ORMException extends Exception {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public ORMException(Throwable initCause) {
|
||||||
|
super(initCause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ORMException(String message, Throwable initCause) {
|
||||||
|
super(message, initCause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ORMException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package fr.pandacube.java.util.db2.sql_tools;
|
||||||
|
|
||||||
|
public class ORMInitTableException extends ORMException {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* package */ <T extends SQLElement> ORMInitTableException(Class<T> tableElem) {
|
||||||
|
super("Error while initializing table "+tableElem.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* package */ <T extends SQLElement> ORMInitTableException(Class<T> tableElem, Throwable t) {
|
||||||
|
super("Error while initializing table "+tableElem.getName(), t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -16,7 +16,10 @@ import java.util.Objects;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import fr.pandacube.java.PandacubeUtil;
|
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||||
|
|
||||||
|
import fr.pandacube.java.util.Log;
|
||||||
|
import fr.pandacube.java.util.db2.sql_tools.SQLWhereComp.SQLComparator;
|
||||||
|
|
||||||
public abstract class SQLElement {
|
public abstract class SQLElement {
|
||||||
/** cache for fields for each subclass of SQLElement */
|
/** cache for fields for each subclass of SQLElement */
|
||||||
@ -109,7 +112,7 @@ public abstract class SQLElement {
|
|||||||
|
|
||||||
listToFill.addField((SQLField<?>)val);
|
listToFill.addField((SQLField<?>)val);
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
PandacubeUtil.getMasterLogger().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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +196,14 @@ public abstract class SQLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public <T, E extends SQLElement> E getForeign(SQLFKField<T, E> field) throws ORMException {
|
||||||
|
T fkValue = get(field);
|
||||||
|
if (fkValue == null) return null;
|
||||||
|
return ORM.getFirst(field.getForeignElementClass(),
|
||||||
|
new SQLWhereComp(field.getForeignField(), SQLComparator.EQ, fkValue), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean isValidForSave() {
|
public boolean isValidForSave() {
|
||||||
return values.keySet().containsAll(fields.keySet());
|
return values.keySet().containsAll(fields.keySet());
|
||||||
@ -217,12 +228,14 @@ public abstract class SQLElement {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void save() throws SQLException {
|
public void save() throws ORMException {
|
||||||
if (!isValidForSave())
|
if (!isValidForSave())
|
||||||
throw new IllegalStateException("this instance of " + getClass().getName() + " has at least one undefined value and can't be saved.");
|
throw new IllegalStateException("this instance of " + getClass().getName() + " has at least one undefined value and can't be saved.");
|
||||||
|
|
||||||
ORM.initTable(getClass());
|
ORM.initTable(getClass());
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
Connection conn = db.getNativeConnection();
|
Connection conn = db.getNativeConnection();
|
||||||
|
|
||||||
|
|
||||||
@ -315,7 +328,9 @@ public abstract class SQLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
modifiedSinceLastSave.clear();
|
modifiedSinceLastSave.clear();
|
||||||
|
} catch(SQLException e) {
|
||||||
|
throw new ORMException("Error while saving data in table "+tableName(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -334,7 +349,7 @@ public abstract class SQLElement {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void delete() {
|
public void delete() throws ORMException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (stored)
|
if (stored)
|
||||||
@ -348,7 +363,7 @@ public abstract class SQLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
throw new ORMException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -388,5 +403,24 @@ public abstract class SQLElement {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
ToStringBuilder b = new ToStringBuilder(this);
|
||||||
|
|
||||||
|
for (SQLField<?> f : fields.values()) {
|
||||||
|
try {
|
||||||
|
b.append(f.name, get(f));
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
b.append(f.name, "(Must be defined before saving)");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return b.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
63
src/fr/pandacube/java/util/db2/sql_tools/SQLFKField.java
Normal file
63
src/fr/pandacube/java/util/db2/sql_tools/SQLFKField.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package fr.pandacube.java.util.db2.sql_tools;
|
||||||
|
|
||||||
|
import fr.pandacube.java.util.Log;
|
||||||
|
|
||||||
|
public class SQLFKField<T, E extends SQLElement> extends SQLField<T> {
|
||||||
|
|
||||||
|
private SQLField<T> sqlForeignKeyField;
|
||||||
|
private Class<E> sqlForeignKeyElement;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public SQLFKField(String n, SQLType<T> t, boolean nul, Class<E> fkEl, SQLField<T> fkF) {
|
||||||
|
super(n, t, nul);
|
||||||
|
construct(fkEl, fkF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SQLFKField(String n, SQLType<T> t, boolean nul, T deflt, Class<E> fkEl, SQLField<T> fkF) {
|
||||||
|
super(n, t, nul, deflt);
|
||||||
|
construct(fkEl, fkF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <E extends SQLElement> SQLFKField<Integer, E> idFK(String n, SQLType<Integer> t, boolean nul, Class<E> fkEl) {
|
||||||
|
if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null");
|
||||||
|
try {
|
||||||
|
return new SQLFKField<>(n, t, nul, fkEl, ORM.getSQLIdField(fkEl));
|
||||||
|
} catch (ORMInitTableException e) {
|
||||||
|
Log.severe("Can't create Foreign key Field called '"+n+"'", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <E extends SQLElement> SQLFKField<Integer, E> idFKField(String n, SQLType<Integer> t, boolean nul, Integer deflt, Class<E> fkEl) {
|
||||||
|
if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null");
|
||||||
|
try {
|
||||||
|
return new SQLFKField<>(n, t, nul, deflt, fkEl, ORM.getSQLIdField(fkEl));
|
||||||
|
} catch (ORMInitTableException e) {
|
||||||
|
Log.severe("Can't create Foreign key Field called '"+n+"'", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void construct(Class<E> fkEl, SQLField<T> fkF) {
|
||||||
|
if (fkEl == null) throw new IllegalArgumentException("foreignKeyElement can't be null");
|
||||||
|
if (fkF == null) throw new IllegalArgumentException("foreignKeyField can't be null");
|
||||||
|
try {
|
||||||
|
ORM.initTable(fkEl);
|
||||||
|
} catch (ORMInitTableException e) {
|
||||||
|
Log.severe(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!fkEl.equals(fkF.getSQLElementType()))
|
||||||
|
throw new IllegalArgumentException("foreignKeyField must be from supplied foreignKeyElement");
|
||||||
|
if (!type.equals(fkF.type))
|
||||||
|
throw new IllegalArgumentException("foreignKeyField and current Field must have the same SQLType");
|
||||||
|
sqlForeignKeyField = fkF;
|
||||||
|
sqlForeignKeyElement = fkEl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SQLField<T> getForeignField() { return sqlForeignKeyField; }
|
||||||
|
public Class<E> getForeignElementClass() { return sqlForeignKeyElement; }
|
||||||
|
|
||||||
|
}
|
@ -7,13 +7,28 @@ public class SQLOrderBy {
|
|||||||
|
|
||||||
private List<OBField> orderByFields = new ArrayList<>();
|
private List<OBField> orderByFields = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construit une nouvelle clause ORDER BY
|
||||||
|
*/
|
||||||
public SQLOrderBy() {}
|
public SQLOrderBy() {}
|
||||||
|
|
||||||
public SQLOrderBy addField(SQLField<?> field,Direction d) {
|
/**
|
||||||
|
* Ajoute un champ dans la clause ORDER BY en construction
|
||||||
|
* @param field le champ SQL à ordonner
|
||||||
|
* @param d le sens de tri (croissant ASC ou décroissant DESC)
|
||||||
|
* @return l'objet courant (permet de chainer les ajouts de champs)
|
||||||
|
*/
|
||||||
|
public SQLOrderBy addField(SQLField<?> field, Direction d) {
|
||||||
orderByFields.add(new OBField(field, d));
|
orderByFields.add(new OBField(field, d));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un champ dans la clause ORDER BY en construction,
|
||||||
|
* avec comme ordre de tri croissant ASC par défaut
|
||||||
|
* @param field le champ SQL à ordonner dans l'ordre croissant ASC
|
||||||
|
* @return l'objet courant (permet de chainer les ajouts de champs)
|
||||||
|
*/
|
||||||
public SQLOrderBy addField(SQLField<?> field) {
|
public SQLOrderBy addField(SQLField<?> field) {
|
||||||
return addField(field, Direction.ASC);
|
return addField(field, Direction.ASC);
|
||||||
}
|
}
|
||||||
@ -48,7 +63,7 @@ public class SQLOrderBy {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum Direction {
|
public enum Direction {
|
||||||
ASC, DESC;
|
ASC, DESC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,18 @@ public class SQLType<T> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return toString().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == null || !(obj instanceof SQLType))
|
||||||
|
return false;
|
||||||
|
return toString().equals(((SQLType<?>)obj).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public class SQLWhereChain extends SQLWhere {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum SQLBoolOp {
|
public enum SQLBoolOp {
|
||||||
/** Equivalent to SQL "<code>AND</code>" */
|
/** Equivalent to SQL "<code>AND</code>" */
|
||||||
AND("AND"),
|
AND("AND"),
|
||||||
/** Equivalent to SQL "<code>OR</code>" */
|
/** Equivalent to SQL "<code>OR</code>" */
|
||||||
|
@ -36,7 +36,7 @@ public class SQLWhereComp extends SQLWhere {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum SQLComparator {
|
public enum SQLComparator {
|
||||||
/** Equivalent to SQL "<code>=</code>" */
|
/** Equivalent to SQL "<code>=</code>" */
|
||||||
EQ("="),
|
EQ("="),
|
||||||
/** Equivalent to SQL "<code>></code>" */
|
/** Equivalent to SQL "<code>></code>" */
|
||||||
|
@ -13,9 +13,8 @@ public class SQLWhereLike extends SQLWhere {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare a field with a value
|
* Compare a field with a value
|
||||||
* @param l the field at left of the comparison operator. Can't be null
|
* @param f the field at left of the LIKE keyword. Can't be null
|
||||||
* @param c the comparison operator, can't be null
|
* @param like the like expression.
|
||||||
* @param r the value at right of the comparison operator. Can't be null
|
|
||||||
*/
|
*/
|
||||||
public SQLWhereLike(SQLField<String> f, String like) {
|
public SQLWhereLike(SQLField<String> f, String like) {
|
||||||
if (f == null || like == null)
|
if (f == null || like == null)
|
||||||
|
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import fr.pandacube.java.PandacubeUtil;
|
import fr.pandacube.java.util.Log;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
|
|
||||||
public class SQLWhereNull extends SQLWhere {
|
public class SQLWhereNull extends SQLWhere {
|
||||||
@ -21,7 +21,7 @@ public class SQLWhereNull extends SQLWhere {
|
|||||||
if (field == null)
|
if (field == null)
|
||||||
throw new IllegalArgumentException("field can't be null");
|
throw new IllegalArgumentException("field can't be null");
|
||||||
if (!field.canBeNull)
|
if (!field.canBeNull)
|
||||||
PandacubeUtil.getMasterLogger().log(Level.WARNING, "Useless : Trying to check IS [NOT] NULL on the field "+field.getSQLElementType().getName()+"#"+field.name+" which is declared in the ORM as 'can't be null'");
|
Log.getLogger().log(Level.WARNING, "Useless : Trying to check IS [NOT] NULL on the field "+field.getSQLElementType().getName()+"#"+field.name+" which is declared in the ORM as 'can't be null'");
|
||||||
fild = field;
|
fild = field;
|
||||||
nulll = isNull;
|
nulll = isNull;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,8 @@ import java.nio.ByteBuffer;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import fr.pandacube.java.PandacubeUtil;
|
import fr.pandacube.java.Pandacube;
|
||||||
|
import fr.pandacube.java.util.Log;
|
||||||
import fr.pandacube.java.util.network.packet.Packet;
|
import fr.pandacube.java.util.network.packet.Packet;
|
||||||
import fr.pandacube.java.util.network.packet.PacketClient;
|
import fr.pandacube.java.util.network.packet.PacketClient;
|
||||||
import fr.pandacube.java.util.network.packet.PacketException;
|
import fr.pandacube.java.util.network.packet.PacketException;
|
||||||
@ -37,9 +38,9 @@ public class TCPClient extends Thread implements Closeable {
|
|||||||
if (a == null || l == null)
|
if (a == null || l == null)
|
||||||
throw new IllegalArgumentException("les arguments ne peuvent pas être null");
|
throw new IllegalArgumentException("les arguments ne peuvent pas être null");
|
||||||
socket = new Socket();
|
socket = new Socket();
|
||||||
socket.setReceiveBufferSize(PandacubeUtil.NETWORK_TCP_BUFFER_SIZE);
|
socket.setReceiveBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE);
|
||||||
socket.setSendBufferSize(PandacubeUtil.NETWORK_TCP_BUFFER_SIZE);
|
socket.setSendBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE);
|
||||||
socket.setSoTimeout(PandacubeUtil.NETWORK_TIMEOUT);
|
socket.setSoTimeout(Pandacube.NETWORK_TIMEOUT);
|
||||||
socket.connect(a);
|
socket.connect(a);
|
||||||
addr = a;
|
addr = a;
|
||||||
listener = l;
|
listener = l;
|
||||||
@ -79,9 +80,9 @@ public class TCPClient extends Thread implements Closeable {
|
|||||||
|
|
||||||
listener.onPacketReceive(this, ps);
|
listener.onPacketReceive(this, ps);
|
||||||
} catch (PacketException|InvalidServerMessage e) {
|
} catch (PacketException|InvalidServerMessage e) {
|
||||||
PandacubeUtil.getMasterLogger().log(Level.SEVERE, "Message du serveur mal formé", e);
|
Log.getLogger().log(Level.SEVERE, "Message du serveur mal formé", e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PandacubeUtil.getMasterLogger().log(Level.SEVERE, "Erreur lors de la prise en charge du message par le serveur", e);
|
Log.getLogger().log(Level.SEVERE, "Erreur lors de la prise en charge du message par le serveur", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import fr.pandacube.java.PandacubeUtil;
|
import fr.pandacube.java.Pandacube;
|
||||||
import fr.pandacube.java.util.network.packet.bytebuffer.ByteBuffer;
|
import fr.pandacube.java.util.network.packet.bytebuffer.ByteBuffer;
|
||||||
import fr.pandacube.java.util.network.packet.bytebuffer.ByteSerializable;
|
import fr.pandacube.java.util.network.packet.bytebuffer.ByteSerializable;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public abstract class Packet implements ByteSerializable {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final Charset CHARSET = PandacubeUtil.NETWORK_CHARSET;
|
public static final Charset CHARSET = Pandacube.NETWORK_CHARSET;
|
||||||
|
|
||||||
private static Map<Byte, Class<? extends Packet>> packetTypes = new HashMap<Byte, Class<? extends Packet>>();
|
private static Map<Byte, Class<? extends Packet>> packetTypes = new HashMap<Byte, Class<? extends Packet>>();
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import fr.pandacube.java.PandacubeUtil;
|
import fr.pandacube.java.Pandacube;
|
||||||
|
import fr.pandacube.java.util.Log;
|
||||||
import fr.pandacube.java.util.network.packet.Packet;
|
import fr.pandacube.java.util.network.packet.Packet;
|
||||||
import fr.pandacube.java.util.network.packet.PacketClient;
|
import fr.pandacube.java.util.network.packet.PacketClient;
|
||||||
import fr.pandacube.java.util.network.packet.PacketServer;
|
import fr.pandacube.java.util.network.packet.PacketServer;
|
||||||
@ -52,7 +53,7 @@ public class TCPServer extends Thread implements Closeable {
|
|||||||
if (port <= 0 || port > 65535)
|
if (port <= 0 || port > 65535)
|
||||||
throw new IllegalArgumentException("le numéro de port est invalide");
|
throw new IllegalArgumentException("le numéro de port est invalide");
|
||||||
socket = new ServerSocket();
|
socket = new ServerSocket();
|
||||||
socket.setReceiveBufferSize(PandacubeUtil.NETWORK_TCP_BUFFER_SIZE);
|
socket.setReceiveBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE);
|
||||||
socket.setPerformancePreferences(0, 2, 1);
|
socket.setPerformancePreferences(0, 2, 1);
|
||||||
socket.bind(new InetSocketAddress(port));
|
socket.bind(new InetSocketAddress(port));
|
||||||
listener = l;
|
listener = l;
|
||||||
@ -67,8 +68,8 @@ public class TCPServer extends Thread implements Closeable {
|
|||||||
try {
|
try {
|
||||||
while(true) {
|
while(true) {
|
||||||
Socket socketClient = socket.accept();
|
Socket socketClient = socket.accept();
|
||||||
socketClient.setSendBufferSize(PandacubeUtil.NETWORK_TCP_BUFFER_SIZE);
|
socketClient.setSendBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE);
|
||||||
socketClient.setSoTimeout(PandacubeUtil.NETWORK_TIMEOUT);
|
socketClient.setSoTimeout(Pandacube.NETWORK_TIMEOUT);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TCPServerClientConnection co = new TCPServerClientConnection(socketClient, connectionCounterId.getAndIncrement());
|
TCPServerClientConnection co = new TCPServerClientConnection(socketClient, connectionCounterId.getAndIncrement());
|
||||||
@ -76,11 +77,11 @@ public class TCPServer extends Thread implements Closeable {
|
|||||||
listener.onClientConnect(this, co);
|
listener.onClientConnect(this, co);
|
||||||
co.start();
|
co.start();
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
PandacubeUtil.getMasterLogger().log(Level.SEVERE, "Connexion impossible avec "+socketClient.getInetAddress());
|
Log.getLogger().log(Level.SEVERE, "Connexion impossible avec "+socketClient.getInetAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PandacubeUtil.getMasterLogger().log(Level.WARNING, "Plus aucune connexion ne peux être acceptée", e);
|
Log.getLogger().log(Level.WARNING, "Plus aucune connexion ne peux être acceptée", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,9 +136,9 @@ public class TCPServer extends Thread implements Closeable {
|
|||||||
try {
|
try {
|
||||||
interpreteReceivedMessage(this, packetData);
|
interpreteReceivedMessage(this, packetData);
|
||||||
} catch (InvalidClientMessage e) {
|
} catch (InvalidClientMessage e) {
|
||||||
PandacubeUtil.getMasterLogger().log(Level.SEVERE, "Erreur protocole de : ", e);
|
Log.getLogger().log(Level.SEVERE, "Erreur protocole de : ", e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PandacubeUtil.getMasterLogger().log(Level.SEVERE, "Erreur lors de la prise en charge du message par le serveur", e);
|
Log.getLogger().log(Level.SEVERE, "Erreur lors de la prise en charge du message par le serveur", e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +147,7 @@ public class TCPServer extends Thread implements Closeable {
|
|||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PandacubeUtil.getMasterLogger().log(Level.SEVERE, "Fermeture de la connexion de "+address, e);
|
Log.getLogger().log(Level.SEVERE, "Fermeture de la connexion de "+address, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import java.io.IOException;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
import fr.pandacube.java.PandacubeUtil;
|
import fr.pandacube.java.util.Log;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,7 +44,7 @@ public class PacketExecutor implements Runnable {
|
|||||||
rep.sendPacket(new PrintStream(socket.getOutputStream()));
|
rep.sendPacket(new PrintStream(socket.getOutputStream()));
|
||||||
} catch (IOException e1) { }
|
} catch (IOException e1) { }
|
||||||
if (e instanceof IOException)
|
if (e instanceof IOException)
|
||||||
PandacubeUtil.getPluginLogger().warning("Impossible de lire le packet reçu sur le socket "+socket+" : "+e.toString());
|
Log.getLogger().warning("Impossible de lire le packet reçu sur le socket "+socket+" : "+e.toString());
|
||||||
else
|
else
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user