import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
import java.util.concurrent.Callable;
import net.pterodactylus.util.database.Join.JoinType;
import net.pterodactylus.util.database.ObjectCreator;
import net.pterodactylus.util.database.OrderField;
-import net.pterodactylus.util.database.OrderField.Order;
import net.pterodactylus.util.database.Parameter.StringParameter;
import net.pterodactylus.util.database.Query;
import net.pterodactylus.util.database.Query.Type;
-import net.pterodactylus.util.database.ResultProcessor;
import net.pterodactylus.util.database.ValueField;
import net.pterodactylus.util.database.ValueFieldWhereClause;
return database.getMultiple(query, groupCreator);
}
- private class TrackLoader implements ResultProcessor {
-
- private final List<Track> loadedTracks = new ArrayList<Track>();
- private Track track;
-
- public Track get() {
- return loadedTracks.isEmpty() ? null : loadedTracks.get(0);
- }
-
- public List<Track> all() {
- return loadedTracks;
- }
-
- /**
- * {@inheritDoc}
- */
- public void processResult(ResultSet resultSet) throws SQLException {
- String trackId = resultSet.getString("TRACKS.ID");
- if ((track == null) || (!track.id().equals(trackId))) {
- track = new DefaultTrack(trackId).name(resultSet.getString("TRACKS.NAME")).artists(new ArrayList<Artist>()).styles(new HashSet<Style>());
- loadedTracks.add(track);
- }
- Artist artist = new LazyArtist(resultSet.getString("ARTISTS.ID")).name(resultSet.getString("ARTISTS.NAME"));
- if (!track.artists().contains(artist)) {
- track.artists().add(artist);
- }
- Style style = new DefaultStyle(resultSet.getString("STYLES.ID")).name(resultSet.getString("STYLES.NAME"));
- track.styles().add(style);
- }
-
- }
-
- private class ArtistLoader implements ResultProcessor {
-
- private final List<Artist> artists = new ArrayList<Artist>();
- private Artist artist;
-
- public Artist get() {
- return artists.isEmpty() ? null : artists.get(0);
- }
-
- public List<Artist> 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 LazyArtist(artistId).name(resultSet.getString("ARTISTS.NAME")).groups(new HashSet<Group>());
- artists.add(artist);
- }
-
- Group group = new DefaultGroup(resultSet.getString("GROUPS.ID")).name(resultSet.getString("GROUPS.NAME")).url(resultSet.getString("GROUPS.URL"));
- artist.groups().add(group);
- }
-
- }
-
private class LazyArtist extends DefaultArtist {
private final Memoizer<Void> tracksMemoizer = new Memoizer<Void>(new Callable<Void>() {