Пример #1
0
  /**
   * 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;
  }
 /**
  * confirm orders
  *
  * @param request
  * @param response
  */
 private synchronized void confirmOrders(
     HttpServletRequest request, HttpServletResponse response) {
   if (!Boolean.parseBoolean(request.getParameter(REQUEST_SUBMIT_ORDERS.toString()))) {
     Logger.getLogger(OrderTableCommand.class.getName())
         .info(
             REQUEST_SUBMIT_ORDERS.toString()
                 + request.getParameter(REQUEST_SUBMIT_ORDERS.toString()));
     return;
   }
   for (int i = 0; i < list.size(); i++) {
     Logger.getLogger(OrderTableCommand.class.getName()).info(REQUEST_SUBMIT_ORDERS.toString());
     String str =
         MYSQL_ORDER_ID.toString()
             + list.get(i).getOrderId()
             + MYSQL_USER_ID.toString()
             + list.get(i).getUserId();
     OrderDAO orderDao = DAOFactory.getFactory(DB_MYSQL).createOrderDAO();
     Logger.getLogger(OrderTableCommand.class.getName()).info(str + request.getParameter(str));
     if (Boolean.parseBoolean(request.getParameter(str))) {
       orderDao.confirmOrder(list.get(i).getOrderId());
     }
   }
 }