Example usage for org.hibernate Query list

List of usage examples for org.hibernate Query list

Introduction

In this page you can find the example usage for org.hibernate Query list.

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:automatedbillingsoftware_DA.InvoiceReport_DA.java

public List<InvoiceReport> searchInvoiceReport(Date frmDate, Date toDate, int orderNo, String docName,
        int docNo) {
    List<InvoiceReport> invoiceList = new LinkedList<>();
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from InvoiceReport where status =:status");
    query.setParameter("status", 1);
    List<InvoiceReport> invoiceReportList = query.list();

    List<InvoiceReport> searchList = new LinkedList<>();

    for (int i = 0; i < invoiceReportList.size(); i++) {
        if (invoiceReportList.get(i).getOrderNo() == (double) orderNo
                || (invoiceReportList.get(i).getBillDate().compareTo(toDate) <= 0
                        && invoiceReportList.get(i).getBillDate().compareTo(frmDate) >= 0)
                || new ChallanBL().fetchChallanByDocName(docName) != null) {
            searchList.add(invoiceReportList.get(i));
        }//from  ww  w  .j a  v a  2s .  co  m
    }

    beginTransaction.commit();
    System.out.println("searchList=>" + searchList);
    return searchList;

}

From source file:automatedbillingsoftware_DA.Products_DA.java

public void deleteProducts(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Products p where p.status=:status AND p.prodid=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<Products> list = (List<Products>) query.list();
    Products get = list.get(0);/*w  w w .j av a2s . c  o  m*/
    get.setStatus(0);
    session.update(get);
    beginTransaction.commit();

}

From source file:automatedbillingsoftware_DA.Products_DA.java

public Products fetchProductById(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Products p where p.status=:status AND p.prodid=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<Products> list = (List<Products>) query.list();
    Products get = list.get(0);/* www .  j  a  v a 2s. c o  m*/

    beginTransaction.commit();
    return get;
}

From source file:automatedbillingsoftware_DA.Products_DA.java

public List<Products> fetchAllProducts() {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Products p where status=:status");
    query.setParameter("status", 1);
    List<Products> list = (List<Products>) query.list();
    beginTransaction.commit();/*  w  ww  .j  av  a2s. co  m*/
    return list;
}

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 . j  a v a  2  s.c  o  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();/*ww  w.j av  a2 s  .  c  om*/
    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  . jav  a 2s .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 List<Tax> fetchAllTaxList() {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Tax t where t.status=:status");
    query.setParameter("status", 1);
    List<Tax> list = (List<Tax>) query.list();
    beginTransaction.commit();/*from  w ww .  j  a  v  a2 s.  com*/
    return list;
}

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  w  ww  . j  a v 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();/*from   w  w  w .ja va  2 s  . c o  m*/
    return tax;
}