List of usage examples for org.hibernate SessionFactory getCurrentSession
Session getCurrentSession() throws HibernateException;
From source file:automatedbillingsoftware_DA.Products_DA.java
public List<Products> fetchProductByQRCode(String qrcode) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Query query = session.createQuery("from Products p where status =:status and qrCode=:code"); query.setParameter("status", 1); query.setParameter("code", qrcode); List<Products> list = (List<Products>) query.list(); System.out.println(qrcode + "list.size=>" + list.size()); beginTransaction.commit();/*from w ww . ja v a 2s . co m*/ return list; }
From source file:automatedbillingsoftware_DA.Products_DA.java
public Products fetchProductByName(String name) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Query query = session.createQuery("from Products p where status =:status and prodName=:name"); query.setParameter("status", 1); query.setParameter("name", name); List<Products> list = (List<Products>) query.list(); beginTransaction.commit();/*from www.j av a 2 s .c o m*/ return (Products) (list.size() > 0 ? list.get(0) : null); }
From source file:automatedbillingsoftware_DA.Products_DA.java
public List<Products> fetchProductSearchList(String catName, String prodName, double minQty, double maxQty, double minPrice, double maxPrice) { System.out.println("prodName 1=>" + prodName); SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Categories_DA categories_DA = new Categories_DA(); Categories cat = categories_DA.fetchCategoryByName(catName); int idcat = 0; if (cat != null) { idcat = cat.getCatid();//from w w w .j a va2 s.c o m } System.out.println("cat=>" + idcat + "cat=>" + catName); if (prodName == null) { prodName = ""; } Query query = session.createSQLQuery("Select * from PRODUCT_TBL where PRODNAME LIKE '%" + prodName + "%' OR " + "CATEGORY_CATID = " + idcat + " AND status = 1 "); List list = query.list(); ArrayList<Products> prodList = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { Products prod = new Products(); Object[] obj = (Object[]) list.get(i); prod.setProdid((Integer) obj[0]); prod.setDateOfAddition((Date) obj[1]); prod.setBarCode((String) obj[2]); prod.setModTime((Date) obj[3]); prod.setModifiedBy((String) obj[4]); prod.setProdCost((Double) obj[5]); prod.setProdDesc((String) obj[6]); prod.setProdName((String) obj[7]); prod.setProdQty((Double) obj[8]); prod.setStatus((Integer) obj[10]); prod.setCategory((Categories) categories_DA.fetchCategoryById((Integer) obj[12])); prod.setQrCode((String) obj[9]); prod.setUom((String) obj[11]); prodList.add(prod); } // query = session.createQuery("from Products where status=:status AND prodName LIKE :name OR category.catName LIKE :catName"); // query.setParameter("status", 1); // query.setParameter("name", prodName); // query.setParameter("catName", catName); // List<Products> prodList = (List<Products>) query.list(); System.out.println("prodList size=>" + prodList.size()); ArrayList<Products> productList = new ArrayList<>(); List<Products> pList = prodList; for (int i = 0; i < pList.size(); i++) { Products pr = prodList.get(i); System.out.println("prod=>" + pr); double qty = pr.getProdQty(); double cost = pr.getProdCost(); System.out.println("prodName=>" + prodName); System.out.println("prodCost=>" + pr.getProdCost() + "maxPrice=>" + maxPrice + "comp=>" + (((pr.getProdCost() <= maxPrice)))); if ((idcat != 0 && pr.getCategory().getCatid() == idcat) || !prodName.isEmpty() || ((qty <= maxQty && maxQty != 0) && qty >= minQty) || (cost >= minPrice && (cost <= maxPrice && maxPrice != 0))) { productList.add(pr); } else { // prodList.remove(pr); } } // prodList.stream().forEach((pr) -> { // // System.out.println("prodCost=>" + pr.getProdCost() + "comp=>" + ((pr.getProdCost() >= minPrice && (pr.getProdCost() <= maxPrice && maxPrice != 0)))); // // // // if (((pr.getProdQty() <= maxQty && maxQty != 0) && pr.getProdQty() >= minQty) || (pr.getProdCost() >= minPrice && (pr.getProdCost() <= maxPrice && maxPrice != 0))) { // prodList.add(pr); // } else { // // prodList.remove(pr); // } // }); beginTransaction.commit(); return productList; }
From source file:automatedbillingsoftware_DA.TaxDA.java
public Tax addTax(Tax tax) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); session.persist(tax);/*from w ww.ja va 2s . com*/ beginTransaction.commit(); return tax; }
From source file:automatedbillingsoftware_DA.TaxDA.java
public Tax fetchTaxByName(String name) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Query query = session.createQuery("from Tax t where t.taxName LIKE :taxName AND t.status=:status"); query.setParameter("status", 1); query.setParameter("taxName", name); Tax tax = (Tax) query.list().get(0); beginTransaction.commit();/*from www .jav a 2s .c o m*/ return tax; }
From source file:automatedbillingsoftware_DA.TaxDA.java
public Tax fetchTaxById(int id) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Query query = session.createQuery("from Tax t where t.taxId=:taxId AND t.status=:status"); query.setParameter("status", 1); query.setParameter("taxId", id); Tax tax = (Tax) query.list().get(0); beginTransaction.commit();// w w w. j a va2 s . c om return tax; }
From source file:automatedbillingsoftware_DA.TaxDA.java
public void deleteTax(int id) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Tax tax = (Tax) session.load(Tax.class, id); tax.setStatus(0);// w w w.j ava 2s . c o m session.update(tax); beginTransaction.commit(); }
From source file:automatedbillingsoftware_DA.TaxDA.java
public void updateTax(Tax tax) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); session.update(tax);/*from w w w . j a va 2s.c o m*/ beginTransaction.commit(); }
From source file:automatedbillingsoftware_DA.User_DA.java
public Users addUser(Users users) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); session.saveOrUpdate(users);//from w w w.j a v a 2 s . c o m beginTransaction.commit(); return users; }
From source file:automatedbillingsoftware_DA.User_DA.java
public List<Users> fetchAllUser(Users users) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Query query = session.createQuery("from Users where status=:status"); query.setParameter("status", 1); List<Users> list = (List<Users>) query.list(); // session.saveOrUpdate(users); beginTransaction.commit();// w w w . ja v a 2s. c o m // return users; return list; }