Add method to get a track by a derivative ID.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 28 Jul 2012 23:36:04 +0000 (01:36 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 28 Jul 2012 23:36:04 +0000 (01:36 +0200)
src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java

index c0001c4..967faa5 100644 (file)
@@ -329,6 +329,24 @@ public class DataManager {
        }
 
        /**
+        * Returns the track that contains the derivative with the given ID.
+        *
+        * @param id
+        *            The ID of the track derivative
+        * @return The track the derivative belongs to, or {@code null} if there is
+        *         no such track
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
+       public Track getTrackByDerivativeId(String id) throws DatabaseException {
+               Query query = new Query(Type.SELECT, "TRACKS");
+               query.addField(new Field("TRACKS.*"));
+               query.addJoin(new Join(JoinType.INNER, "TRACK_DERIVATIVES", new Field("TRACK_DERIVATIVES.TRACK"), new Field("TRACKS.ID")));
+               query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_DERIVATIVES.ID", new StringParameter(id))));
+               return loadTrackProperties(database.getSingle(query, trackCreator));
+       }
+
+       /**
         * Returns all tracks by the artist with the given ID.
         *
         * @param artistId