From 5fc0bbf713ccc5862e185ad47550dc2dcca2e7f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 26 Apr 2012 10:43:15 +0200 Subject: [PATCH] Add remix name and artists to track. --- .../demoscenemusic/data/DataManager.java | 42 +++++++++++++++++++++- .../demoscenemusic/data/DefaultTrack.java | 35 ++++++++++++++++++ .../pterodactylus/demoscenemusic/data/Track.java | 35 ++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index f3252f0..ac146e1 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -139,6 +139,24 @@ public class DataManager { } /** + * Returns all remix artists involved in the track with the given ID. + * + * @param trackId + * The ID of the track + * @return All remix artists involved in the track, in preferred order + * @throws DatabaseException + * if a database error occurs + */ + public List getRemixArtistsByTrack(String trackId) throws DatabaseException { + Query query = new Query(Type.SELECT, "ARTISTS"); + query.addField(new Field("ARTISTS.*")); + query.addJoin(new Join(JoinType.INNER, "TRACK_REMIX_ARTISTS", new Field("TRACK_REMIX_ARTISTS.ARTIST"), new Field("ARTISTS.ID"))); + query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_REMIX_ARTISTS.TRACK", new StringParameter(trackId)))); + query.addOrderField(new OrderField(new Field("TRACK_REMIX_ARTISTS.DISPLAY_ORDER"))); + return database.getMultiple(query, artistCreator); + } + + /** * Returns the track with the given ID. * * @param id @@ -392,6 +410,19 @@ public class DataManager { }); + /** Memoizer for the remix artists. */ + private final Memoizer remixArtistsMemoizer = new Memoizer(new Callable() { + + @Override + public Void call() throws Exception { + if (!hasValue("remixArtists")) { + getValue("remixArtists", List.class).set(getRemixArtistsByTrack(getId())); + } + return null; + } + + }); + /** * Creates a new track. * @@ -424,6 +455,15 @@ public class DataManager { return super.getStyles(); } + /** + * {@inheritDoc} + */ + @Override + public List getRemixArtists() { + remixArtistsMemoizer.get(); + return super.getRemixArtists(); + } + } /** @@ -440,7 +480,7 @@ public class DataManager { */ @Override public Track createObject(ResultSet resultSet) throws SQLException { - return new LazyTrack(resultSet.getString("TRACKS.ID")).setName(resultSet.getString("TRACKS.NAME")); + return new LazyTrack(resultSet.getString("TRACKS.ID")).setName(resultSet.getString("TRACKS.NAME")).setRemix(resultSet.getString("TRACKS.REMIX")); } } diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java index b357517..fafb8a2 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java @@ -94,4 +94,39 @@ public class DefaultTrack extends DefaultBase implements Track { return this; } + /** + * {@inheritDoc} + */ + @Override + public String getRemix() { + return getValue("remix", String.class).get(); + } + + /** + * {@inheritDoc} + */ + @Override + public Track setRemix(String remix) { + getValue("remix", String.class).set(remix); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("unchecked") + public List getRemixArtists() { + return getValue("remixArtists", List.class).get(); + } + + /** + * {@inheritDoc} + */ + @Override + public Track setRemixArtists(List remixArtists) { + getValue("remixArtists", List.class).set(remixArtists); + return this; + } + } diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java b/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java index 204cb77..a1362db 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java @@ -75,4 +75,39 @@ public interface Track extends Base { */ public Track setStyles(Collection styles); + /** + * Returns the name of this remix. If this track is not a remix, + * {@code null} is returned. + * + * @return The name of this remix, or {@code null} if this track is not a + * remix + */ + public String getRemix(); + + /** + * Sets the name of the remix. + * + * @param remix + * The name of this remix, or {@code null} if this track is not a + * remix + * @return This track + */ + public Track setRemix(String remix); + + /** + * Returns all remix artists involved in this track. + * + * @return All remix artists involved in this track + */ + public List getRemixArtists(); + + /** + * Sets all remix artists involved in this track. + * + * @param remixArtists + * All remix artists involved in this track + * @return This track + */ + public Track setRemixArtists(List remixArtists); + } -- 2.7.4