public Collection<Artist> getAllArtists() throws DatabaseException {
Query query = new Query(Type.SELECT, "ARTISTS");
query.addField(new Field("ARTISTS.*"));
- return database.getMultiple(query, artistCreator);
+ return loadProperties(database.getMultiple(query, artistCreator));
}
/**
Query query = new Query(Type.SELECT, "ARTISTS");
query.addField(new Field("ARTISTS.*"));
query.addWhereClause(new ValueFieldWhereClause(new ValueField("ARTISTS.ID", new StringParameter(id))));
- return database.getSingle(query, artistCreator);
+ return loadProperties(database.getSingle(query, artistCreator));
}
/**
query.addField(new Field("ARTISTS.*"));
query.addJoin(new Join(JoinType.INNER, "GROUP_ARTISTS", new Field("ARTISTS.ID"), new Field("GROUP_ARTISTS.ARTIST")));
query.addWhereClause(new ValueFieldWhereClause(new ValueField("GROUP_ARTISTS.GROUP_", new StringParameter(groupId))));
- return database.getMultiple(query, artistCreator);
+ return loadProperties(database.getMultiple(query, artistCreator));
}
/**
query.addJoin(new Join(JoinType.INNER, "TRACK_ARTISTS", new Field("TRACK_ARTISTS.ARTIST"), new Field("ARTISTS.ID")));
query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_ARTISTS.TRACK", new StringParameter(trackId))));
query.addOrderField(new OrderField(new Field("TRACK_ARTISTS.DISPLAY_ORDER")));
- return database.getMultiple(query, artistCreator);
+ return loadProperties(database.getMultiple(query, artistCreator));
}
/**
query.addValueField(new ValueField("ID", new StringParameter(id)));
query.addValueField(new ValueField("NAME", new StringParameter(name)));
database.insert(query);
- return getArtistById(id);
+ return loadProperties(getArtistById(id));
}
/**
}
/**
+ * Loads the properties for an artist.
+ *
+ * @param artist
+ * The artist to load the properties for
+ * @return The artist
+ * @throws DatabaseException
+ * if a database error occurs
+ */
+ public Artist loadProperties(final Artist artist) throws DatabaseException {
+ Query query = new Query(Type.SELECT, "ARTIST_PROPERTIES");
+ query.addField(new Field("ARTIST_PROPERTIES.PROPERTY"));
+ query.addField(new Field("ARTIST_PROPERTIES.VALUE"));
+ query.addWhereClause(new ValueFieldWhereClause(new ValueField("ARTIST", new StringParameter(artist.getId()))));
+ database.process(query, new ResultProcessor() {
+
+ @Override
+ public void processResult(ResultSet resultSet) throws SQLException {
+ if (resultSet.isFirst()) {
+ artist.getProperties().removeAll();
+ }
+ artist.getProperties().set(resultSet.getString("ARTIST_PROPERTIES.PROPERTY"), resultSet.getString("ARTIST_PROPERTIES.VALUE"));
+ }
+
+ });
+ return artist;
+ }
+
+ /**
+ * Loads the properties of all given artists.
+ *
+ * @param artists
+ * The artists to load the properties for
+ * @return The list of artists
+ * @throws DatabaseException
+ * if a database error occurs
+ */
+ public List<Artist> loadProperties(List<Artist> artists) throws DatabaseException {
+ for (Artist artist : artists) {
+ loadProperties(artist);
+ }
+ return artists;
+ }
+
+ /**
* Returns all remix artists involved in the track with the given ID.
*
* @param trackId