Add javadoc.
[demoscenemusic.git] / src / main / java / net / pterodactylus / demoscenemusic / data / DataManager.java
index b2a3337..f3252f0 100644 (file)
@@ -38,33 +38,64 @@ import net.pterodactylus.util.database.ValueField;
 import net.pterodactylus.util.database.ValueFieldWhereClause;
 
 /**
- * TODO
+ * Interface between the database and the application.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public class DataManager {
 
+       /** The artist object creator. */
        @SuppressWarnings("synthetic-access")
        private final ObjectCreator<Artist> artistCreator = new ArtistCreator();
+
+       /** The group object creator. */
        @SuppressWarnings("synthetic-access")
        private final ObjectCreator<Group> groupCreator = new GroupCreator();
+
+       /** The track object creator. */
        @SuppressWarnings("synthetic-access")
        private final ObjectCreator<Track> trackCreator = new TrackCreator();
+
+       /** The style object creator. */
        @SuppressWarnings("synthetic-access")
        private final ObjectCreator<Style> styleCreator = new StyleCreator();
 
+       /** The database. */
        private final Database database;
 
+       /**
+        * Creates a new data manager.
+        *
+        * @param database
+        *            The database to operate on
+        */
        public DataManager(Database database) {
                this.database = database;
        }
 
+       /**
+        * Returns all artists.
+        *
+        * @return All artists
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
        public Collection<Artist> getAllArtists() throws DatabaseException {
                Query query = new Query(Type.SELECT, "ARTISTS");
                query.addField(new Field("ARTISTS.*"));
                return database.getMultiple(query, artistCreator);
        }
 
+       /**
+        * Returns the artist with the given ID.
+        *
+        * @param id
+        *            The ID of the artist
+        * @return The artist with the given ID, or {@code null} if there is no
+        *         artist with the given ID
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
        public Artist getArtistById(String id) throws DatabaseException {
                Query query = new Query(Type.SELECT, "ARTISTS");
                query.addField(new Field("ARTISTS.*"));
@@ -72,6 +103,15 @@ public class DataManager {
                return database.getSingle(query, artistCreator);
        }
 
+       /**
+        * Returns all artists that belong to the group with the given ID.
+        *
+        * @param groupId
+        *            The ID of the group
+        * @return All artists belonging to the given group
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
        public Collection<Artist> getArtistsByGroup(String groupId) throws DatabaseException {
                Query query = new Query(Type.SELECT, "ARTISTS");
                query.addField(new Field("ARTISTS.*"));
@@ -80,6 +120,15 @@ public class DataManager {
                return database.getMultiple(query, artistCreator);
        }
 
+       /**
+        * Returns all artists involved in the track with the given ID.
+        *
+        * @param trackId
+        *            The ID of the track
+        * @return All artists involved in the track, in preferred order
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
        public List<Artist> getArtistsByTrack(String trackId) throws DatabaseException {
                Query query = new Query(Type.SELECT, "ARTISTS");
                query.addField(new Field("ARTISTS.*"));
@@ -89,6 +138,16 @@ public class DataManager {
                return database.getMultiple(query, artistCreator);
        }
 
+       /**
+        * Returns the track with the given ID.
+        *
+        * @param id
+        *            The ID of the track
+        * @return The track with the given ID, or {@code null} if there is no such
+        *         track
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
        public Track getTrackById(String id) throws DatabaseException {
                Query query = new Query(Type.SELECT, "TRACKS");
                query.addField(new Field("TRACKS.*"));
@@ -96,6 +155,15 @@ public class DataManager {
                return database.getSingle(query, trackCreator);
        }
 
+       /**
+        * Returns all tracks by the artist with the given ID.
+        *
+        * @param artistId
+        *            The ID of the artist
+        * @return All tracks by the given artist
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
        public Collection<Track> getTracksByArtist(String artistId) throws DatabaseException {
                Query query = new Query(Type.SELECT, "TRACKS");
                query.addField(new Field("TRACKS.*"));
@@ -104,6 +172,15 @@ public class DataManager {
                return database.getMultiple(query, trackCreator);
        }
 
+       /**
+        * Returns all groups the artist with the given ID belongs to.
+        *
+        * @param artistId
+        *            The ID of the artist
+        * @return All groups the artist belongs to
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
        public Collection<Group> getGroupsByArtist(String artistId) throws DatabaseException {
                Query query = new Query(Type.SELECT, "GROUPS");
                query.addField(new Field("GROUPS.*"));
@@ -112,6 +189,15 @@ public class DataManager {
                return database.getMultiple(query, groupCreator);
        }
 
+       /**
+        * Returns all styles for the track with the given ID.
+        *
+        * @param trackId
+        *            The ID of the track
+        * @return All styles for the given track
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
        public Collection<Style> getStylesByTrack(String trackId) throws DatabaseException {
                Query query = new Query(Type.SELECT, "STYLES");
                query.addField(new Field("STYLES.*"));
@@ -120,8 +206,16 @@ public class DataManager {
                return database.getMultiple(query, styleCreator);
        }
 
+       /**
+        * {@link Artist} implementation that retrieves some attributes (such as
+        * {@link #getGroups()}, and {@link #getTracks()}) from the
+        * {@link DataManager} on demand.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
        private class LazyArtist extends DefaultArtist {
 
+               /** Memoizer for the tracks by this artist. */
                private final Memoizer<Void> tracksMemoizer = new Memoizer<Void>(new Callable<Void>() {
                        @Override
                        public Void call() throws DatabaseException {
@@ -132,6 +226,7 @@ public class DataManager {
                        }
                });
 
+               /** Memoizer for the groups of this artist. */
                private final Memoizer<Void> groupsMemoizer = new Memoizer<Void>(new Callable<Void>() {
 
                        @Override
@@ -144,10 +239,20 @@ public class DataManager {
 
                });
 
+               /**
+                * Creates a new lazy artist.
+                *
+                * @param id
+                *            The ID of the artist
+                */
                public LazyArtist(String id) {
                        super(id);
                }
 
+               //
+               // DEFAULTARTIST METHODS
+               //
+
                /**
                 * {@inheritDoc}
                 */
@@ -157,6 +262,9 @@ public class DataManager {
                        return super.getGroups();
                }
 
+               /**
+                * {@inheritDoc}
+                */
                @Override
                public Collection<Track> getTracks() {
                        tracksMemoizer.get();
@@ -165,6 +273,13 @@ public class DataManager {
 
        }
 
+       /**
+        * {@link ObjectCreator} implementation that can create {@link Artist}
+        * objects. This specific class actually creates {@link LazyArtist}
+        * instances.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
        private class ArtistCreator implements ObjectCreator<Artist> {
 
                /**
@@ -177,8 +292,15 @@ public class DataManager {
 
        }
 
+       /**
+        * {@link Group} implementation that retrieves some attributes (such as
+        * {@link #getArtists()}) from the {@link DataManager} on demand.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
        private class LazyGroup extends DefaultGroup {
 
+               /** Memoizer for the artist. */
                private final Memoizer<Void> artistsMemoizer = new Memoizer<Void>(new Callable<Void>() {
 
                        @Override
@@ -191,10 +313,20 @@ public class DataManager {
 
                });
 
+               /**
+                * Creates a new lazy group.
+                *
+                * @param id
+                *            The ID of the group
+                */
                public LazyGroup(String id) {
                        super(id);
                }
 
+               //
+               // DEFAULTGROUP METHODS
+               //
+
                /**
                 * {@inheritDoc}
                 */
@@ -206,6 +338,13 @@ public class DataManager {
 
        }
 
+       /**
+        * {@link ObjectCreator} implementation that can create {@link Group}
+        * objects. This specific implementation creates {@link LazyGroup}
+        * instances.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
        private class GroupCreator implements ObjectCreator<Group> {
 
                /**
@@ -218,8 +357,16 @@ public class DataManager {
 
        }
 
+       /**
+        * {@link Track} implementation that retrieves some attributes (such as
+        * {@link #getArtists()}, and {@link #getStyles()}) from the
+        * {@link DataManager} on demand.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
        private class LazyTrack extends DefaultTrack {
 
+               /** Memoizer for the artists. */
                private final Memoizer<Void> artistsMemoizer = new Memoizer<Void>(new Callable<Void>() {
 
                        @Override
@@ -232,6 +379,7 @@ public class DataManager {
 
                });
 
+               /** Memoizer for the styles. */
                private final Memoizer<Void> stylesMemoizer = new Memoizer<Void>(new Callable<Void>() {
 
                        @Override
@@ -245,12 +393,19 @@ public class DataManager {
                });
 
                /**
+                * Creates a new track.
+                *
                 * @param id
+                *            The ID of the track
                 */
                public LazyTrack(String id) {
                        super(id);
                }
 
+               //
+               // DEFAULTTRACK METHODS
+               //
+
                /**
                 * {@inheritDoc}
                 */
@@ -271,6 +426,13 @@ public class DataManager {
 
        }
 
+       /**
+        * {@link ObjectCreator} implementation that can create {@link Track}
+        * objects. This specific implementation creates {@link LazyTrack}
+        * instances.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
        private class TrackCreator implements ObjectCreator<Track> {
 
                /**
@@ -283,6 +445,12 @@ public class DataManager {
 
        }
 
+       /**
+        * {@link ObjectCreator} implementation that can create {@link Style}
+        * objects.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
        private class StyleCreator implements ObjectCreator<Style> {
 
                /**