import net.pterodactylus.util.database.ObjectCreator;
import net.pterodactylus.util.database.ObjectCreator.StringCreator;
import net.pterodactylus.util.database.OrderField;
+import net.pterodactylus.util.database.Parameter.IntegerParameter;
import net.pterodactylus.util.database.Parameter.StringParameter;
import net.pterodactylus.util.database.Query;
import net.pterodactylus.util.database.Query.Type;
}
/**
+ * Saves the given track. This also saves all relationships of the track.
+ *
+ * @param track
+ * The track to save
+ * @throws DatabaseException
+ * if a database error occurs
+ */
+ public void saveTrack(Track track) throws DatabaseException {
+ Query query = new Query(Type.UPDATE, "TRACKS");
+ query.addValueField(new ValueField("TRACKS.NAME", new StringParameter(track.getName())));
+ query.addValueField(new ValueField("TRACKS.REMIX", new StringParameter(track.getRemix())));
+ query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACKS.ID", new StringParameter(track.getId()))));
+ database.update(query);
+ /* store artist information. */
+ track.getArtists(); /* prefetch artists. */
+ query = new Query(Type.DELETE, "TRACK_ARTISTS");
+ query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_ARTISTS.TRACK", new StringParameter(track.getId()))));
+ database.update(query);
+ for (int index = 0; index < track.getArtists().size(); ++index) {
+ query = new Query(Type.INSERT, "TRACK_ARTISTS");
+ query.addValueField(new ValueField("TRACK_ARTISTS.TRACK", new StringParameter(track.getId())));
+ query.addValueField(new ValueField("TRACK_ARTISTS.ARTIST", new StringParameter(track.getArtists().get(index).getId())));
+ query.addValueField(new ValueField("TRACK_ARTISTS.DISPLAY_ORDER", new IntegerParameter(index + 1)));
+ database.insert(query);
+ }
+ /* store properties. */
+ saveProperties(track.getProperties(), "TRACK_PROPERTIES", "TRACK", track.getId());
+ }
+
+ /**
* Returns the derivative with the given ID.
*
* @param id
/** Memoizer for the tracks by this artist. */
private final Memoizer<Void> tracksMemoizer = new Memoizer<Void>(new Callable<Void>() {
+
@Override
public Void call() throws DatabaseException {
if (!hasValue("tracks")) {
}
return null;
}
+
});
/**