CS636 Pizza1's DAO API, plus sample methods

DAO methods:

topcat$ grep public *DAO.java

      
AdminDAO.java:public class AdminDAO {
AdminDAO.java:  public AdminDAO(DbDAO db) throws SQLException {
AdminDAO.java:  public void advanceDay() throws SQLException
AdminDAO.java:  public int findCurrentDay() throws SQLException
DbDAO.java:public class DbDAO {
DbDAO.java:     public DbDAO(String dbUrl, String usr, String passwd) throws SQLException {
DbDAO.java:     public void close() throws SQLException {
DbDAO.java:     public void initializeDb() throws SQLException {
MenuDAO.java:public class MenuDAO {
MenuDAO.java:   public MenuDAO(DbDAO db) throws SQLException {
MenuDAO.java:   public MenuSize findMenuSize(String name) throws SQLException
MenuDAO.java:   public Set<MenuSize> findMenuSizes() throws SQLException
MenuDAO.java:   public MenuTopping findMenuTopping(String name) throws SQLException
MenuDAO.java:   public Set<MenuTopping> findMenuToppings() throws SQLException {
MenuDAO.java:   public void createMenuTopping(String toppingName) throws SQLException {
MenuDAO.java:   public void createMenuSize(String sizeName) throws SQLException {
MenuDAO.java:   public void deleteMenuTopping(String topping) throws SQLException
MenuDAO.java:   public void deleteMenuSize(String size) throws SQLException
PizzaOrderDAO.java:public class PizzaOrderDAO {
PizzaOrderDAO.java:     public PizzaOrderDAO(DbDAO db) throws SQLException {
PizzaOrderDAO.java:     public void insertOrder(PizzaOrder order) throws SQLException {
PizzaOrderDAO.java:     public List<PizzaOrder> findOrdersByRoom(int roomNumber, int day) throws SQLException
PizzaOrderDAO.java:     public int findFirstOrder(int status) throws SQLException
PizzaOrderDAO.java:     public void updateOrderStatus(int ordNo, int newStatus) throws SQLException
PizzaOrderDAO.java:     public List<PizzaOrder> findOrdersByDays(int day1, int day2) throws SQLException {

These throw SQLException on errors, but they first carefully close the statement in a finally clause.
They use a private connection object set up at the program start for reuse--typical client-server use of longer-lived connection.

Sample DAO method:

   // find all active toppings
   public Set<MenuTopping> findMenuToppings() throws SQLException {
      Set<MenuTopping> toppings = new TreeSet<MenuTopping>();

      Statement stmt = connection.createStatement();
      try {
            ResultSet set = stmt.executeQuery("select * from " + MENU_TOPPING_TABLE);
            while (set.next())
              toppings.add(new MenuTopping(set.getInt("id"), set.getString("topping_name")));
      } finally {
            stmt.close();
      }
      return toppings;
   }

Another DAO method, from AdminDAO.java:

   
   public void advanceDay() throws SQLException
   {
       Statement stmt = connection.createStatement();
       try {
           stmt.executeUpdate("update " + SYS_TABLE
                               + " set current_day = current_day + 1 ");
       } finally {
           stmt.close();
       }
   } 

Note no transactions yet, and this one pretty much passes the buck to the DAO.