Cleanup/format code + suppression ancien ORM
This commit is contained in:
@@ -1,145 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LoginHistoryElement extends SQLElement {
|
||||
|
||||
|
||||
private long time;
|
||||
private String playerId;
|
||||
private String ip = null;
|
||||
private ActionType actionType;
|
||||
private int nbOnline;
|
||||
private String playerName;
|
||||
private int minecraftVersion = 0;
|
||||
|
||||
|
||||
public LoginHistoryElement(long t, UUID pId, ActionType action, int nbO) {
|
||||
super("pandacube_login_history");
|
||||
setTime(t);
|
||||
setPlayerId(pId);
|
||||
setActionType(action);
|
||||
setNbOnline(nbO);
|
||||
}
|
||||
|
||||
LoginHistoryElement(int id, long t, String pId, String ip, ActionType action, int nbO) {
|
||||
super("pandacube_login_history", id);
|
||||
if (pId == null)
|
||||
throw new IllegalArgumentException("pId ne peuvent être null");
|
||||
setTime(t);
|
||||
playerId = pId;
|
||||
this.ip = ip;
|
||||
setActionType(action);
|
||||
setNbOnline(nbO);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
Long.toString(time),
|
||||
playerId,
|
||||
ip,
|
||||
actionType.toString(),
|
||||
Integer.toString(nbOnline),
|
||||
playerName,
|
||||
Integer.toString(minecraftVersion)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"time",
|
||||
"playerId",
|
||||
"ip",
|
||||
"actionType",
|
||||
"nbOnline",
|
||||
"playerName",
|
||||
"minecraftVersion"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return UUID.fromString(playerId);
|
||||
}
|
||||
|
||||
public void setPlayerId(UUID pId) {
|
||||
if (pId == null)
|
||||
throw new IllegalArgumentException("pId ne peut être null");
|
||||
playerId = pId.toString();
|
||||
}
|
||||
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(InetAddress addr) {
|
||||
if (addr == null)
|
||||
ip = null;
|
||||
else
|
||||
ip = addr.getHostAddress();
|
||||
}
|
||||
|
||||
|
||||
public ActionType getActionType() {
|
||||
return actionType;
|
||||
}
|
||||
|
||||
public void setActionType(ActionType actionT) {
|
||||
if (actionT == null)
|
||||
throw new IllegalArgumentException("actionT ne peut être null");
|
||||
actionType = actionT;
|
||||
}
|
||||
|
||||
|
||||
public int getNbOnline() {
|
||||
return nbOnline;
|
||||
}
|
||||
|
||||
public void setNbOnline(int nbOnline) {
|
||||
this.nbOnline = nbOnline;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setPlayerName(String pn) {
|
||||
playerName = pn;
|
||||
}
|
||||
|
||||
public int getMinecraftVersion() {
|
||||
return minecraftVersion;
|
||||
}
|
||||
|
||||
public void setMinecraftVersion(int m) {
|
||||
minecraftVersion = m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public enum ActionType {
|
||||
LOGIN, LOGOUT
|
||||
}
|
||||
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import fr.pandacube.java.util.db.LoginHistoryElement.ActionType;
|
||||
|
||||
public class LoginHistoryTable extends SQLTable<LoginHistoryElement> {
|
||||
|
||||
public LoginHistoryTable() throws SQLException {
|
||||
super("pandacube_login_history");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "time BIGINT NOT NULL,"
|
||||
+ "playerId CHAR(36) NOT NULL,"
|
||||
+ "ip VARCHAR(128) NULL,"
|
||||
+ "actionType ENUM('LOGIN', 'LOGOUT') NOT NULL,"
|
||||
+ "nbOnline INT NOT NULL,"
|
||||
+ "playerName VARCHAR(16) NULL,"
|
||||
+ "minecraftVersion INT NOT NULL DEFAULT 0";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LoginHistoryElement getElementInstance(ResultSet sqlResult) throws SQLException {
|
||||
LoginHistoryElement el = new LoginHistoryElement(
|
||||
sqlResult.getInt("id"),
|
||||
sqlResult.getLong("time"),
|
||||
sqlResult.getString("playerId"),
|
||||
sqlResult.getString("ip"),
|
||||
ActionType.valueOf(sqlResult.getString("actionType")),
|
||||
sqlResult.getInt("nbOnline"));
|
||||
el.setPlayerName(sqlResult.getString("playerName"));
|
||||
el.setMinecraftVersion(sqlResult.getInt("minecraftVersion"));
|
||||
return el;
|
||||
}
|
||||
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import fr.pandacube.java.util.PlayerFinder;
|
||||
|
||||
public class MPGroupElement extends SQLElement {
|
||||
|
||||
private String groupName;
|
||||
|
||||
|
||||
|
||||
public MPGroupElement(String name) {
|
||||
super("pandacube_mp_group");
|
||||
setGroupName(name);
|
||||
}
|
||||
|
||||
protected MPGroupElement(int id, String name) {
|
||||
super("pandacube_mp_group", id);
|
||||
setGroupName(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
groupName
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"groupName"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getGroupName() { return groupName; }
|
||||
|
||||
public void setGroupName(String name) {
|
||||
if (name == null)
|
||||
throw new NullPointerException();
|
||||
if (!PlayerFinder.isValidPlayerName(name))
|
||||
throw new IllegalArgumentException("Le nom d'un groupe doit respecter le pattern d'un pseudo valide");
|
||||
groupName = name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<MPGroupUserElement> getUsers() throws SQLException {
|
||||
return ORM.getTable(MPGroupUserTable.class)
|
||||
.getAll("groupId = "+getId(), "id ASC", null, null);
|
||||
}
|
||||
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MPGroupTable extends SQLTable<MPGroupElement> {
|
||||
|
||||
public MPGroupTable() throws SQLException {
|
||||
super("pandacube_mp_group");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "groupName VARCHAR(16) NOT NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MPGroupElement getElementInstance(ResultSet sqlResult)
|
||||
throws SQLException {
|
||||
return new MPGroupElement(
|
||||
sqlResult.getInt("id"),
|
||||
sqlResult.getString("groupName"));
|
||||
}
|
||||
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MPGroupUserElement extends SQLElement {
|
||||
|
||||
private int groupId;
|
||||
private String playerId;
|
||||
|
||||
|
||||
public MPGroupUserElement(int gId, UUID pId) {
|
||||
super("pandacube_mp_group_user");
|
||||
setGroupId(gId);
|
||||
setPlayerId(pId);
|
||||
}
|
||||
|
||||
protected MPGroupUserElement(int id, int gId, String pId) {
|
||||
super("pandacube_mp_group_user", id);
|
||||
setGroupId(gId);
|
||||
setPlayerId(UUID.fromString(pId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
Integer.toString(groupId),
|
||||
playerId
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"groupId",
|
||||
"playerId"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int getGroupId() { return groupId; }
|
||||
public UUID getPlayerId() { return UUID.fromString(playerId); }
|
||||
|
||||
public void setGroupId(int gId) { groupId = gId; }
|
||||
public void setPlayerId(UUID pId) {
|
||||
if (pId == null)
|
||||
throw new NullPointerException();
|
||||
this.playerId = pId.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public PlayerElement getPlayerElement() throws SQLException {
|
||||
return ORM.getTable(PlayerTable.class)
|
||||
.getFirst("playerId LIKE '"+getPlayerId()+"'", "id ASC");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MPGroupUserTable extends SQLTable<MPGroupUserElement> {
|
||||
|
||||
public MPGroupUserTable() throws SQLException {
|
||||
super("pandacube_mp_group_user");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "groupId INT NOT NULL,"
|
||||
+ "playerId VARCHAR(36) NOT NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MPGroupUserElement getElementInstance(ResultSet sqlResult)
|
||||
throws SQLException {
|
||||
return new MPGroupUserElement(
|
||||
sqlResult.getInt("id"),
|
||||
sqlResult.getInt("groupId"),
|
||||
sqlResult.getString("playerId"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne l'instance de MPGroupUserElement correcpondant à la présence d'un joueur dans un groupe
|
||||
* @param group le groupe concerné, sous forme d'instance de MPGroupElement
|
||||
* @param player l'identifiant du joueur
|
||||
* @return null si la correspondance n'a pas été trouvée
|
||||
* @throws SQLException
|
||||
*/
|
||||
public MPGroupUserElement getPlayerInGroup(MPGroupElement group, UUID player) throws SQLException {
|
||||
if (player == null || group == null) return null;
|
||||
return getFirst("groupId = "+group.getId()+" AND playerId = '"+player+"'", "id");
|
||||
}
|
||||
|
||||
}
|
@@ -1,177 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Représente un message dans la base de donnée<br/>
|
||||
* <br/>
|
||||
* Les propriétés suivantes doivent être complétés hors constructeur (par défaut <code>null</code>) :
|
||||
* <ul>
|
||||
* <li><code>destNick</code></li>
|
||||
* <li>ou <code>destGroup</code></li>
|
||||
* </ul>
|
||||
* La propriété <code>deleted</code> est défini par défaut à Faux.
|
||||
* @author Marc Baloup
|
||||
*
|
||||
*/
|
||||
public class MPMessageElement extends SQLElement {
|
||||
|
||||
private long time;
|
||||
private int securityKey; // permet de différencier deux message, dans le cas où 2 messages ont exactement la même valeur time
|
||||
private String viewerId;
|
||||
private String sourceId;
|
||||
private String destId = null;
|
||||
private Integer destGroup = null;
|
||||
private String message;
|
||||
private boolean wasRead;
|
||||
private boolean deleted = false;
|
||||
private boolean serverSync;
|
||||
|
||||
|
||||
|
||||
public MPMessageElement(long t, int secKey, UUID viewId, UUID srcId, String msg, boolean r, boolean sync) {
|
||||
super("pandacube_mp_message");
|
||||
setTime(t);
|
||||
setSecurityKey(secKey);
|
||||
setViewerId(viewId);
|
||||
setSourceId(srcId);
|
||||
setMessage(msg);
|
||||
setRead(r);
|
||||
setServerSync(sync);
|
||||
}
|
||||
|
||||
|
||||
protected MPMessageElement(int id, long t, int secKey, String viewNick, String srcNick, String msg, boolean r, boolean sync) {
|
||||
super("pandacube_mp_message", id);
|
||||
setTime(t);
|
||||
setSecurityKey(secKey);
|
||||
setViewerId(UUID.fromString(viewNick));
|
||||
setSourceId((srcNick == null) ? null : UUID.fromString(srcNick));
|
||||
setMessage(msg);
|
||||
setRead(r);
|
||||
setServerSync(sync);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
Long.toString(time),
|
||||
Integer.toString(securityKey),
|
||||
viewerId,
|
||||
sourceId,
|
||||
destId,
|
||||
(destGroup==null)?null:destGroup.toString(),
|
||||
message,
|
||||
(wasRead)?"1":"0",
|
||||
(deleted)?"1":"0",
|
||||
(serverSync)?"1":"0"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"time",
|
||||
"securityKey",
|
||||
"viewerId",
|
||||
"sourceId",
|
||||
"destId",
|
||||
"destGroup",
|
||||
"message",
|
||||
"wasRead",
|
||||
"deleted",
|
||||
"serverSync"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public long getTime() { return time; }
|
||||
public int getSecurityKey() { return securityKey; }
|
||||
public UUID getViewerId() { return UUID.fromString(viewerId); }
|
||||
public UUID getSourceId() {
|
||||
if (sourceId == null) return null;
|
||||
return UUID.fromString(sourceId);
|
||||
}
|
||||
public UUID getDestId() {
|
||||
if (destId == null) return null;
|
||||
return UUID.fromString(destId);
|
||||
}
|
||||
public Integer getDestGroup() { return destGroup; }
|
||||
public String getMessage() { return message; }
|
||||
public boolean isRead() { return wasRead; }
|
||||
public boolean isDeleted() { return deleted; }
|
||||
public boolean isServerSync() { return serverSync; }
|
||||
|
||||
|
||||
|
||||
|
||||
public void setTime(long t) { time = t; }
|
||||
public void setSecurityKey(int secKey) { securityKey = secKey; }
|
||||
|
||||
public void setViewerId(UUID viewId) {
|
||||
if (viewId == null)
|
||||
throw new NullPointerException();
|
||||
viewerId = viewId.toString();
|
||||
}
|
||||
|
||||
public void setSourceId(UUID srcId) {
|
||||
if (srcId == null) sourceId = null;
|
||||
else sourceId = srcId.toString();
|
||||
}
|
||||
|
||||
public void setDestId(UUID destId) {
|
||||
if (destId == null) this.destId = null;
|
||||
else {
|
||||
this.destId = destId.toString();
|
||||
destGroup = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDestGroup(Integer destGroup) {
|
||||
this.destGroup = destGroup;
|
||||
if (destGroup != null)
|
||||
destId = null;
|
||||
}
|
||||
|
||||
public void setMessage(String msg) {
|
||||
if (msg == null)
|
||||
throw new NullPointerException();
|
||||
message = msg;
|
||||
}
|
||||
|
||||
public void setRead(boolean r) { wasRead = r; }
|
||||
public void setDeleted(boolean del) { deleted = del; }
|
||||
public void setServerSync(boolean sync) { serverSync = sync; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public MPGroupElement getDestGroupElement() throws SQLException {
|
||||
if (getDestGroup() == null) return null;
|
||||
|
||||
return ORM.getTable(MPGroupTable.class).get(getDestGroup());
|
||||
}
|
||||
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import fr.pandacube.java.util.PlayerFinder;
|
||||
|
||||
public class MPMessageTable extends SQLTable<MPMessageElement> {
|
||||
|
||||
public MPMessageTable() throws SQLException {
|
||||
super("pandacube_mp_message");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "time BIGINT NOT NULL,"
|
||||
+ "securityKey INT NOT NULL,"
|
||||
+ "viewerId VARCHAR(36) NOT NULL,"
|
||||
+ "sourceId VARCHAR(36) NULL," // Null si la source est la console ou une autre entité qu'un joueur
|
||||
+ "destId VARCHAR(36) NULL,"
|
||||
+ "destGroup INT NULL,"
|
||||
+ "message VARCHAR(512) NOT NULL,"
|
||||
+ "wasRead TINYINT NOT NULL,"
|
||||
+ "deleted TINYINT NOT NULL,"
|
||||
+ "serverSync TINYINT NOT NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MPMessageElement getElementInstance(ResultSet sqlResult)
|
||||
throws SQLException {
|
||||
MPMessageElement el = new MPMessageElement(
|
||||
sqlResult.getInt("id"),
|
||||
sqlResult.getLong("time"),
|
||||
sqlResult.getInt("securityKey"),
|
||||
sqlResult.getString("viewerId"),
|
||||
sqlResult.getString("sourceId"),
|
||||
sqlResult.getString("message"),
|
||||
sqlResult.getBoolean("wasRead"),
|
||||
sqlResult.getBoolean("serverSync"));
|
||||
String destId = sqlResult.getString("destId");
|
||||
el.setDestId(destId==null ? null : UUID.fromString(destId));
|
||||
|
||||
int group = sqlResult.getInt("destGroup");
|
||||
el.setDestGroup(sqlResult.wasNull()?null:group);
|
||||
|
||||
el.setDeleted(sqlResult.getBoolean("deleted"));
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public List<MPMessageElement> getAllUnsyncMessage() throws SQLException {
|
||||
return getAll("serverSync = 0", "time ASC", null, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<MPMessageElement> getAllUnreadForPlayer(UUID player) throws SQLException {
|
||||
return getForPlayer(player, true, null, false);
|
||||
}
|
||||
|
||||
|
||||
public List<MPMessageElement> getOneDiscussionForPlayer(UUID player, Object discussion, Integer numberLast, boolean revert) throws SQLException {
|
||||
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;
|
||||
|
||||
String where = "viewerId = '"+player+"'";
|
||||
if (discussion == null)
|
||||
where += " AND sourceId IS NULL AND destGroup IS NULL";
|
||||
else if (discussion instanceof String)
|
||||
where += " AND destGroup IN (SELECT id FROM "+ORM.getTable(MPGroupTable.class).getTableName()+" WHERE groupName LIKE '"+discussion+"')";
|
||||
else if (discussion instanceof UUID && discussion.equals(player))
|
||||
where += " AND destId LIKE '"+discussion+"' AND sourceId LIKE '"+discussion+"' AND destGroup IS NULL";
|
||||
else // discussion instanceof UUID
|
||||
where += " AND (destId LIKE '"+discussion+"' OR sourceId LIKE '"+discussion+"') AND destGroup IS NULL";
|
||||
|
||||
return getAll(where, (revert)?"time DESC":"time ASC", numberLast, null);
|
||||
}
|
||||
|
||||
|
||||
public List<MPMessageElement> getForPlayer(UUID player, boolean onlyUnread, Integer numberLast, boolean revert) throws SQLException {
|
||||
if (player == null) return null;
|
||||
|
||||
String where = "viewerId = '"+player+"'";
|
||||
if (onlyUnread)
|
||||
where += " AND wasRead = 0";
|
||||
|
||||
return getAll(where, (revert)?"time DESC":"time ASC", numberLast, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,141 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ModoHistoryElement extends SQLElement {
|
||||
|
||||
private String modoId = null;
|
||||
private ActionType actionType;
|
||||
private long time;
|
||||
private String playerId;
|
||||
private Long value = null;
|
||||
private String message;
|
||||
|
||||
|
||||
public ModoHistoryElement(UUID modo, ActionType type, UUID player, String message) {
|
||||
super("pandacube_modo_history");
|
||||
setModoId(modo);
|
||||
setActionType(type);
|
||||
setPlayerId(player);
|
||||
setMessage(message);
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
ModoHistoryElement(int id, String modo, ActionType type, String player, String message) {
|
||||
super("pandacube_modo_history", id);
|
||||
setModoId((modo == null)?null:UUID.fromString(modo));
|
||||
setActionType(type);
|
||||
setPlayerId(UUID.fromString(player));
|
||||
setMessage(message);
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
modoId,
|
||||
actionType.name(),
|
||||
String.valueOf(time),
|
||||
playerId,
|
||||
(value == null)?null:value.toString(),
|
||||
message
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"modoId",
|
||||
"actionType",
|
||||
"time",
|
||||
"playerId",
|
||||
"value",
|
||||
"message"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
public UUID getModoId() {
|
||||
return modoId == null ? null : UUID.fromString(modoId);
|
||||
}
|
||||
|
||||
public void setModoId(UUID modo) {
|
||||
this.modoId = modo == null ? null : modo.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ActionType getActionType() {
|
||||
return actionType;
|
||||
}
|
||||
|
||||
public void setActionType(ActionType actionType) {
|
||||
if (actionType == null) throw new IllegalArgumentException("le paramètre ne peut être null");
|
||||
this.actionType = actionType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne la durée de la sanction appliquée (en secondes), ou la somme d'argent retirée du compte
|
||||
* @return
|
||||
*/
|
||||
public long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value correspond soit à la durée de la sanction appliquée (en secondes), soit à la valeur de l'amende appliquée
|
||||
* @param value
|
||||
*/
|
||||
public void setValue(Long value) {
|
||||
if (value != null && value.longValue() < 0) value = null;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return UUID.fromString(playerId);
|
||||
}
|
||||
|
||||
public void setPlayerId(UUID player) {
|
||||
if (player == null) throw new IllegalArgumentException("le paramètre ne peut être null");
|
||||
this.playerId = player.toString();
|
||||
}
|
||||
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
if (message == null) throw new IllegalArgumentException("le paramètre ne peut être null");
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public enum ActionType{
|
||||
BAN, UNBAN, MUTE, UNMUTE, REPORT, KICK
|
||||
}
|
||||
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import fr.pandacube.java.util.db.ModoHistoryElement.ActionType;
|
||||
|
||||
public class ModoHistoryTable extends SQLTable<ModoHistoryElement> {
|
||||
|
||||
|
||||
|
||||
public ModoHistoryTable() throws SQLException {
|
||||
super("pandacube_modo_history");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "modoId CHAR(36) NULL," // null si c'est la console
|
||||
+ "actionType ENUM('BAN', 'UNBAN', 'MUTE', 'UNMUTE', 'REPORT', 'KICK') NOT NULL,"
|
||||
+ "time BIGINT NOT NULL,"
|
||||
+ "playerId CHAR(36) NOT NULL,"
|
||||
+ "value BIGINT NULL,"
|
||||
+ "message VARCHAR(512) NOT NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModoHistoryElement getElementInstance(ResultSet sqlResult) throws SQLException {
|
||||
ModoHistoryElement el = new ModoHistoryElement(
|
||||
sqlResult.getInt("id"),
|
||||
sqlResult.getString("modoId"),
|
||||
ActionType.valueOf(sqlResult.getString("actionType")),
|
||||
sqlResult.getString("playerId"),
|
||||
sqlResult.getString("message"));
|
||||
el.setValue(sqlResult.getLong("value"));
|
||||
el.setTime(sqlResult.getLong("time"));
|
||||
return el;
|
||||
}
|
||||
|
||||
}
|
@@ -1,97 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.pandacube.java.util.db2.sql_tools.DBConnection;
|
||||
|
||||
/**
|
||||
* <b>ORM = Object-Relational Mapping</b><br/>
|
||||
* Liste des tables avec leur classes :
|
||||
* <ul>
|
||||
* <li><code>LoginHistoryTable</code></li>
|
||||
* <li><code>ModoHistoryTable</code></li>
|
||||
* <li><code>StaffTicketTable</code></li>
|
||||
* <li><code>MPMessageTable</code></li>
|
||||
* <li><code>MPGroupTable</code></li>
|
||||
* <li><code>MPGroupUserTable</code></li>
|
||||
* <li><code>MPWebSessionTable</code></li>
|
||||
* <li><code>PlayerIgnoreTable</code></li>
|
||||
* </ul>
|
||||
* @author Marc Baloup
|
||||
*
|
||||
*/
|
||||
public final class ORM {
|
||||
|
||||
private static List<SQLTable<?>> tables = new ArrayList<SQLTable<?>>();
|
||||
|
||||
/* package */ static DBConnection connection;
|
||||
|
||||
|
||||
public synchronized static void init(DBConnection conn) {
|
||||
try {
|
||||
|
||||
connection = conn;
|
||||
/*
|
||||
* Les tables SQL sont à instancier ici !
|
||||
*/
|
||||
|
||||
tables.add(new LoginHistoryTable());
|
||||
|
||||
tables.add(new ModoHistoryTable());
|
||||
|
||||
tables.add(new MPGroupTable());
|
||||
tables.add(new MPGroupUserTable());
|
||||
tables.add(new MPMessageTable());
|
||||
|
||||
tables.add(new OnlineShopHistoryTable());
|
||||
|
||||
tables.add(new PlayerTable());
|
||||
|
||||
tables.add(new PlayerIgnoreTable());
|
||||
|
||||
tables.add(new ShopStockTable());
|
||||
|
||||
tables.add(new StaffTicketTable());
|
||||
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public synchronized static <T extends SQLTable<?>> T getTable(Class<T> c) {
|
||||
if (c == null) return null;
|
||||
for (SQLTable<?> table : tables) {
|
||||
|
||||
if (c.isAssignableFrom(table.getClass())) {
|
||||
return c.cast(table);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private ORM() { } // rend la classe non instanciable
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -1,129 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class OnlineShopHistoryElement extends SQLElement {
|
||||
|
||||
|
||||
private long time;// timestamp en millisecondes
|
||||
private String transactionId;
|
||||
private SourceType sourceType;// enum(REAL_MONEY, BAMBOU)
|
||||
private String sourcePlayerId;// l'id du joueur duquel vient l'élément source
|
||||
private double sourceQuantity;// la quantité d'entrée (en euro, ou bambou)
|
||||
private String sourceName;// le nom désignant la source ("euro", "bambou", ...)
|
||||
private DestType destType;// enum(BAMBOU, GRADE)
|
||||
private String destPlayerId;// l'id du joueur qui reçoit l'élément obtenu après cette transaction
|
||||
private double destQuantity;// la quantité de sortie (bambou, ou 1 pour l'achat d'un grade)
|
||||
private String destName;// le nom désignant la destination ("bambou", le nom du grade)
|
||||
|
||||
public OnlineShopHistoryElement(long t, SourceType st, double sQtt, String sN, DestType dt, UUID dPID, double dQtt, String dN) {
|
||||
super("pandacube_onlineshop_history");
|
||||
setTime(t);
|
||||
setSourceType(st);
|
||||
setSourceQuantity(sQtt);
|
||||
setSourceName(sN);
|
||||
setDestType(dt);
|
||||
setDestPlayerId(dPID);
|
||||
setDestQuantity(dQtt);
|
||||
setDestName(dN);
|
||||
}
|
||||
|
||||
OnlineShopHistoryElement(int id, long t, String st, double sQtt, String sN, String dt, String dPID, double dQtt, String dN) {
|
||||
super("pandacube_onlineshop_history", id);
|
||||
setTime(t);
|
||||
setSourceType(SourceType.valueOf(st));
|
||||
setSourceQuantity(sQtt);
|
||||
setSourceName(sN);
|
||||
setDestType(DestType.valueOf(dt));
|
||||
destPlayerId = dPID;
|
||||
setDestQuantity(dQtt);
|
||||
setDestName(dN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
Long.toString(time),
|
||||
transactionId,
|
||||
sourceType.name(),
|
||||
sourcePlayerId,
|
||||
Double.toString(sourceQuantity),
|
||||
sourceName,
|
||||
destType.name(),
|
||||
destPlayerId,
|
||||
Double.toString(destQuantity),
|
||||
destName
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"time",
|
||||
"transactionId",
|
||||
"sourceType",
|
||||
"sourcePlayerId",
|
||||
"sourceQuantity",
|
||||
"sourceName",
|
||||
"destType",
|
||||
"destPlayerId",
|
||||
"destQuantity",
|
||||
"destName"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public long getTime() { return time; }
|
||||
public String getTransactionId() { return transactionId; }
|
||||
public SourceType getSourceType() { return sourceType; }
|
||||
public UUID getSourcePlayerId() { return UUID.fromString(sourcePlayerId); }
|
||||
public double getSourceQuantity() { return sourceQuantity; }
|
||||
public String getSourceName() { return sourceName; }
|
||||
public DestType getDestType() { return destType; }
|
||||
public UUID getDestPlayerId() { return UUID.fromString(destPlayerId); }
|
||||
public double getDestQuantity() { return destQuantity; }
|
||||
public String getDestName() { return destName; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void setTime(long t) { time = t; }
|
||||
public void setTransactionId(String t) { transactionId = t; }
|
||||
public void setSourceType(SourceType st) {
|
||||
if (st == null) throw new IllegalArgumentException("sourceType can't be null");
|
||||
sourceType = st;
|
||||
}
|
||||
public void setSourcePlayerId(UUID pId) { sourcePlayerId = pId.toString(); }
|
||||
public void setSourceQuantity(double qtt) { sourceQuantity = qtt; }
|
||||
public void setSourceName(String name) {
|
||||
if (name == null) throw new IllegalArgumentException("sourceName can't be null");
|
||||
sourceName = name;
|
||||
}
|
||||
public void setDestType(DestType st) {
|
||||
if (st == null) throw new IllegalArgumentException("destType can't be null");
|
||||
destType = st;
|
||||
}
|
||||
public void setDestPlayerId(UUID pId) {
|
||||
if (pId == null) throw new IllegalArgumentException("destPlayerId can't be null");
|
||||
destPlayerId = pId.toString();
|
||||
}
|
||||
public void setDestQuantity(double qtt) { destQuantity = qtt; }
|
||||
public void setDestName(String name) {
|
||||
if (name == null) throw new IllegalArgumentException("destName can't be null");
|
||||
destName = name;
|
||||
}
|
||||
|
||||
|
||||
public static enum SourceType {
|
||||
REAL_MONEY, BAMBOU
|
||||
}
|
||||
|
||||
public static enum DestType {
|
||||
BAMBOU, GRADE
|
||||
}
|
||||
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OnlineShopHistoryTable extends SQLTable<OnlineShopHistoryElement> {
|
||||
|
||||
public OnlineShopHistoryTable() throws SQLException {
|
||||
super("pandacube_onlineshop_history");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "time BIGINT NOT NULL,"
|
||||
+ "transactionId VARCHAR(255) NULL,"
|
||||
+ "sourceType ENUM('REAL_MONEY', 'BAMBOU') NOT NULL,"
|
||||
+ "sourcePlayerId CHAR(36) NULL,"
|
||||
+ "sourceQuantity DOUBLE NOT NULL,"
|
||||
+ "sourceName VARCHAR(64) NOT NULL,"
|
||||
+ "destType ENUM('BAMBOU', 'GRADE') NOT NULL,"
|
||||
+ "destPlayerId CHAR(36) NOT NULL,"
|
||||
+ "destQuantity DOUBLE NOT NULL,"
|
||||
+ "destName VARCHAR(64) NOT NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OnlineShopHistoryElement getElementInstance(ResultSet sqlResult) throws SQLException {
|
||||
OnlineShopHistoryElement el = new OnlineShopHistoryElement(
|
||||
sqlResult.getInt("id"),
|
||||
sqlResult.getLong("time"),
|
||||
sqlResult.getString("sourceType"),
|
||||
sqlResult.getDouble("sourceQuantity"),
|
||||
sqlResult.getString("sourceName"),
|
||||
sqlResult.getString("destType"),
|
||||
sqlResult.getString("destPlayerId"),
|
||||
sqlResult.getDouble("destQuantity"),
|
||||
sqlResult.getString("destName"));
|
||||
el.setTransactionId(sqlResult.getString("transactionId"));
|
||||
String sourcePlayerId = sqlResult.getString("sourcePlayerId");
|
||||
if (sourcePlayerId != null)
|
||||
el.setSourcePlayerId(UUID.fromString(sourcePlayerId));
|
||||
return el;
|
||||
}
|
||||
|
||||
}
|
@@ -1,179 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerElement extends SQLElement {
|
||||
|
||||
private String playerId;
|
||||
private String token = null;
|
||||
private String mailCheck = null;
|
||||
private String password = null;
|
||||
private String mail = null;
|
||||
private String playerDisplayName;
|
||||
private long firstTimeInGame;
|
||||
private long timeWebRegister = 0;
|
||||
private long lastTimeInGame = 0;
|
||||
private long lastWebActivity = 0;
|
||||
private String onlineInServer = null;
|
||||
private String skinURL = null;
|
||||
private boolean isVanish = false;
|
||||
private Date birthday = null;
|
||||
private int lastYearCelebratedBirthday = 0;
|
||||
private Long banTimeout = null;
|
||||
private Long muteTimeout = null;
|
||||
private boolean isWhitelisted = false;
|
||||
private long bambou = 0;
|
||||
private String grade = "default";
|
||||
|
||||
public PlayerElement(UUID pId, String dispName, long firstTimeIG, long lastWebAct, String onlineInServer) {
|
||||
super("pandacube_player");
|
||||
setPlayerId(pId);
|
||||
setOnlineInServer(onlineInServer);
|
||||
setLastWebActivity(lastWebAct);
|
||||
setPlayerDisplayName(dispName);
|
||||
setFirstTimeInGame(firstTimeIG);
|
||||
}
|
||||
|
||||
PlayerElement(int id, String pId, String dispName, long firstTimeIG, long lastWebAct, String onlineInServer) {
|
||||
super("pandacube_player", id);
|
||||
setPlayerId(UUID.fromString(pId));
|
||||
setOnlineInServer(onlineInServer);
|
||||
setLastWebActivity(lastWebAct);
|
||||
setPlayerDisplayName(dispName);
|
||||
setFirstTimeInGame(firstTimeIG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
playerId,
|
||||
token,
|
||||
mailCheck,
|
||||
password,
|
||||
mail,
|
||||
playerDisplayName,
|
||||
Long.toString(firstTimeInGame),
|
||||
Long.toString(timeWebRegister),
|
||||
Long.toString(lastTimeInGame),
|
||||
Long.toString(lastWebActivity),
|
||||
onlineInServer,
|
||||
skinURL,
|
||||
isVanish?"1":"0",
|
||||
(birthday!=null)?birthday.toString():null,
|
||||
Integer.toString(lastYearCelebratedBirthday),
|
||||
(banTimeout!=null)?banTimeout.toString():null,
|
||||
(muteTimeout!=null)?muteTimeout.toString():null,
|
||||
isWhitelisted?"1":"0",
|
||||
Long.toString(bambou),
|
||||
grade
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"playerId",
|
||||
"token",
|
||||
"mailCheck",
|
||||
"password",
|
||||
"mail",
|
||||
"playerDisplayName",
|
||||
"firstTimeInGame",
|
||||
"timeWebRegister",
|
||||
"lastTimeInGame",
|
||||
"lastWebActivity",
|
||||
"onlineInServer",
|
||||
"skinURL",
|
||||
"isVanish",
|
||||
"birthday",
|
||||
"lastYearCelebratedBirthday",
|
||||
"banTimeout",
|
||||
"muteTimeout",
|
||||
"isWhitelisted",
|
||||
"bambou",
|
||||
"grade"
|
||||
};
|
||||
}
|
||||
|
||||
public UUID getPlayerId() { return UUID.fromString(playerId); }
|
||||
public UUID getToken() { return (token == null) ? null : UUID.fromString(token); }
|
||||
public String getMailCheck() { return mailCheck; }
|
||||
public String getPasswordHash() { return password; }
|
||||
public String getMail() { return mail; }
|
||||
public long getFirstTimeInGame() { return firstTimeInGame; }
|
||||
public long getTimeWebRegister() { return timeWebRegister; }
|
||||
public long getLastTimeInGame() { return lastTimeInGame; }
|
||||
public long getLastWebActivity() { return lastWebActivity; }
|
||||
public String getOnlineInServer() { return onlineInServer; }
|
||||
public String getPlayerDisplayName() { return playerDisplayName; }
|
||||
public String getSkinURL() { return skinURL; }
|
||||
public boolean isVanish() { return isVanish; }
|
||||
public Date getBirthday() { return birthday; }
|
||||
public int getLastYearCelebratedBirthday() { return lastYearCelebratedBirthday; }
|
||||
public Long getBanTimeout() { return banTimeout; }
|
||||
public Long getMuteTimeout() { return muteTimeout; }
|
||||
public boolean isWhitelisted() { return isWhitelisted; }
|
||||
public long getBambou() { return bambou; }
|
||||
public String getGrade() { return grade; }
|
||||
|
||||
|
||||
|
||||
public void setPlayerId(UUID pName) {
|
||||
if (pName == null)
|
||||
throw new NullPointerException();
|
||||
playerId = pName.toString();
|
||||
}
|
||||
|
||||
public void setToken(UUID t) {
|
||||
if (t == null)
|
||||
token = null;
|
||||
else
|
||||
token = t.toString();
|
||||
}
|
||||
|
||||
public void setMailCheck(String mCheck) { mailCheck = mCheck; }
|
||||
|
||||
public void setPasswordHash(String pass) { password = pass; }
|
||||
|
||||
public void setMail(String m) { mail = m; }
|
||||
|
||||
public void setFirstTimeInGame(long time) { firstTimeInGame = time; }
|
||||
|
||||
public void setTimeWebRegister(long time) { timeWebRegister = time; }
|
||||
|
||||
public void setLastTimeInGame(long time) { lastTimeInGame = time; }
|
||||
|
||||
public void setLastWebActivity(long time) { lastWebActivity = time; }
|
||||
|
||||
public void setOnlineInServer(String onlineInServer) { this.onlineInServer = onlineInServer; }
|
||||
|
||||
public void setSkinURL(String skinURL) { this.skinURL = skinURL; }
|
||||
|
||||
public void setPlayerDisplayName(String dispName) {
|
||||
if (dispName == null)
|
||||
throw new NullPointerException();
|
||||
playerDisplayName = dispName;
|
||||
}
|
||||
|
||||
public void setVanish(boolean v) { isVanish = v; }
|
||||
|
||||
public void setBirthday(Date b) { birthday = b; }
|
||||
|
||||
public void setLastYearCelebratedBirthday(int y) { lastYearCelebratedBirthday = y; }
|
||||
|
||||
public void setBanTimeout(Long banT) { banTimeout = banT; }
|
||||
|
||||
public void setMuteTimeout(Long muteT) { muteTimeout = muteT; }
|
||||
|
||||
public void setWhitelisted(boolean w) { isWhitelisted = w; }
|
||||
|
||||
public void setBambou(long b) { bambou = b; }
|
||||
|
||||
public void setGrade(String g) {
|
||||
if (g == null || g.equals(""))
|
||||
g = "default";
|
||||
grade = g;
|
||||
}
|
||||
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerIgnoreElement extends SQLElement {
|
||||
|
||||
private String ignore;
|
||||
private String ignored;
|
||||
|
||||
|
||||
public PlayerIgnoreElement(UUID ignore, UUID ignored) {
|
||||
super("pandacube_player_ignore");
|
||||
setIgnore(ignore);
|
||||
setIgnored(ignored);
|
||||
}
|
||||
|
||||
|
||||
protected PlayerIgnoreElement(int id, String ignore, String ignored) {
|
||||
super("pandacube_player_ignore", id);
|
||||
this.ignore = ignore;
|
||||
this.ignored = ignored;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
ignore,
|
||||
ignored
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"ignorer",
|
||||
"ignored"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public UUID getIgnore() {
|
||||
return UUID.fromString(ignore);
|
||||
}
|
||||
|
||||
|
||||
public void setIgnore(UUID i) {
|
||||
if (i == null)
|
||||
throw new IllegalArgumentException("i can't be null");
|
||||
ignore = i.toString();
|
||||
}
|
||||
|
||||
|
||||
public UUID getIgnored() {
|
||||
return UUID.fromString(ignored);
|
||||
}
|
||||
|
||||
|
||||
public void setIgnored(UUID i) {
|
||||
if (i == null)
|
||||
throw new IllegalArgumentException("i can't be null");
|
||||
ignored = i.toString();
|
||||
}
|
||||
|
||||
}
|
@@ -1,79 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerIgnoreTable extends SQLTable<PlayerIgnoreElement> {
|
||||
|
||||
public PlayerIgnoreTable() throws SQLException {
|
||||
super("pandacube_player_ignore");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "ignorer CHAR(36) NOT NULL,"
|
||||
+ "ignored CHAR(36) NOT NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PlayerIgnoreElement getElementInstance(ResultSet sqlResult) throws SQLException {
|
||||
return new PlayerIgnoreElement(sqlResult.getInt("id"),
|
||||
sqlResult.getString("ignorer"),
|
||||
sqlResult.getString("ignored"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<UUID> getListIgnoredPlayer(UUID ignore) throws SQLException {
|
||||
if (ignore == null)
|
||||
throw new IllegalArgumentException("ignore can't be null");
|
||||
|
||||
List<PlayerIgnoreElement> dbIgnored = getAll("ignorer = '"+ignore+"'", "id", null, null);
|
||||
|
||||
List<UUID> ret = new ArrayList<UUID>();
|
||||
|
||||
for (PlayerIgnoreElement el : dbIgnored) {
|
||||
ret.add(el.getIgnored());
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean isPlayerIgnoringPlayer(UUID ignore, UUID ignored) throws SQLException {
|
||||
if (ignore == null)
|
||||
throw new IllegalArgumentException("ignore can't be null");
|
||||
if (ignored == null)
|
||||
throw new IllegalArgumentException("ignored can't be null");
|
||||
|
||||
return getFirst("ignorer = '"+ignore+"' AND ignored = '"+ignored+"'", "id") != null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setPlayerIgnorePlayer(UUID ignore, UUID ignored, boolean set) throws SQLException {
|
||||
if (ignore == null)
|
||||
throw new IllegalArgumentException("ignore can't be null");
|
||||
if (ignored == null)
|
||||
throw new IllegalArgumentException("ignored can't be null");
|
||||
if (ignore.equals(ignored)) // on ne peut pas s'auto ignorer
|
||||
return;
|
||||
|
||||
PlayerIgnoreElement el = getFirst("ignorer = '"+ignore+"' AND ignored = '"+ignored+"'", "id");
|
||||
|
||||
if (set && el == null) {
|
||||
el = new PlayerIgnoreElement(ignore, ignored);
|
||||
el.save();
|
||||
}
|
||||
else if (!set && el != null) {
|
||||
el.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerTable extends SQLTable<PlayerElement> {
|
||||
|
||||
public PlayerTable() throws SQLException {
|
||||
super("pandacube_player");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "playerId CHAR(36) NOT NULL,"
|
||||
+ "token CHAR(36) NULL,"
|
||||
+ "mailCheck VARCHAR(255) NULL,"
|
||||
+ "password VARCHAR(255) NULL,"
|
||||
+ "mail VARCHAR(255) NULL,"
|
||||
+ "playerDisplayName VARCHAR(255) NOT NULL,"
|
||||
+ "firstTimeInGame BIGINT NOT NULL,"
|
||||
+ "timeWebRegister BIGINT NULL,"
|
||||
+ "lastTimeInGame BIGINT NULL,"
|
||||
+ "lastWebActivity BIGINT NOT NULL,"
|
||||
+ "onlineInServer VARCHAR(32) NULL,"
|
||||
+ "skinURL VARCHAR(255) NULL,"
|
||||
+ "isVanish TINYINT NULL,"
|
||||
+ "birthday DATE NULL,"
|
||||
+ "lastYearCelebratedBirthday INT NOT NULL DEFAULT 0,"
|
||||
+ "banTimeout BIGINT NULL,"
|
||||
+ "muteTimeout BIGINT NULL,"
|
||||
+ "isWhitelisted TINYINT NOT NULL DEFAULT 0,"
|
||||
+ "bambou BIGINT NOT NULL DEFAULT 0,"
|
||||
+ "grade VARCHAR(36) NOT NULL DEFAULT 'default'";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PlayerElement getElementInstance(ResultSet sqlResult)
|
||||
throws SQLException {
|
||||
PlayerElement el = new PlayerElement(
|
||||
sqlResult.getInt("id"),
|
||||
sqlResult.getString("playerId"),
|
||||
sqlResult.getString("playerDisplayName"),
|
||||
sqlResult.getLong("firstTimeInGame"),
|
||||
sqlResult.getLong("lastWebActivity"),
|
||||
sqlResult.getString("onlineInServer"));
|
||||
String token = sqlResult.getString("token");
|
||||
el.setToken((token == null) ? null : UUID.fromString(token));
|
||||
el.setMailCheck(sqlResult.getString("mailCheck"));
|
||||
el.setPasswordHash(sqlResult.getString("password"));
|
||||
el.setMail(sqlResult.getString("mail"));
|
||||
el.setFirstTimeInGame(sqlResult.getLong("firstTimeInGame"));
|
||||
el.setTimeWebRegister(sqlResult.getLong("timeWebRegister"));
|
||||
el.setLastTimeInGame(sqlResult.getLong("lastTimeInGame"));
|
||||
el.setSkinURL(sqlResult.getString("skinURL"));
|
||||
el.setVanish(sqlResult.getBoolean("isVanish"));
|
||||
el.setBirthday(sqlResult.getDate("birthday"));
|
||||
el.setLastYearCelebratedBirthday(sqlResult.getInt("lastYearCelebratedBirthday"));
|
||||
el.setBambou(sqlResult.getLong("bambou"));
|
||||
el.setGrade(sqlResult.getString("grade"));
|
||||
|
||||
long longVal;
|
||||
|
||||
longVal = sqlResult.getLong("banTimeout");
|
||||
el.setBanTimeout(sqlResult.wasNull()?null:longVal);
|
||||
longVal = sqlResult.getLong("muteTimeout");
|
||||
el.setMuteTimeout(sqlResult.wasNull()?null:longVal);
|
||||
|
||||
el.setWhitelisted(sqlResult.getBoolean("isWhitelisted"));
|
||||
return el;
|
||||
}
|
||||
|
||||
}
|
@@ -1,162 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import fr.pandacube.java.util.db2.sql_tools.DBConnection;
|
||||
|
||||
public abstract class SQLElement {
|
||||
|
||||
DBConnection db = ORM.connection;
|
||||
|
||||
|
||||
private boolean saved = false;
|
||||
|
||||
protected final String tableName;
|
||||
|
||||
// champ relatif aux données
|
||||
private int id = 0;
|
||||
|
||||
|
||||
|
||||
public SQLElement(String name) {
|
||||
tableName = name;
|
||||
saved = false;
|
||||
}
|
||||
protected SQLElement(String name, int id) {
|
||||
tableName = name;
|
||||
this.id = id;
|
||||
saved = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void save() {
|
||||
|
||||
try {
|
||||
Connection conn;
|
||||
conn = db.getNativeConnection();
|
||||
|
||||
String[] fields = getFieldsName(), values = getValues();
|
||||
|
||||
|
||||
|
||||
if (saved)
|
||||
{ // mettre à jour les valeurs dans la base
|
||||
String sql = "";
|
||||
for (int i=0; i<fields.length && i<values.length; i++)
|
||||
{
|
||||
sql += fields[i]+" = ? ,";
|
||||
}
|
||||
|
||||
if (sql.length() > 0)
|
||||
sql = sql.substring(0, sql.length()-1);
|
||||
|
||||
PreparedStatement st = conn.prepareStatement("UPDATE "+tableName+" SET "+sql+" WHERE id="+id);
|
||||
try {
|
||||
for (int i=0; i<fields.length && i<values.length; i++)
|
||||
{
|
||||
st.setString(i+1, values[i]);
|
||||
}
|
||||
|
||||
st.executeUpdate();
|
||||
} finally {
|
||||
st.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // ajouter dans la base
|
||||
String concat_vals = "";
|
||||
String concat_fields = StringUtils.join(fields, ',');
|
||||
for (int i=0; i<fields.length && i<values.length; i++)
|
||||
{
|
||||
if (i!=0) concat_vals += ",";
|
||||
concat_vals += " ? ";
|
||||
}
|
||||
|
||||
|
||||
PreparedStatement st = conn.prepareStatement("INSERT INTO "+tableName+" ("+concat_fields+") VALUES ("+concat_vals+")", Statement.RETURN_GENERATED_KEYS);
|
||||
try {
|
||||
for (int i=0; i<fields.length && i<values.length; i++)
|
||||
{
|
||||
st.setString(i+1, values[i]);
|
||||
}
|
||||
|
||||
st.executeUpdate();
|
||||
|
||||
ResultSet rs = st.getGeneratedKeys();
|
||||
try {
|
||||
if(rs.next())
|
||||
{
|
||||
id = rs.getInt(1);
|
||||
}
|
||||
|
||||
saved = true;
|
||||
} finally {
|
||||
rs.close();
|
||||
}
|
||||
} finally {
|
||||
st.close();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void delete() {
|
||||
|
||||
try {
|
||||
if (saved)
|
||||
{ // supprimer la ligne de la base
|
||||
PreparedStatement st = db.getNativeConnection().prepareStatement("DELETE FROM "+tableName+" WHERE id="+id);
|
||||
try {
|
||||
st.executeUpdate();
|
||||
saved = false;
|
||||
} finally {
|
||||
st.close();
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int getId() {
|
||||
if (!saved)
|
||||
throw new IllegalStateException("Ne peut pas fournir l'ID d'un élément non sauvegardé");
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Récupère la liste des valeurs des champs de la table correspondante, excepté
|
||||
* le champ <code>id</code>
|
||||
* @return les valeurs des champs sous la forme de chaine de caractères
|
||||
*/
|
||||
protected abstract String[] getValues();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Récupère la liste des noms des champs de la table correspondante, excepté
|
||||
* le champ <code>id</code>
|
||||
* @return les noms des champs sous la forme de chaine de caractères
|
||||
*/
|
||||
protected abstract String[] getFieldsName();
|
||||
}
|
@@ -1,142 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.pandacube.java.util.db2.sql_tools.DBConnection;
|
||||
|
||||
public abstract class SQLTable<T extends SQLElement> {
|
||||
|
||||
DBConnection db = ORM.connection;
|
||||
|
||||
private final String tableName;
|
||||
|
||||
|
||||
public SQLTable(String name) throws SQLException {
|
||||
tableName = name;
|
||||
|
||||
if (!tableExist())
|
||||
createTable();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void createTable() throws SQLException {
|
||||
Statement stmt = db.getNativeConnection().createStatement();
|
||||
String sql = "CREATE TABLE IF NOT EXISTS "+tableName+" " +
|
||||
"("+createTableParameters()+")";
|
||||
try {
|
||||
stmt.executeUpdate(sql);
|
||||
} finally {
|
||||
stmt.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean tableExist() throws SQLException {
|
||||
ResultSet set = null;
|
||||
boolean exist = false;
|
||||
try {
|
||||
set = db.getNativeConnection().getMetaData().getTables(null, null, tableName, null);
|
||||
exist = set.next();
|
||||
} finally {
|
||||
if (set != null)
|
||||
set.close();
|
||||
}
|
||||
return exist;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne une chaine de caractère qui sera inclu dans la requête SQL de création de la table.
|
||||
* La requête est de la forme : <code>CRATE TABLE tableName ();</code>
|
||||
* La chaine retournée sera ajoutée entre les parenthèses.
|
||||
*/
|
||||
protected abstract String createTableParameters();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Crée une instance de l'élément courant se trouvant dans le resultSet passé en paramètre
|
||||
* @param sqlResult le set de résultat, déjà positionné sur un élément. Ne surtout pas appeler la méthode next() !
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected abstract T getElementInstance(ResultSet sqlResult) throws SQLException;
|
||||
|
||||
|
||||
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public T get(int id) throws SQLException {
|
||||
T elementInstance = null;
|
||||
Statement stmt = db.getNativeConnection().createStatement();
|
||||
try {
|
||||
String sql = "SELECT * FROM "+tableName+" WHERE id = "+id+";";
|
||||
|
||||
ResultSet set = stmt.executeQuery(sql);
|
||||
try {
|
||||
if (set.next())
|
||||
elementInstance = getElementInstance(set);
|
||||
} finally {
|
||||
set.close();
|
||||
}
|
||||
} finally {
|
||||
stmt.close();
|
||||
}
|
||||
return elementInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<T> getAll() throws SQLException {
|
||||
return getAll(null, null, null, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public T getFirst(String where, String orderBy) throws SQLException {
|
||||
List<T> elts = getAll(where, orderBy, 1, null);
|
||||
return (elts.size() == 0)? null : elts.get(0);
|
||||
}
|
||||
|
||||
|
||||
public List<T> getAll(String where, String orderBy, Integer limit, Integer offset) throws SQLException {
|
||||
Statement stmt = db.getNativeConnection().createStatement();
|
||||
String sql = "SELECT * FROM "+tableName;
|
||||
|
||||
if (where != null)
|
||||
sql += " WHERE "+where;
|
||||
if (orderBy != null)
|
||||
sql += " ORDER BY "+orderBy;
|
||||
if (limit != null)
|
||||
sql += " LIMIT "+limit;
|
||||
if (offset != null)
|
||||
sql += " OFFSET "+offset;
|
||||
sql += ";";
|
||||
|
||||
List<T> elmts = new ArrayList<T>();
|
||||
try {
|
||||
ResultSet set = stmt.executeQuery(sql);
|
||||
try {
|
||||
while (set.next())
|
||||
elmts.add(getElementInstance(set));
|
||||
} finally {
|
||||
set.close();
|
||||
}
|
||||
} finally {
|
||||
stmt.close();
|
||||
}
|
||||
return elmts;
|
||||
}
|
||||
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
public class ShopStockElement extends SQLElement {
|
||||
|
||||
private String material;
|
||||
private short damage = 0;
|
||||
private double quantity;
|
||||
private String server;
|
||||
|
||||
|
||||
public ShopStockElement(String m, short d, double q, String s) {
|
||||
super("pandacube_shop_stock");
|
||||
setMaterial(m);
|
||||
setDamage(d);
|
||||
setQuantity(q);
|
||||
setServer(s);
|
||||
}
|
||||
|
||||
protected ShopStockElement(int id, String m, short d, double q, String s) {
|
||||
super("pandacube_shop_stock", id);
|
||||
setMaterial(m);
|
||||
setDamage(d);
|
||||
setQuantity(q);
|
||||
setServer(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
material,
|
||||
Short.toString(damage),
|
||||
Double.toString(quantity),
|
||||
server
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"material",
|
||||
"damage",
|
||||
"quantity",
|
||||
"server"
|
||||
};
|
||||
}
|
||||
|
||||
public String getMaterial() { return material; }
|
||||
|
||||
public void setMaterial(String m) {
|
||||
if (m == null) throw new IllegalArgumentException("Material can't be null");
|
||||
material = m;
|
||||
}
|
||||
|
||||
public short getDamage() { return damage; }
|
||||
|
||||
public void setDamage(short d) {
|
||||
damage = d;
|
||||
}
|
||||
|
||||
public double getQuantity() { return quantity; }
|
||||
|
||||
public void setQuantity(double q) {
|
||||
if (q < 0) q = 0;
|
||||
quantity = q;
|
||||
}
|
||||
|
||||
public String getServer() { return server; }
|
||||
|
||||
public void setServer(String s) {
|
||||
if (s == null) throw new IllegalArgumentException("Server can't be null");
|
||||
server = s;
|
||||
}
|
||||
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ShopStockTable extends SQLTable<ShopStockElement> {
|
||||
|
||||
public ShopStockTable() throws SQLException {
|
||||
super("pandacube_shop_stock");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "material varchar(50) NOT NULL,"
|
||||
+ "damage int(11) NOT NULL DEFAULT '0',"
|
||||
+ "quantity double NOT NULL,"
|
||||
+ "server varchar(50) NOT NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopStockElement getElementInstance(ResultSet sqlResult) throws SQLException {
|
||||
return new ShopStockElement(sqlResult.getInt("id"),
|
||||
sqlResult.getString("material"),
|
||||
sqlResult.getShort("damage"),
|
||||
sqlResult.getDouble("quantity"),
|
||||
sqlResult.getString("server"));
|
||||
}
|
||||
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class StaffTicketElement extends SQLElement {
|
||||
|
||||
|
||||
private String playerId;
|
||||
private String message;
|
||||
private long creationTime;
|
||||
private String staffPlayerId = null;
|
||||
|
||||
|
||||
public StaffTicketElement(UUID pId, String m, long creaTime) {
|
||||
super("pandacube_staff_ticket");
|
||||
setPlayerId(pId);
|
||||
setMessage(m);
|
||||
setCreationTime(creaTime);
|
||||
|
||||
}
|
||||
protected StaffTicketElement(int id, String pId, String m, long creaTime) {
|
||||
super("pandacube_staff_ticket", id);
|
||||
setPlayerId(UUID.fromString(pId));
|
||||
setMessage(m);
|
||||
setCreationTime(creaTime);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] getValues() {
|
||||
return new String[] {
|
||||
playerId,
|
||||
message,
|
||||
Long.toString(creationTime),
|
||||
staffPlayerId,
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getFieldsName() {
|
||||
return new String[] {
|
||||
"playerId",
|
||||
"message",
|
||||
"creationTime",
|
||||
"staffPlayerId"
|
||||
};
|
||||
}
|
||||
public UUID getPlayerId() {
|
||||
return UUID.fromString(playerId);
|
||||
}
|
||||
public void setPlayerId(UUID pId) {
|
||||
if (pId == null) throw new IllegalArgumentException("playerName can't be null");
|
||||
this.playerId = pId.toString();
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
if (message == null) throw new IllegalArgumentException("message can't be null");
|
||||
this.message = message;
|
||||
}
|
||||
public long getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
public void setCreationTime(long creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
public UUID getStaffPlayer() {
|
||||
if (staffPlayerId == null) return null;
|
||||
return UUID.fromString(staffPlayerId);
|
||||
}
|
||||
public void setStaffPlayer(UUID staffId) {
|
||||
if (staffId == null) staffPlayerId = null;
|
||||
else staffPlayerId = staffId.toString();
|
||||
}
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package fr.pandacube.java.util.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class StaffTicketTable extends SQLTable<StaffTicketElement> {
|
||||
|
||||
|
||||
public StaffTicketTable() throws SQLException {
|
||||
super("pandacube_staff_ticket");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTableParameters() {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "playerId CHAR(36) NOT NULL,"
|
||||
+ "message VARCHAR(1024) NOT NULL,"
|
||||
+ "creationTime BIGINT NOT NULL,"
|
||||
+ "staffPlayerId CHAR(36) NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StaffTicketElement getElementInstance(ResultSet sqlResult)
|
||||
throws SQLException {
|
||||
StaffTicketElement el = new StaffTicketElement(
|
||||
sqlResult.getInt("id"),
|
||||
sqlResult.getString("playerId"),
|
||||
sqlResult.getString("message"),
|
||||
sqlResult.getLong("creationTime"));
|
||||
String staffId = sqlResult.getString("staffPlayerId");
|
||||
el.setStaffPlayer((staffId == null) ? null : UUID.fromString(staffId));
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
}
|
@@ -1,2 +0,0 @@
|
||||
@java.lang.Deprecated
|
||||
package fr.pandacube.java.util.db;
|
Reference in New Issue
Block a user