Ajout d'une table stockant les textures (skin et cape) des joueurs

This commit is contained in:
Marc Baloup 2016-08-18 15:17:36 +02:00
parent bb510ac57d
commit 0c1ac240f8
2 changed files with 62 additions and 0 deletions

View File

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

View File

@ -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<E extends SQLElement<E>> extends ArrayList<E> {
}
public <T, F extends SQLElement<F>> Map<T, F> getAllForeign(SQLFKField<E, T, F> foreignKey) throws ORMException {
Set<T> 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<F> foreignElemts = ORM.getAll(foreignKey.getForeignElementClass(), where, null, null, null);
Map<T, F> 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()));