コード例 #1
0
  // removes the new books order item request placed by the customer on delivering it
  public List<OrderItem> removeNewBookOrderItem(Book book, List<OrderItem> list) {
    try {
      Book book1 = new Book();
      for (int i = list.size() - 1; i >= 0; i--) {
        OrderItem oi = list.get(i);

        if (oi.getBook().getProductName().trim().equals(book.getProductName())
            && oi.getBook().getAuthor().trim().equals(book.getAuthor())
            && oi.getBook().getEdition().trim().equals(book.getEdition())
            && oi.getBook().getActive() == book.getActive()) {
          list.remove(i);
          book1 = oi.getBook();
          if (book1.getActive() == 0) {
            Session session1 = HibernateUtil.getSessionFactory().openSession();
            Transaction tx1 = session1.beginTransaction();
            Book book2 = (Book) session1.get(Book.class, book1.getProductId());
            if (book.getOrderitemList() != null) {
              session1.delete(book2.getInventoryItem());
            }
            session1.delete(book2);
            tx1.commit();
            close();
          }
          break;
        }
      }
    } catch (Exception e) {
      System.out.print("Can not delete");
    }

    return list;
  }
コード例 #2
0
 // updates the details of an order item
 public void updateItem(String status, Float cost, int oid) {
   try {
     Session session1 = HibernateUtil.getSessionFactory().openSession();
     Transaction tx1 = session1.beginTransaction();
     OrderItem oi1 = (OrderItem) session1.get(OrderItem.class, oid);
     oi1.setItemStatus(status);
     Book book = oi1.getBook();
     int bookId = book.getProductId();
     Book book1 = (Book) session1.get(Book.class, bookId);
     session1.update(oi1);
     session1.update(book1);
     tx1.commit();
     close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }