From: David ‘Bombe’ Roden Date: Fri, 27 Jul 2012 11:29:36 +0000 (+0200) Subject: Add track derivatives to tracks. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=5580bfd42efd17a09314e551f9166e27bfbd329e;p=demoscenemusic.git Add track derivatives to tracks. --- diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index 7744116..449965b 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -345,6 +345,51 @@ public class DataManager { } /** + * Returns the derivatives for the given track. + * + * @param track + * The track to get the derivatives for + * @return The derivatives for the given track + * @throws DatabaseException + * if a database error occurs + */ + public Collection getTrackDerivativesByTrack(Track track) throws DatabaseException { + Query query = new Query(Type.SELECT, "TRACK_DERIVATIVES"); + query.addField(new Field("TRACK_DERIVATIVES.*")); + query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_DERIVATIVES.TRACK", new StringParameter(track.getId())))); + return loadTrackDerivativeProperties(database.getMultiple(query, trackDerivativeCreator)); + } + + /** + * Loads the properties for the given track derivative. + * + * @param trackDerivative + * The track derivative to load the properties for + * @return The track derivative with its properties loaded + * @throws DatabaseException + * if a database error occurs + */ + public TrackDerivative loadTrackDerivativeProperties(TrackDerivative trackDerivative) throws DatabaseException { + return loadProperties(trackDerivative, "TRACK_DERIVATIVE_PROPERTIES", "TRACK_DERIVATIVE"); + } + + /** + * Loads the properties for the given track derivatives. + * + * @param trackDerivatives + * The track derivatives to load the properties for + * @return The track derivatives with their properties loaded + * @throws DatabaseException + * if a database error occurs + */ + public List loadTrackDerivativeProperties(List trackDerivatives) throws DatabaseException { + for (TrackDerivative trackDerivative : trackDerivatives) { + loadTrackDerivativeProperties(trackDerivative); + } + return trackDerivatives; + } + + /** * Returns all groups the artist with the given ID belongs to. * * @param artistId @@ -665,6 +710,19 @@ public class DataManager { }); + /** Memoizer for the track derivatives. */ + private final Memoizer derivativesMemoizer = new Memoizer(new Callable() { + + @Override + public Void call() throws Exception { + if (!hasValue("derivatives")) { + getValue("derivatives", Collection.class).set(getTrackDerivativesByTrack(LazyTrack.this)); + } + return null; + } + + }); + /** Memoizer for the related tracks. */ private final Memoizer relatedTracksMemoizer = new Memoizer(new Callable() { @@ -722,6 +780,15 @@ public class DataManager { * {@inheritDoc} */ @Override + public Collection getDerivatives() { + derivativesMemoizer.get(); + return super.getDerivatives(); + } + + /** + * {@inheritDoc} + */ + @Override public Map> getRelatedTracks() { relatedTracksMemoizer.get(); return super.getRelatedTracks(); diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java index 9901fcb..804d710 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java @@ -135,6 +135,24 @@ public class DefaultTrack extends DefaultBase implements Track { */ @Override @SuppressWarnings("unchecked") + public Collection getDerivatives() { + return getValue("derivatives", Collection.class).get(); + } + + /** + * {@inheritDoc} + */ + @Override + public Track setDerivatives(Collection derivatives) { + getValue("derivatives", Collection.class).set(derivatives); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("unchecked") public Map> getRelatedTracks() { return getValue("relatedTracks", Map.class).get(); } diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java b/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java index 32ae937..332132a 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java @@ -130,6 +130,23 @@ public interface Track extends Base { public Track setRemixArtists(List remixArtists); /** + * Returns all derivatives of this track. A derivative of a MOD file could + * be a WAV or MP3 file. + * + * @return All derivatives of this track + */ + public Collection getDerivatives(); + + /** + * Sets the derivatives of this track. + * + * @param derivatives + * The derivatives of this track + * @return This track + */ + public Track setDerivatives(Collection derivatives); + + /** * Returns all tracks that are somehow related to this track. * * @return All tracks that are related to this track