package database;

import java.io.*;
import javax.servlet.*;


public class MusicDBServlet extends GenericServlet {

    private MusicstoreDB musics;

    public void init(ServletConfig config) throws ServletException {
        // Store the ServletConfig object and log the initialization
        super.init(config);

        // Load the database to prepare for requests
        musics = new MusicstoreDB();
    }

    public void destroy() {
        // Allow the database to be garbage collected
        musics = null;
    }

    public void service(ServletRequest req, ServletResponse res)
	throws ServletException, IOException {
            throw new UnavailableException(
                this,
                "This servlet does not accept client requests.");
    }

    public MusicDetails getMusicDetails(String musicId) {
        return musics.getMusicDetails(musicId);
    }

    public MusicDetails[] getMusicsSortedByTitle() {
        return musics.getMusicsSortedByTitle();
    }

    public int getNumberOfMusics() {
        return musics.getNumberOfMusics();
    }

    public String getServletInfo() {
        return "The MusicDB servlet manages the musicstore database.  " +
               "It is called by other servlets, not directly by a user.";
    }
}

