Esempio n. 1
0
  public boolean addToCart(Cart cart) {
    Session session = HibernateUtil.openSession();

    Transaction tx = null;
    try {
      tx = session.getTransaction();
      tx.begin();
      session.saveOrUpdate(cart);
      tx.commit();
    } catch (Exception e) {
      if (tx != null) {
        tx.rollback();
      }
      e.printStackTrace();
    } finally {
      session.close();
    }
    return true;
  }
Esempio n. 2
0
 public List<Cart> getListOfProductsInCart() {
   List<Cart> list = new ArrayList<Cart>();
   Session session = HibernateUtil.openSession();
   Transaction tx = null;
   try {
     tx = session.getTransaction();
     tx.begin();
     list = session.createQuery("from Cart").list();
     tx.commit();
   } catch (Exception e) {
     if (tx != null) {
       tx.rollback();
     }
     e.printStackTrace();
   } finally {
     session.close();
   }
   return list;
 }
Esempio n. 3
0
 public List<Cart> getCartByUserId(String uid) {
   List<Cart> list = new ArrayList<Cart>();
   Session session = HibernateUtil.openSession();
   Transaction tx = null;
   try {
     tx = session.getTransaction();
     tx.begin();
     Query query = session.createQuery("from Cart where user_id=" + uid);
     list = query.list();
     tx.commit();
   } catch (Exception e) {
     if (tx != null) {
       tx.rollback();
     }
     e.printStackTrace();
   } finally {
     session.close();
   }
   return list;
 }
Esempio n. 4
0
 public Cart getCartById(String pid) {
   Cart cart = new Cart();
   Session session = HibernateUtil.openSession();
   Transaction tx = null;
   try {
     tx = session.getTransaction();
     tx.begin();
     Query query = session.createQuery("from Cart where cart_id=" + pid);
     cart = (Cart) query.uniqueResult();
     tx.commit();
   } catch (Exception e) {
     if (tx != null) {
       tx.rollback();
     }
     e.printStackTrace();
   } finally {
     session.close();
   }
   return cart;
 }