Add method to create an artist.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 26 Jul 2012 05:25:48 +0000 (07:25 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 26 Jul 2012 05:28:49 +0000 (07:28 +0200)
src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java

index 60b8318..a6f5a54 100644 (file)
@@ -24,6 +24,7 @@ import java.util.EnumMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 import java.util.concurrent.Callable;
 
 import net.pterodactylus.demoscenemusic.data.Track.Relationship;
@@ -149,6 +150,24 @@ public class DataManager {
        }
 
        /**
+        * Creates a new artist with the given name.
+        *
+        * @param name
+        *            The name of the artist
+        * @return The created artist
+        * @throws DatabaseException
+        *             if a database error occurs
+        */
+       public Artist createArtist(String name) throws DatabaseException {
+               Query query = new Query(Type.INSERT, "ARTISTS");
+               String id = UUID.randomUUID().toString();
+               query.addValueField(new ValueField("ID", new StringParameter(id)));
+               query.addValueField(new ValueField("NAME", new StringParameter(name)));
+               database.insert(query);
+               return getArtistById(id);
+       }
+
+       /**
         * Returns all remix artists involved in the track with the given ID.
         *
         * @param trackId