From 747a5afddade17479a3d0e951c1e5ce51a3b7950 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 29 Jul 2012 01:36:04 +0200 Subject: [PATCH] Add method to get a track by a derivative ID. --- .../pterodactylus/demoscenemusic/data/DataManager.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index c0001c4..967faa5 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -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 -- 2.7.4