From: David ‘Bombe’ Roden Date: Fri, 27 Jul 2012 11:15:25 +0000 (+0200) Subject: Add method to load properties for arbitrary objects. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=1cc008977b7c075c415ec43b34870229260b2506;p=demoscenemusic.git Add method to load properties for arbitrary objects. --- diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index 7943401..5324d28 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -443,6 +443,44 @@ public class DataManager { return database.getMultiple(query, new StringCreator("USER_OPENIDS.OPENID")); } + // + // PRIVATE METHODS + // + + /** + * Loads the properties for the given object. + * + * @param + * The type of the object + * @param object + * The object + * @param table + * The table to load the properties from + * @param type + * The type of the object (“ARTIST,” “TRACK,” etc.) + * @return The object with its properties loaded + * @throws DatabaseException + * if a database error occurs + */ + private T loadProperties(final T object, final String table, String type) throws DatabaseException { + Query query = new Query(Type.SELECT, table); + query.addField(new Field(table + ".PROPERTY")); + query.addField(new Field(table + ".VALUE")); + query.addWhereClause(new ValueFieldWhereClause(new ValueField(type, new StringParameter(object.getId())))); + database.process(query, new ResultProcessor() { + + @Override + public void processResult(ResultSet resultSet) throws SQLException { + if (resultSet.isFirst()) { + object.getProperties().removeAll(); + } + object.getProperties().set(resultSet.getString(table + ".PROPERTY"), resultSet.getString(table + ".VALUE")); + } + + }); + return object; + } + /** * {@link Artist} implementation that retrieves some attributes (such as * {@link #getGroups()}, and {@link #getTracks()}) from the