Save groups when saving artist.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 31 Jul 2012 04:41:08 +0000 (06:41 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 31 Jul 2012 04:41:08 +0000 (06:41 +0200)
src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java

index f3d3578..8d331cb 100644 (file)
@@ -190,6 +190,20 @@ 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);
+
+               /* save groups. */
+               Collection<Group> groups = artist.getGroups();
+               query = new Query(Type.DELETE, "GROUP_ARTISTS");
+               query.addWhereClause(new ValueFieldWhereClause(new ValueField("GROUP_ARTISTS.ARTIST", new StringParameter(artist.getId()))));
+               database.update(query);
+               for (Group group : groups) {
+                       query = new Query(Type.INSERT, "GROUP_ARTISTS");
+                       query.addValueField(new ValueField("GROUP_", new StringParameter(group.getId())));
+                       query.addValueField(new ValueField("ARTIST", new StringParameter(artist.getId())));
+                       database.insert(query);
+               }
+
+               /* save properties. */
                saveArtistProperties(artist);
        }