From: David ‘Bombe’ Roden Date: Mon, 30 Jul 2012 11:46:06 +0000 (+0200) Subject: Get parties a track was released at from the track. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=1e2c5a3d82db1f6c93adddd79b77278222979eca;p=demoscenemusic.git Get parties a track was released at from the track. --- diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index bcfbb18..ea040bd 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -618,6 +618,23 @@ public class DataManager { } /** + * Returns all parties that the track with the given ID was released at. + * + * @param trackId + * The ID of the track + * @return All parties the track was released at + * @throws DatabaseException + * if a database error occurs + */ + public Collection getPartiesByTrackId(String trackId) throws DatabaseException { + Query query = new Query(Type.SELECT, "PARTIES"); + query.addField(new Field("PARTIES.*")); + query.addJoin(new Join(JoinType.INNER, "PARTY_TRACKS", new Field("PARTY_TRACKS.PARTY"), new Field("PARTIES.ID"))); + query.addWhereClause(new ValueFieldWhereClause(new ValueField("PARTY_TRACKS.TRACK", new StringParameter(trackId)))); + return loadPartyProperties(database.getMultiple(query, partyCreator)); + } + + /** * Returns the party with the given ID. * * @param partyId @@ -1081,6 +1098,21 @@ public class DataManager { return super.getRelatedTracks(); } + /** + * {@inheritDoc} + */ + @Override + public Collection getParties() { + if (!hasValue("parties")) { + try { + getValue("parties", Collection.class).set(getPartiesByTrackId(getId())); + } catch (DatabaseException de1) { + throw new RuntimeException("Could not load Parties for Track " + getId() + ".", de1); + } + } + return super.getParties(); + } + } /** diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java index 804d710..ffeb003 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultTrack.java @@ -166,4 +166,22 @@ public class DefaultTrack extends DefaultBase implements Track { return this; } + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("unchecked") + public Collection getParties() { + return getValue("parties", Collection.class).get(); + } + + /** + * {@inheritDoc} + */ + @Override + public Track setParties(Collection parties) { + getValue("parties", Collection.class).set(parties); + 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 332132a..cb9249f 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/Track.java @@ -162,4 +162,20 @@ public interface Track extends Base { */ public Track setRelatedTracks(Map> relatedTracks); + /** + * Returns all parties this track was released at. + * + * @return All parties this track was released at + */ + public Collection getParties(); + + /** + * Sets all parties this track was released at. + * + * @param parties + * All parties this track was released at + * @return This track + */ + public Track setParties(Collection parties); + }