From 1c09a66fc0aef0cf83432f11408e8d8ca2e11632 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 19 Apr 2012 15:03:51 +0200 Subject: [PATCH] Add method to get all tracks for an artist. --- .../demoscenemusic/data/DataManager.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index 520a3d9..23159df 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -97,11 +97,34 @@ public class DataManager { return trackLoader.get(); } + public Collection getTracksByArtist(String artistId) throws DatabaseException { + Query query = new Query(Type.SELECT, "TRACKS"); + query.addField(new Field("TRACKS.*")); + query.addField(new Field("TRACK_ARTISTS.*")); + query.addField(new Field("ARTISTS.*")); + query.addField(new Field("TRACK_STYLES.*")); + query.addField(new Field("STYLES.*")); + query.addJoin(new Join(JoinType.INNER, "TRACK_ARTISTS", new Field("TRACKS.ID"), new Field("TRACK_ARTISTS.TRACK"))); + query.addJoin(new Join(JoinType.INNER, "ARTISTS", new Field("TRACK_ARTISTS.ARTIST"), new Field("ARTISTS.ID"))); + query.addJoin(new Join(JoinType.INNER, "TRACK_STYLES", new Field("TRACKS.ID"), new Field("TRACK_STYLES.TRACK"))); + query.addJoin(new Join(JoinType.INNER, "STYLES", new Field("TRACK_STYLES.STYLE"), new Field("STYLES.ID"))); + query.addWhereClause(new ValueFieldWhereClause(new ValueField("ARTISTS.ID", new StringParameter(artistId)))); + query.addOrderField(new OrderField(new Field("TRACKS.ID"), Order.ASCENDING)); + query.addOrderField(new OrderField(new Field("TRACK_ARTISTS.DISPLAY_ORDER"), Order.ASCENDING)); + TrackLoader trackLoader = new TrackLoader(); + database.process(query, trackLoader); + return trackLoader.all(); + } + private class TrackLoader implements ResultProcessor { private final List loadedTracks = new ArrayList(); private Track track; + public List all() { + return loadedTracks; + } + /** * {@inheritDoc} */ -- 2.7.4