From 0c1ac240f837df1f4173532de2c06eede70e9af7 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 18 Aug 2016 15:17:36 +0200 Subject: [PATCH] Ajout d'une table stockant les textures (skin et cape) des joueurs --- .../java/util/db/SQLPlayerTexture.java | 29 ++++++++++++++++ .../util/db/sql_tools/SQLElementList.java | 33 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/fr/pandacube/java/util/db/SQLPlayerTexture.java diff --git a/src/fr/pandacube/java/util/db/SQLPlayerTexture.java b/src/fr/pandacube/java/util/db/SQLPlayerTexture.java new file mode 100644 index 0000000..8f6ef04 --- /dev/null +++ b/src/fr/pandacube/java/util/db/SQLPlayerTexture.java @@ -0,0 +1,29 @@ +package fr.pandacube.java.util.db; + +import fr.pandacube.java.util.db.sql_tools.SQLElement; +import fr.pandacube.java.util.db.sql_tools.SQLFKField; +import fr.pandacube.java.util.db.sql_tools.SQLField; +import fr.pandacube.java.util.db.sql_tools.SQLType; + +public class SQLPlayerTexture extends SQLElement { + + public SQLPlayerTexture() { + super(); + } + + public SQLPlayerTexture(int id) { + super(id); + } + + @Override + protected String tableName() { + return "pandacube_player_texture"; + } + + public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, + SQLPlayer.class, SQLPlayer.playerId); + public static final SQLField alias = new SQLField<>("alias", SQLType.VARCHAR(64), false); + public static final SQLField textureData = new SQLField<>("textureData", SQLType.TEXT, false); + public static final SQLField textureSignature = new SQLField<>("textureSignature", SQLType.VARCHAR(8192), false); + +} diff --git a/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java b/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java index 8ab57cb..e082cfe 100644 --- a/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java @@ -3,13 +3,18 @@ package fr.pandacube.java.util.db.sql_tools; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import com.google.gson.JsonArray; import fr.pandacube.java.util.Log; +import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; +import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; /** * @@ -166,6 +171,34 @@ public class SQLElementList> extends ArrayList { } + + public > Map getAllForeign(SQLFKField foreignKey) throws ORMException { + Set values = new HashSet<>(); + forEach(v -> { + T val = v.get(foreignKey); + if (val != null) + values.add(val); + }); + + if (values.isEmpty()) { + return new HashMap<>(); + } + + SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR); + values.forEach(v -> where.add(new SQLWhereComp(foreignKey.getForeignField(), SQLComparator.EQ, v))); + + + SQLElementList foreignElemts = ORM.getAll(foreignKey.getForeignElementClass(), where, null, null, null); + + Map ret = new HashMap<>(); + foreignElemts.forEach(foreignVal -> ret.put(foreignVal.get(foreignKey.getForeignField()), foreignVal)); + return ret; + } + + + + + public JsonArray asJsonArray() { JsonArray json = new JsonArray(); forEach(el -> json.add(el.asJsonObject()));