import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.Callable;
query.addValueField(new ValueField("NAME", new StringParameter(artist.getName())));
query.addWhereClause(new ValueFieldWhereClause(new ValueField("ID", new StringParameter(artist.getId()))));
database.update(query);
+ saveArtistProperties(artist);
+ }
+
+ /**
+ * Saves the properties of the given artist.
+ *
+ * @param artist
+ * The artist whose properties to save
+ * @throws DatabaseException
+ * if a database error occurs
+ */
+ public void saveArtistProperties(Artist artist) throws DatabaseException {
+ saveProperties(artist.getProperties(), "ARTIST_PROPERTIES", "ARTIST", artist.getId());
+ }
+
+ /**
+ * Saves the given properties to the given table for the given principal.
+ *
+ * @param properties
+ * The properties to save
+ * @param table
+ * The table in which to save the properties
+ * @param type
+ * The type of the principal (e. g. “ARTIST” or “TRACK”)
+ * @param id
+ * The ID of the principial
+ * @throws DatabaseException
+ * if a database error occurs
+ */
+ public void saveProperties(Properties properties, String table, String type, String id) throws DatabaseException {
+ if (!properties.isDirty()) {
+ return;
+ }
+ Query query = new Query(Type.DELETE, table);
+ query.addWhereClause(new ValueFieldWhereClause(new ValueField(type, new StringParameter(id))));
+ database.update(query);
+ for (Entry<String, String> property : properties) {
+ Query insertQuery = new Query(Type.INSERT, table);
+ insertQuery.addValueField(new ValueField(type, new StringParameter(id)));
+ insertQuery.addValueField(new ValueField("PROPERTY", new StringParameter(property.getKey())));
+ insertQuery.addValueField(new ValueField("VALUE", new StringParameter(property.getValue())));
+ database.insert(insertQuery);
+ }
+ properties.resetDirty();
}
/**