From 8b1f18fc1bf6df1bd50409612bf4bbfbd2b560c0 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 3 Mar 2016 14:39:50 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20des=20tables=20SQL=20pou?= =?UTF-8?q?r=20la=20prise=20en=20charges=20de=20la=20boutique=20en=20ligne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/db/OnlineShopHistoryElement.java | 129 ++++++++++++++++++ .../java/util/db/OnlineShopHistoryTable.java | 43 ++++++ .../pandacube/java/util/db/PlayerElement.java | 22 ++- .../pandacube/java/util/db/PlayerTable.java | 6 +- 4 files changed, 196 insertions(+), 4 deletions(-) create mode 100644 src/fr/pandacube/java/util/db/OnlineShopHistoryElement.java create mode 100644 src/fr/pandacube/java/util/db/OnlineShopHistoryTable.java diff --git a/src/fr/pandacube/java/util/db/OnlineShopHistoryElement.java b/src/fr/pandacube/java/util/db/OnlineShopHistoryElement.java new file mode 100644 index 0000000..009aa2d --- /dev/null +++ b/src/fr/pandacube/java/util/db/OnlineShopHistoryElement.java @@ -0,0 +1,129 @@ +package fr.pandacube.java.util.db; + +import java.util.UUID; + +public class OnlineShopHistoryElement extends SQLElement { + + + private long time;// timestamp en millisecondes + 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, UUID sPID, double sQtt, String sN, DestType dt, UUID dPID, double dQtt, String dN) { + super("pandacube_onlineshop_history"); + setTime(t); + setSourceType(st); + setSourcePlayerId(sPID); + setSourceQuantity(sQtt); + setSourceName(sN); + setDestType(dt); + setDestPlayerId(dPID); + setDestQuantity(dQtt); + setDestName(dN); + } + + OnlineShopHistoryElement(int id, long t, String st, String sPID, double sQtt, String sN, String dt, String dPID, double dQtt, String dN) { + super("pandacube_onlineshop_history", id); + setTime(t); + setSourceType(SourceType.valueOf(st)); + sourcePlayerId = sPID; + setSourceQuantity(sQtt); + setSourceName(sN); + setDestType(DestType.valueOf(dt)); + destPlayerId = dPID; + setDestQuantity(dQtt); + setDestName(dN); + } + + @Override + protected String[] getValues() { + return new String[] { + Long.toString(time), + sourceType.name(), + sourcePlayerId, + Double.toString(sourceQuantity), + sourceName, + destType.name(), + destPlayerId, + Double.toString(destQuantity), + destName + + }; + } + + @Override + protected String[] getFieldsName() { + return new String[] { + "time", + "sourceType", + "sourcePlayerId", + "sourceQuantity", + "sourceName", + "destType", + "destPlayerId", + "destQuantity", + "destName" + }; + } + + + public long getTime() { return time; } + 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 setSourceType(SourceType st) { + if (st == null) throw new IllegalArgumentException("sourceType can't be null"); + sourceType = st; + } + public void setSourcePlayerId(UUID pId) { + if (pId == null) throw new IllegalArgumentException("sourcePlayerId can't be null"); + 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 + } + +} diff --git a/src/fr/pandacube/java/util/db/OnlineShopHistoryTable.java b/src/fr/pandacube/java/util/db/OnlineShopHistoryTable.java new file mode 100644 index 0000000..7e43b90 --- /dev/null +++ b/src/fr/pandacube/java/util/db/OnlineShopHistoryTable.java @@ -0,0 +1,43 @@ +package fr.pandacube.java.util.db; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class OnlineShopHistoryTable extends SQLTable { + + public OnlineShopHistoryTable() throws SQLException { + super("pandacube_onlineshop_history"); + } + + @Override + protected String createTableParameters() { + return "id INT AUTO_INCREMENT PRIMARY KEY," + + "time BIGINT NOT NULL," + + "sourceType ENUM('REAL_MONEY', 'BAMBOU') NOT NULL," + + "sourcePlayerId CHAR(36) NOT 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.getString("sourcePlayerId"), + sqlResult.getDouble("sourceQuantity"), + sqlResult.getString("sourceName"), + sqlResult.getString("destType"), + sqlResult.getString("destPlayerId"), + sqlResult.getDouble("destQuantity"), + sqlResult.getString("destName")); + + return el; + } + +} diff --git a/src/fr/pandacube/java/util/db/PlayerElement.java b/src/fr/pandacube/java/util/db/PlayerElement.java index df62fb9..8dd21f0 100644 --- a/src/fr/pandacube/java/util/db/PlayerElement.java +++ b/src/fr/pandacube/java/util/db/PlayerElement.java @@ -23,6 +23,8 @@ public class PlayerElement extends SQLElement { 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"); @@ -33,7 +35,7 @@ public class PlayerElement extends SQLElement { setFirstTimeInGame(firstTimeIG); } - protected PlayerElement(int id, String pId, String dispName, long firstTimeIG, long lastWebAct, String onlineInServer) { + PlayerElement(int id, String pId, String dispName, long firstTimeIG, long lastWebAct, String onlineInServer) { super("pandacube_player", id); setPlayerId(UUID.fromString(pId)); setOnlineInServer(onlineInServer); @@ -62,7 +64,9 @@ public class PlayerElement extends SQLElement { Integer.toString(lastYearCelebratedBirthday), (banTimeout!=null)?banTimeout.toString():null, (muteTimeout!=null)?muteTimeout.toString():null, - isWhitelisted?"1":"0" + isWhitelisted?"1":"0", + Long.toString(bambou), + grade }; } @@ -86,7 +90,9 @@ public class PlayerElement extends SQLElement { "lastYearCelebratedBirthday", "banTimeout", "muteTimeout", - "isWhitelisted" + "isWhitelisted", + "bambou", + "grade" }; } @@ -108,6 +114,8 @@ public class PlayerElement extends SQLElement { 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; } @@ -159,5 +167,13 @@ public class PlayerElement extends SQLElement { 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; + } } diff --git a/src/fr/pandacube/java/util/db/PlayerTable.java b/src/fr/pandacube/java/util/db/PlayerTable.java index 3f4cb6e..00712fc 100644 --- a/src/fr/pandacube/java/util/db/PlayerTable.java +++ b/src/fr/pandacube/java/util/db/PlayerTable.java @@ -30,7 +30,9 @@ public class PlayerTable extends SQLTable { + "lastYearCelebratedBirthday INT NOT NULL DEFAULT 0," + "banTimeout BIGINT NULL," + "muteTimeout BIGINT NULL," - + "isWhitelisted TINYINT NOT NULL DEFAULT 0"; + + "isWhitelisted TINYINT NOT NULL DEFAULT 0," + + "bambou BIGINT NOT NULL DEFAULT 0," + + "grade VARCHAR(36) NOT NULL DEFAULT 'default'"; } @Override @@ -55,6 +57,8 @@ public class PlayerTable extends SQLTable { 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;