X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fdemoscenemusic%2Fdata%2FDataManager.java;h=373f80c2fb1b32a61c4d572f5195d798e5067cd2;hb=6044000b16b448b4f1f6df4dd9b101ceed2397ac;hp=8348b2f7afef1f338633253793d9bb85205cd0c0;hpb=e19732e4343d5a75a6539d6cf2fda897a2889f91;p=demoscenemusic.git diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index 8348b2f..373f80c 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -24,6 +24,7 @@ import java.util.EnumMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.Callable; @@ -180,6 +181,50 @@ public class DataManager { query.addValueField(new ValueField("NAME", new StringParameter(artist.getName()))); query.addWhereClause(new ValueFieldWhereClause(new ValueField("ID", new StringParameter(artist.getId())))); database.update(query); + saveArtistProperties(artist); + } + + /** + * Saves the properties of the given artist. + * + * @param artist + * The artist whose properties to save + * @throws DatabaseException + * if a database error occurs + */ + public void saveArtistProperties(Artist artist) throws DatabaseException { + saveProperties(artist.getProperties(), "ARTIST_PROPERTIES", "ARTIST", artist.getId()); + } + + /** + * Saves the given properties to the given table for the given principal. + * + * @param properties + * The properties to save + * @param table + * The table in which to save the properties + * @param type + * The type of the principal (e. g. “ARTIST” or “TRACK”) + * @param id + * The ID of the principial + * @throws DatabaseException + * if a database error occurs + */ + public void saveProperties(Properties properties, String table, String type, String id) throws DatabaseException { + if (!properties.isDirty()) { + return; + } + Query query = new Query(Type.DELETE, table); + query.addWhereClause(new ValueFieldWhereClause(new ValueField(type, new StringParameter(id)))); + database.update(query); + for (Entry property : properties) { + Query insertQuery = new Query(Type.INSERT, table); + insertQuery.addValueField(new ValueField(type, new StringParameter(id))); + insertQuery.addValueField(new ValueField("PROPERTY", new StringParameter(property.getKey()))); + insertQuery.addValueField(new ValueField("VALUE", new StringParameter(property.getValue()))); + database.insert(insertQuery); + } + properties.resetDirty(); } /**