From: David ‘Bombe’ Roden Date: Wed, 18 Apr 2012 21:39:47 +0000 (+0200) Subject: Add method to load all artists. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=c9117016826126bebbac9f4bee9fa9a3839b87c7;p=demoscenemusic.git Add method to load all artists. --- diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index a99b13d..ba2f61e 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -20,6 +20,7 @@ package net.pterodactylus.demoscenemusic.data; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -50,6 +51,19 @@ public class DataManager { this.database = database; } + public Collection getAllArtists() throws DatabaseException { + Query query = new Query(Type.SELECT, "ARTISTS"); + query.addField(new Field("ARTISTS.*")); + query.addField(new Field("GROUP_ARTISTS.*")); + query.addField(new Field("GROUPS.*")); + query.addJoin(new Join(JoinType.INNER, "GROUP_ARTISTS", new Field("ARTISTS.ID"), new Field("GROUP_ARTISTS.ARTIST"))); + query.addJoin(new Join(JoinType.INNER, "GROUPS", new Field("GROUP_ARTISTS.GROUP_"), new Field("GROUPS.ID"))); + query.addOrderField(new OrderField(new Field("ARTISTS.ID"))); + ArtistLoader artistLoader = new ArtistLoader(); + database.process(query, artistLoader); + return artistLoader.all(); + } + public Track trackById(String id) throws DatabaseException { Query query = new Query(Type.SELECT, "TRACKS"); query.addField(new Field("TRACKS.*")); @@ -114,4 +128,43 @@ public class DataManager { } + private class ArtistLoader implements ResultProcessor { + + private final List artists = new ArrayList(); + private Artist artist; + + public List all() { + return artists; + } + + // + // RESULTPROCESSOR METHODS + // + + /** + * {@inheritDoc} + */ + public void processResult(ResultSet resultSet) throws SQLException { + String artistId = resultSet.getString("ARTISTS.ID"); + if ((artist == null) || (!artist.id().equals(artistId))) { + artist = new AbstractArtist(artistId) { + + public void save() { + } + + }.name(resultSet.getString("ARTISTS.NAME")).groups(new HashSet()); + artists.add(artist); + } + + Group group = new AbstractGroup(resultSet.getString("GROUPS.ID")) { + + public void save() { + } + + }.name(resultSet.getString("GROUPS.NAME")).url(resultSet.getString("GROUPS.URL")); + artist.groups().add(group); + } + + } + } diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp deleted file mode 100644 index 9dff832..0000000 --- a/src/main/webapp/index.jsp +++ /dev/null @@ -1,7 +0,0 @@ - - - - -

Demoscene Music

- -