/** * check if the order is ready * * @param orderId order id * @return if order is ready */ @Override public boolean checkOrder(int orderId) { Connection connection = MyConnection.getInstance().getConnection(); int ready = 0; try { PreparedStatement preparedStatement = connection.prepareStatement("select * from order_table where orderId = ?"); preparedStatement.setInt(1, orderId); ResultSet resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { ready = resultSet.getInt(MYSQL_READY.toString()); } } catch (SQLException | NullPointerException ex) { Logger.getLogger(MySQLOrderDAO.class.getName()).error(ex); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException ex) { Logger.getLogger(MySQLOrderDAO.class.getName()).error(ex); } } return (ready == 1); }
/** * select all user-applied orders, that are not submitted * * @return */ @Override public LinkedList<Order> selectAllForOrderTable() { LinkedList<Order> list = new LinkedList(); Connection connection = MyConnection.getInstance().getConnection(); try { // selecting all orders PreparedStatement preparedStatement = connection.prepareStatement("select * from order_table"); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { // if order is not submitted if (resultSet.getInt(MYSQL_READY.toString()) == 0) { list.add( new Order( resultSet.getInt(MYSQL_ORDER_ID.toString()), resultSet.getInt(MYSQL_USER_ID.toString()), null, 0, 0)); } } } catch (SQLException | NullPointerException ex) { Logger.getLogger(MySQLOrderDAO.class.getName()).error(ex); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException ex) { Logger.getLogger(MySQLOrderDAO.class.getName()).error(ex); } } return list; }