

package database;

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

public class ProductDBServlet extends GenericServlet {

    private ProductDB products;

    public void init(ServletConfig config) throws ServletException {
        super.init(config);

        // Load the database to prepare for requests
        products = new ProductDB();
    }

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

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

    public ProductDetails getProductDetails(String productId) {
        return products.getProductDetails(productId);
    }

    public ProductDetails[] getProductsSortedByName() {
        return products.getProductsSortedByName();
    }

    public int getNumberOfProducts() {
        return products.getNumProducts();
    }

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

/**
 * This is a simple example of a Generic Servlet.  Other servlets
 * call its public methods; it does not accept calls from clients.
 */
/*public class BookDBServlet extends GenericServlet {

    private BookstoreDB books;

    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
        books = new BookstoreDB();
    }

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

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

    public BookDetails getBookDetails(String bookId) {
        return books.getBookDetails(bookId);
    }

    public BookDetails[] getBooksSortedByTitle() {
        return books.getBooksSortedByTitle();
    }

    public int getNumberOfBooks() {
        return books.getNumberOfBooks();
    }

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




