Ejemplo 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;
  }
Ejemplo 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;
 }
Ejemplo 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;
 }
Ejemplo 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;
 }