Store party links when storing tracks.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 30 Jul 2012 12:57:31 +0000 (14:57 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 30 Jul 2012 12:57:31 +0000 (14:57 +0200)
src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java

index ea040bd..f5b071f 100644 (file)
@@ -457,6 +457,19 @@ public class DataManager {
                        query.addValueField(new ValueField("TRACK_ARTISTS.DISPLAY_ORDER", new IntegerParameter(index + 1)));
                        database.insert(query);
                }
+
+               /* store party links. */
+               Collection<Party> parties = track.getParties(); /* prefetch parties. */
+               query = new Query(Type.DELETE, "PARTY_TRACKS");
+               query.addWhereClause(new ValueFieldWhereClause(new ValueField("PARTY_TRACKS.TRACK", new StringParameter(track.getId()))));
+               database.update(query);
+               for (Party party : parties) {
+                       query = new Query(Type.INSERT, "PARTY_TRACKS");
+                       query.addValueField(new ValueField("PARTY_TRACKS.TRACK", new StringParameter(track.getId())));
+                       query.addValueField(new ValueField("PARTY_TRACKS.PARTY", new StringParameter(party.getId())));
+                       database.insert(query);
+               }
+
                /* store properties. */
                saveProperties(track.getProperties(), "TRACK_PROPERTIES", "TRACK", track.getId());
        }