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:Action.OrderManagement.java

public String fillCompanyNames() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Company_Details company_Details;//from   www  .j  a  v  a  2s.co  m
    Query q = s.createQuery(" from Company_Details");
    List<Company_Details> data = q.list();
    if (data.isEmpty()) {
    } else {
        for (Company_Details cid : data) {

            getCompanyNamesList().add(cid.getCompanyName());

        }
    }

    t.commit();
    return "success";
}

From source file:Action.OrderManagement.java

public String fillCompanyDetails() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Company_Details company_Details;/*from   ww  w .j av  a 2 s  .com*/
    Query q = s.createQuery(" from Company_Details where companyName='" + getCompanyName() + "'");
    List<Company_Details> data = q.list();
    for (Company_Details sid : data) {
        setCity(sid.getCity());
        setProvince(sid.getProvince());
        setStreet1(sid.getStreet1());
        setStreet2(sid.getStreet2());
        setPincode(sid.getPincode());
        setEmailId(sid.getEmailId());
        setContactNo1(sid.getContactNo1());
        setContactNo2(sid.getContactNo2());
        setCompanyHead(sid.getCompanyHead());
    }
    t.commit();

    return "success";
}

From source file:Action.OrderManagement.java

public String addOrder() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Company_Details company_Details;/*from   w ww .  j a va 2 s  .com*/
    Query q1 = s.createQuery(" from Company_Details where companyName='" + getCompanyName() + "'");
    List<Company_Details> data1 = q1.list();
    company_Details = new Company_Details(0, getCompanyName(), getStreet1(), getStreet2(), getCity(),
            getProvince(), getPincode(), getEmailId(), getCompanyHead(), getContactNo1(), getContactNo2());

    if (data1.isEmpty()) {
        s.save(company_Details);
        System.out.println("sssss");
    }

    setNewMaterialRequired("  Pieces ." + "Material Required for Order  - 1. " + getName() + "  "
            + getQuantity() + "  Pieces   2. " + getName2() + "  " + getQuantity2());
    Order_Details order_Details;
    order_Details = new Order_Details(0, getOrderDescription(), getContactPerson(), "Pending", 0, 0,
            getNewMaterialRequired(), company_Details);
    s.save(order_Details);

    if (getName2().isEmpty()) {
    } else {
        Product_Details product_Details;
        product_Details = new Product_Details(0, getName(), getQuantity(), getRateFixed(), getDeliveryDate(),
                order_Details);
        s.save(product_Details);

        Product_Processing product_processing11;
        product_processing11 = new Product_Processing(0, 0, "Process 1", product_Details);
        s.save(product_processing11);
        Product_Processing product_processing12;
        product_processing12 = new Product_Processing(0, 0, "Process 2", product_Details);
        s.save(product_processing12);
        Product_Processing product_processing13;
        product_processing13 = new Product_Processing(0, 0, "Process 3", product_Details);
        s.save(product_processing13);
        Product_Processing product_processing14;
        product_processing14 = new Product_Processing(0, 0, "Process 4", product_Details);
        s.save(product_processing14);
        Product_Processing product_processing15;
        product_processing15 = new Product_Processing(0, 0, "Process 5", product_Details);
        s.save(product_processing15);
    }

    if (getName2().isEmpty()) {
    } else {
        Product_Details product_Details2;
        product_Details2 = new Product_Details(0, getName2(), getQuantity2(), getRateFixed2(),
                getDeliveryDate2(), order_Details);
        s.save(product_Details2);

        Product_Processing product_processing21;
        product_processing21 = new Product_Processing(0, 0, "Process 1", product_Details2);
        s.save(product_processing21);
        Product_Processing product_processing22;
        product_processing22 = new Product_Processing(0, 0, "Process 2", product_Details2);
        s.save(product_processing22);
        Product_Processing product_processing23;
        product_processing23 = new Product_Processing(0, 0, "Process 3", product_Details2);
        s.save(product_processing23);
        Product_Processing product_processing24;
        product_processing24 = new Product_Processing(0, 0, "Process 4", product_Details2);
        s.save(product_processing24);
        Product_Processing product_processing25;
        product_processing25 = new Product_Processing(0, 0, "Process 5", product_Details2);
        s.save(product_processing25);
    }
    /*  if(Name3.isEmpty()){        // To be corrected
    } else {
    Product_Details product_Details3;
    product_Details3 = new Product_Details( 0, Name3, Quantity3,rateFixed3,deliveryDate3,order_Details);
    s.save(product_Details3);
    Product_Details product_Details4;
    product_Details4 = new Product_Details( 0, Name4, Quantity4,rateFixed4,deliveryDate4,order_Details);
    s.save(product_Details4);
    Product_Details product_Details5;
    product_Details5 = new Product_Details( 0, Name5, Quantity5,rateFixed5,deliveryDate5,order_Details);
    s.save(product_Details5);
      }*/

    t.commit();

    return "success";
}

From source file:Action.OrderManagement.java

public String fillOrderProgress() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    List<Order_Details> orderList = new <Order_Details>ArrayList();
    List<Product_Details> productList1 = new <Product_Details>ArrayList();
    List<Product_Details> productList2 = new <Product_Details>ArrayList();
    List<Product_Processing> productProcessList = new <Product_Processing>ArrayList();

    int i = 1, j = 1, k = 1; // to increment order 1 , 2 3 etc

    Query q = s.createQuery(" from Order_Details where status='Pending'");
    List<Order_Details> data = q.list();
    for (Order_Details od : data) {
        getReq().setAttribute("order_Details" + i, od);
        orderList.add(od);//from   www. j  av a  2  s  .co  m
        Query q1 = s.createQuery(" from Product_Details where order_details_FK='" + od.getOrderId() + "'");
        List<Product_Details> data1 = q1.list();
        for (Product_Details pd : data1) {
            getReq().setAttribute("product_Details" + i + j, pd);
            if (i == 1) {
                productList1.add(pd);
            }
            if (i == 2) {
                productList2.add(pd);
            }
            Query q2 = s.createQuery(
                    " from Product_Processing where product_details_FK='" + pd.getProductId() + "'");
            List<Product_Processing> data2 = q2.list();
            for (Product_Processing pp : data2) {
                productProcessList.add(pp);
                getReq().setAttribute("product_Processing" + i + j + k, pp);
                k++;
            }
            j++;
        }
        i++;
    }
    getReq().setAttribute("orderList", orderList);
    getReq().setAttribute("productList1", productList1);
    getReq().setAttribute("productList2", productList2);

    t.commit();
    return "success";
}

From source file:Action.StockManagement.java

public String fillItemDetails() throws NullPointerException {
    getReq().setAttribute("hello", getResult());
    //setCity("Kunwar");
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Current_Stock current_Stock;/*  ww  w. j a v  a 2  s.c  o  m*/
    Query q = s.createQuery(" from Current_Stock where name='" + getName() + "'");
    List<Current_Stock> data = q.list();
    for (Current_Stock cs : data) {

        setType(cs.getType());
        setDescription(cs.getDescription());
        setItemId(cs.getItemId());
    }
    t.commit();

    return "success";
}

From source file:Action.StockManagement.java

public String fillSupplierDetails() throws NullPointerException {
    getReq().setAttribute("hello", getResult());
    //setCity("Kunwar");
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Supplier_Details supplier_Details;
    Query q = s.createQuery(" from Supplier_Details where supplierName='" + getSupplierName() + "'");
    List<Supplier_Details> data = q.list();
    for (Supplier_Details sid : data) {
        setCity(sid.getCity());//from w w w  .  j  av a 2  s .  c  o  m
        setProvince(sid.getProvince());
        setStreet1(sid.getStreet1());
        setStreet2(sid.getStreet2());
        setPincode(sid.getPincode());
        setEmailId(sid.getEmailId());
        setContactNo1(sid.getContactNo1());
        setContactNo2(sid.getContactNo2());
        setSupplierId(sid.getSupplierId());
    }
    t.commit();

    return "success";
}

From source file:Action.StockManagement.java

public String fillSupplierDetails1() throws NullPointerException {
    getReq().setAttribute("hello", getResult());
    //setCity("Kunwar");
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Supplier_Details supplier_Details;
    Query q = s.createQuery(" from Supplier_Details where supplierName='" + getSupplierName() + "'");
    List<Supplier_Details> data = q.list();
    for (Supplier_Details sid : data) {
        setCity(sid.getCity());/*from w ww.ja  v  a 2  s . c  o m*/
        setProvince(sid.getProvince());
        setStreet1(sid.getStreet1());
        setStreet2(sid.getStreet2());
        setPincode(sid.getPincode());
        setEmailId(sid.getEmailId());
        setContactNo1(sid.getContactNo1());
        setContactNo2(sid.getContactNo2());
        setSupplierName(sid.getSupplierName());
    }
    t.commit();

    return "success";
}

From source file:Action.StockManagement.java

public String fillSupplierId() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Supplier_Details supplier_Details;
    Query q = s.createQuery(" from Supplier_Details");
    List<Supplier_Details> data = q.list();
    if (data.isEmpty()) {
    } else {//from w w  w .j a v a  2s  . c  o m
        for (Supplier_Details sid : data) {
            getStateslist().add(sid.getSupplierId());
            getSupplierNamesList().add(sid.getSupplierName());

        }
    }

    t.commit();

    Session s1 = HibernateUtil.getSession();
    Transaction t1 = s1.beginTransaction();

    Current_Stock current_Stock;
    Query q1 = s1.createQuery(" from Current_Stock");
    List<Current_Stock> data1 = q1.list();
    if (data1.isEmpty()) {
    } else {
        for (Current_Stock cs : data1) {

            getItemNamesList().add(cs.getName());
        }
    }
    t1.commit();
    return "success";
}

From source file:Action.StockManagement.java

public String addStock() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Supplier_Details supplier_Details;
    Query q1 = s.createQuery(" from Supplier_Details where SupplierId='" + getSupplierId() + "'");
    List<Supplier_Details> data1 = q1.list();
    supplier_Details = new Supplier_Details(getSupplierId(), getSupplierName(), getStreet1(), getStreet2(),
            getCity(), getProvince(), getPincode(), getEmailId(), getContactNo1(), getContactNo2());

    if (data1.isEmpty()) {
        s.save(supplier_Details);//from  w w w.  java 2 s  .  c  o  m
    }

    getReq().setAttribute(getSupplierName(), getResult());

    t.commit();
    Session s1 = HibernateUtil.getSession();
    Transaction t1 = s1.beginTransaction();
    Item_History item_History;
    Query q = s1.createQuery(" from Current_Stock where itemId='" + getItemId() + "'");
    List<Current_Stock> data = q.list();
    if (data.isEmpty()) {
        item_History = new Item_History(0, getName(), getCompanyName(), getQuantity(), getType(),
                getDescription(), getCostPerPiece(), getDateOfPurchase(), supplier_Details);
        Current_Stock current_Stock = new Current_Stock(getItemId(), getName(), getQuantity(),
                getCostPerPiece(), getType(), getDescription());
        s1.save(item_History);
        s1.save(current_Stock);
    } else {
        item_History = new Item_History(0, getName(), getCompanyName(), getQuantity(), getType(),
                getDescription(), getCostPerPiece(), getDateOfPurchase(), supplier_Details);
        Current_Stock current_Stock = (Current_Stock) s1.get(Current_Stock.class, getItemId());
        current_Stock.setQuantity(getQuantity() + current_Stock.getQuantity());
        double newCost = ((current_Stock.getCostPerPiece() * current_Stock.getQuantity()
                + getQuantity() * getCostPerPiece()) / current_Stock.getQuantity() + getQuantity());
        current_Stock.setCostPerPiece(newCost);
        s1.save(item_History);
        s1.save(current_Stock);

    }

    getReq().setAttribute(getSupplierName(), getResult());

    t1.commit();

    return "success";
}

From source file:AdminSystemClasses.AtmDB.java

public static List<BankTransaction> viewChecks(DepositedChecks dep) throws Exception {

    Session sf = DB.getSession();//from  w w  w  .j a v  a 2 s .  c o m
    Transaction tx = sf.beginTransaction();

    Query q = sf.createQuery(
            "from bank.BankTransaction bt where atmid = ? and description =? and checknumber is not null");
    q.setParameter(0, dep.getAtmId());
    q.setString(1, "deposit");

    List<BankTransaction> bt = q.list();

    return bt;

}