From 1cc008977b7c075c415ec43b34870229260b2506 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 27 Jul 2012 13:15:25 +0200 Subject: [PATCH] Add method to load properties for arbitrary objects. --- .../demoscenemusic/data/DataManager.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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 -- 2.7.4