/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.menu;

import java.sql.*;
import com.silverwrist.util.*;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;

public class MenuDatabaseOps_mysql extends MenuDatabaseOps
{
  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  public MenuDatabaseOps_mysql(DBConnectionPool pool)
  {
    super(pool);

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Abstract implementations from class MenuDatabaseOps
   *--------------------------------------------------------------------------------
   */

  MenuDefinition getMenu(String namespace, String name) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try
    { // get a connection
      conn = getConnection();

      // create the statement to retrieve the base data
      stmt = conn.prepareStatement("SELECT m.menuid, m.title, m.subtitle FROM menus m, namespaces n "
				   + "WHERE m.menu_nsid = n.nsid AND n.namespace = ? AND m.menu_name = ?;");
      stmt.setString(1,namespace);
      stmt.setString(2,name);
      rs = stmt.executeQuery();
      if (!(rs.next()))
	return null;  // not found

      // get the ID and create the initial menu definition
      int id = rs.getInt(1);
      MenuDefinition def = new MenuDefinition(id,namespace,name,rs.getString(2),rs.getString(3));

      // shut down things for the next operation
      SQLUtils.shutdown(rs);
      rs = null;
      SQLUtils.shutdown(stmt);

      // get the variable definitions
      stmt = conn.prepareStatement("SELECT var_name, default_val FROM menuvars WHERE menuid = ?;");
      stmt.setInt(1,id);
      rs = stmt.executeQuery();
      while (rs.next())
	def.addVariableDef(rs.getString(1),rs.getString(2));

      // shut down things for the next operation
      SQLUtils.shutdown(rs);
      rs = null;
      SQLUtils.shutdown(stmt);

      // get the menu items
      stmt = conn.prepareStatement("SELECT itemtype, sequence, enable, indent, text, linktype, link, target, title, "
				   + "on_click, perm_nsid, perm_name, ifdef_var, ifndef_var FROM menuitems "
				   + "WHERE menuid = ? ORDER BY sequence;");
      stmt.setInt(1,id);
      rs = stmt.executeQuery();
      while (rs.next())
      { // get the namespace and add the item definition
	int nsid = rs.getInt(11);
	String ns = (rs.wasNull() ? null : namespaceIdToName(nsid));
	MenuItemDefinition item = new MenuItemDefinition(rs.getString(1),rs.getInt(2),(rs.getInt(3)!=0),rs.getInt(4),
							 rs.getString(5),rs.getString(6),rs.getString(7),
							 rs.getString(8),rs.getString(9),rs.getString(10),ns,
							 rs.getString(12),rs.getString(13),rs.getString(14));
	def.addItemDef(item);

      } // end while

      return def;

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      SQLUtils.shutdown(rs);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end getMenu

  void setMenuTitle(int id, String title) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menus WRITE;");

      // create and execute the proper statement
      stmt = conn.prepareStatement("UPDATE menus SET title = ? WHERE menuid = ?;");
      stmt.setString(1,title);
      stmt.setInt(2,id);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setMenuTitle

  void setMenuSubtitle(int id, String subtitle) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menus WRITE;");

      // create and execute the proper statement
      stmt = conn.prepareStatement("UPDATE menus SET subtitle = ? WHERE menuid = ?;");
      stmt.setString(1,subtitle);
      stmt.setInt(2,id);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setMenuSubtitle

  void setDefaultVal(int id, String variable, String value) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuvars WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuvars SET default_val = ? WHERE menuid = ? AND var_name = ?;");
      stmt.setString(1,value);
      stmt.setInt(2,id);
      stmt.setString(3,variable);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setDefaultVal

  void addVariable(int id, String variable, String value) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuvars WRITE;");

      // create and execute the appropriate statement
      stmt = conn.prepareStatement("INSERT INTO menuvars (menuid, var_name, default_val) VALUES (?, ?, ?);");
      stmt.setInt(1,id);
      stmt.setString(2,variable);
      stmt.setString(3,value);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end addVariable

  void removeVariable(int id, String variable) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuvars WRITE;");

      // create and execute the appropriate statement
      stmt = conn.prepareStatement("DELETE FROM menuvars WHERE menuid = ? AND var_name = ?;");
      stmt.setInt(1,id);
      stmt.setString(2,variable);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end removeVariable

  void setItemSequence(int id, int old_seq, int new_seq) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET sequence = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setInt(1,new_seq);
      stmt.setInt(2,id);
      stmt.setInt(3,old_seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemSequence

  void setItemEnable(int id, int seq, boolean enable) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET enable = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setInt(1,(enable ? 1 : 0));
      stmt.setInt(2,id);
      stmt.setInt(3,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemEnable

  void setItemIndent(int id, int seq, int indent) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET indent = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setInt(1,indent);
      stmt.setInt(2,id);
      stmt.setInt(3,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemIndent

  void setItemText(int id, int seq, String text) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET text = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setString(1,text);
      stmt.setInt(2,id);
      stmt.setInt(3,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemText

  void setItemLink(int id, int seq, String linktype, String link) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET linktype = ?, link = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setString(1,linktype);
      stmt.setString(2,link);
      stmt.setInt(3,id);
      stmt.setInt(4,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemLink

  void setItemTarget(int id, int seq, String target) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET target = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setString(1,target);
      stmt.setInt(2,id);
      stmt.setInt(3,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end target

  void setItemTitle(int id, int seq, String title) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET title = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setString(1,title);
      stmt.setInt(2,id);
      stmt.setInt(3,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemTitle

  void setItemOnClick(int id, int seq, String on_click) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET on_click = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setString(1,on_click);
      stmt.setInt(2,id);
      stmt.setInt(3,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemOnClick

  void setItemPermission(int id, int seq, String namespace, String name) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET perm_nsid = ?, perm_name = ? WHERE menuid = ? "
				   + "AND sequence = ?;");
      if (namespace==null)
	stmt.setNull(1,Types.INTEGER);
      else
	stmt.setInt(1,namespaceNameToId(namespace));
      stmt.setString(2,name);
      stmt.setInt(3,id);
      stmt.setInt(4,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemPermission

  void setItemIfDef(int id, int seq, String var) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET ifdef_var = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setString(1,var);
      stmt.setInt(2,id);
      stmt.setInt(3,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemIfDef

  void setItemIfNotDef(int id, int seq, String var) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("UPDATE menuitems SET ifndef_var = ? WHERE menuid = ? AND sequence = ?;");
      stmt.setString(1,var);
      stmt.setInt(2,id);
      stmt.setInt(3,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end setItemIfNotDef

  void addItem(int id, String type, int seq, String text, String linktype, String link) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the insert statement
      stmt = conn.prepareStatement("INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link) "
				   + "VALUES (?, ?, ?, ?, ?, ?);");
      stmt.setInt(1,id);
      stmt.setInt(2,seq);
      stmt.setString(3,type);
      stmt.setString(4,text);
      stmt.setString(5,linktype);
      stmt.setString(6,link);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end addItem

  void deleteItem(int id, int seq) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menuitems WRITE;");

      // create and execute the statement
      stmt = conn.prepareStatement("DELETE FROM menuitems WHERE menuid = ? AND sequence = ?;");
      stmt.setInt(1,id);
      stmt.setInt(2,seq);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end deleteItem

  void deleteMenu(int id) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menus WRITE, menuvars WRITE, menuitems WRITE;");

      // delete from the three tables
      stmt = conn.prepareStatement("DELETE FROM menus WHERE menuid = ?;");
      stmt.setInt(1,id);
      stmt.executeUpdate();
      stmt.close();
      stmt = conn.prepareStatement("DELETE FROM menuvars WHERE menuid = ?;");
      stmt.setInt(1,id);
      stmt.executeUpdate();
      stmt.close();
      stmt = conn.prepareStatement("DELETE FROM menuitems WHERE menuid = ?;");
      stmt.setInt(1,id);
      stmt.executeUpdate();

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end deleteMenu

  int createMenu(String namespace, String name, String title) throws DatabaseException
  {
    Connection conn = null;
    PreparedStatement stmt = null;
    Statement stmt2 = null;
    try
    { // get a connection
      conn = getConnection();

      // lock the appropriate table
      stmt2 = conn.createStatement();
      stmt2.executeUpdate("LOCK TABLES menus WRITE;");

      // insert the menu record
      stmt = conn.prepareStatement("INSERT INTO menus (menu_nsid, menu_name, title) VALUES (?, ?, ?);");
      stmt.setInt(1,namespaceNameToId(namespace));
      stmt.setString(2,name);
      stmt.setString(3,title);
      stmt.executeUpdate();
      return MySQLUtils.getLastInsertInt(conn);

    } // end try
    catch (SQLException e)
    { // translate to a general DatabaseException
      throw generalException(e);

    } // end catch
    finally
    { // shut everything down
      MySQLUtils.unlockTables(conn);
      SQLUtils.shutdown(stmt);
      SQLUtils.shutdown(stmt2);
      SQLUtils.shutdown(conn);

    } // end finally

  } // end createMenu

} // end class MenuDatabaseOps_mysql
