Add remix name and artists to track.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 26 Apr 2012 08:43:15 +0000 (10:43 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 26 Apr 2012 08:43:15 +0000 (10:43 +0200)
src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java
src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java
src/main/java/net/pterodactylus/demoscenemusic/data/Track.java

index f3252f0..ac146e1 100644 (file)
@@ -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<Artist> 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<Void> remixArtistsMemoizer = new Memoizer<Void>(new Callable<Void>() {
+
+                       @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<Artist> 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"));
                }
 
        }
index b357517..fafb8a2 100644 (file)
@@ -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<Artist> getRemixArtists() {
+               return getValue("remixArtists", List.class).get();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public Track setRemixArtists(List<Artist> remixArtists) {
+               getValue("remixArtists", List.class).set(remixArtists);
+               return this;
+       }
+
 }
index 204cb77..a1362db 100644 (file)
@@ -75,4 +75,39 @@ public interface Track extends Base {
         */
        public Track setStyles(Collection<? extends Style> 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<Artist> 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<Artist> remixArtists);
+
 }