}
/**
+ * 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<TrackDerivative> 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<TrackDerivative> loadTrackDerivativeProperties(List<TrackDerivative> trackDerivatives) throws DatabaseException {
+ for (TrackDerivative trackDerivative : trackDerivatives) {
+ loadTrackDerivativeProperties(trackDerivative);
+ }
+ return trackDerivatives;
+ }
+
+ /**
* Returns all groups the artist with the given ID belongs to.
*
* @param artistId
});
+ /** Memoizer for the track derivatives. */
+ private final Memoizer<Void> derivativesMemoizer = new Memoizer<Void>(new Callable<Void>() {
+
+ @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<Void> relatedTracksMemoizer = new Memoizer<Void>(new Callable<Void>() {
* {@inheritDoc}
*/
@Override
+ public Collection<TrackDerivative> getDerivatives() {
+ derivativesMemoizer.get();
+ return super.getDerivatives();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public Map<Relationship, Collection<Track>> getRelatedTracks() {
relatedTracksMemoizer.get();
return super.getRelatedTracks();
*/
@Override
@SuppressWarnings("unchecked")
+ public Collection<TrackDerivative> getDerivatives() {
+ return getValue("derivatives", Collection.class).get();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Track setDerivatives(Collection<TrackDerivative> derivatives) {
+ getValue("derivatives", Collection.class).set(derivatives);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ @SuppressWarnings("unchecked")
public Map<Relationship, Collection<Track>> getRelatedTracks() {
return getValue("relatedTracks", Map.class).get();
}
public Track setRemixArtists(List<Artist> 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<TrackDerivative> getDerivatives();
+
+ /**
+ * Sets the derivatives of this track.
+ *
+ * @param derivatives
+ * The derivatives of this track
+ * @return This track
+ */
+ public Track setDerivatives(Collection<TrackDerivative> derivatives);
+
+ /**
* Returns all tracks that are somehow related to this track.
*
* @return All tracks that are related to this track