Example usage for org.hibernate SQLQuery list

List of usage examples for org.hibernate SQLQuery list

Introduction

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

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:com.userweave.module.methoden.questionnaire.dao.AnswerDaoImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// www .  j av a2  s  .  c  o m
public List<SingleDimensionAnswer> getValidAnswersForQuestion(DimensionsQuestion question,
        FilterFunctor filterFunctor) {
    QueryObject query = getQueryObject(question, filterFunctor, "singledimensionanswer",
            "singledimensionanswer");

    query.setResult("{qa.*}");

    if (query.getHasGroupBy()) {
        query.setGroupBy("qa.id, " + "qa.antipodePair_id, " + "qa.multipleDimensionsAnswer_id, " + "qa.rating");
    }

    SQLQuery q = new QueryTemplate(query).createSqlQuery(getCurrentSession());

    q.addEntity("qa", SingleDimensionAnswer.class);

    return q.list();
}

From source file:com.userweave.module.methoden.questionnaire.dao.AnswerDaoImpl.java

License:Open Source License

@Override
public Long getGroupedValidAnswersForDimensionQuestion(DimensionsQuestion question,
        FilterFunctor filterFunctor) {//from   ww w .  j  av  a2  s . co  m
    QueryObject query = getQueryObject(question, filterFunctor, "singledimensionanswer",
            "singledimensionanswer");

    query.setResult("count(distinct r_qa.surveyexecution_id)");

    SQLQuery q = new QueryTemplate(query).createSqlQuery(getCurrentSession());

    if (query.getHasGroupBy()) {
        return ((Integer) q.list().size()).longValue();
    }

    return ((BigInteger) q.uniqueResult()).longValue();
}

From source file:com.userweave.module.methoden.rrt.dao.RrtResultDaoImpl.java

License:Open Source License

@Override
public List<Object[]> findValidResultsForRrtConf(RrtConfigurationEntity conf, FilterFunctor filterFunctor) {
    SurveyExecutionDependentQuery query = createQuery(conf, filterFunctor);

    query.addLeftJoin(new Join("rrt_orderedterm", "rrtterm", "result.id", "rrtterm.result_id"));

    query.setResult("rrtterm.position, rrtterm.termid");

    if (query.getHasGroupBy()) {
        query.setGroupBy("result.id, " + "result.configuration_id, " + "result.executionFinished, "
                + "result.executionStarted, " + "result.executionTime, " + "result.surveyExecution_id");
    }// ww w  .j a va2s  .  c  o m

    SQLQuery q = new QueryTemplate(query).createSqlQuery(getCurrentSession());

    return q.list();
}

From source file:com.utils.dao.impl.ChitdaoImpl.java

public List fetchData(String searchquery) {
    List data;/* ww  w  .j  a  v  a2  s.  co m*/
    Session session = HBSession.getSessionFactory().openSession();
    try {

        session.beginTransaction();
        SQLQuery query = session.createSQLQuery(searchquery);
        //session.close();
        data = query.list();

    } catch (HibernateException e) {
        e.printStackTrace();
        //session.close();
        throw e;
    }
    session.close();
    return data;
}

From source file:com.vertec.daoimpl.GINDAOImpl.java

public int getSupplier(String po) {
    int sid = 0;//from  ww  w  .  ja v a  2 s  .  c o m
    SessionFactory sf = NewHibernateUtil.getSessionFactory();
    Session ses = sf.openSession();
    SQLQuery query = ses.createSQLQuery(
            "SELECT s.supplier_id,s.supplier_name FROM po_info pi inner join supplier s ON s.supplier_id=pi.supplier_supplier_id WHERE pi.po_info_id='"
                    + po + "'");
    List<Object[]> inList = query.list();
    for (Object[] list : inList) {
        sid = Integer.parseInt(list[0].toString());
    }
    ses.close();
    return sid;
}

From source file:com.vertec.daoimpl.GINDAOImpl.java

public JSONObject LoadMRN(String mrn) {

    SessionFactory sf = NewHibernateUtil.getSessionFactory();
    Session ses = sf.openSession();//from  w  w  w. ja v a  2 s  .  com
    SQLQuery query = ses.createSQLQuery(
            "SELECT mrn.product_id,p.product_name,p.product_code,mrn.available_qty FROM mrn mrn INNER JOIN product p on p.product_id=mrn.product_id WHERE mrn.mrn_info_id='"
                    + mrn + "'");

    List<Object[]> inList = query.list();
    JSONObject mainObject = new JSONObject();
    JSONArray jarr = new JSONArray();
    JSONObject product = null;
    for (Object[] list : inList) {
        product = new JSONObject();
        product.put("pid", list[0].toString());
        product.put("pname", list[1].toString());
        product.put("pcode", list[2].toString());
        product.put("qty", list[3].toString());

        SQLQuery query2 = ses.createSQLQuery(
                "SELECT pm.product_master_id,pm.selling_price FROM product_master pm  WHERE pm.product_id='"
                        + list[0].toString() + "'");
        List<Object[]> inList2 = query2.list();
        JSONArray pmarr = new JSONArray();
        JSONObject pmob = null;
        for (Object[] list2 : inList2) {
            pmob = new JSONObject();
            pmob.put("pmid", list2[0].toString());
            pmob.put("sp", list2[1].toString());
            pmarr.add(pmob);
        }
        product.put("pmarr", pmarr);
        jarr.add(product);
    }
    mainObject.put("data", jarr);

    ses.close();

    return mainObject;
}

From source file:com.vertec.daoimpl.GINDAOImpl.java

public String getProductMaster(String pid, String pprice, String sprice) {
    String pmid = "0";
    SessionFactory sf = NewHibernateUtil.getSessionFactory();
    Session ses = sf.openSession();//from   w ww  .  ja  v a2 s .c o  m
    Transaction tr = ses.beginTransaction();

    SQLQuery query = ses.createSQLQuery(
            "SELECT product_id,product_master_id FROM product_master WHERE product_id=:productId AND purchased_price=:pprice AND selling_price=:sprice");
    query.setParameter("productId", pid);
    query.setParameter("pprice", pprice);
    query.setParameter("sprice", sprice);
    List<Object[]> inList = query.list();
    boolean bool = true;
    for (Object[] list : inList) {
        System.out.println("PRODUCT MASTER IS EXIST...............ID : " + list[1].toString());
        bool = false;
        pmid = list[1].toString();
    }

    if (bool) {
        try {
            System.out.println("PRODUCT MASTER IS NOT EXIST.............. ");

            ProductMaster pm = new ProductMaster();
            pm.setPurchasedPrice(Double.valueOf(pprice));
            pm.setSellingPrice(Double.valueOf(sprice));
            Product pro = new PoDAOImpl().getProduct(Integer.valueOf(pid));
            pm.setProductId(pro);
            pm.setIsAvailable(true);
            ses.save(pm);
            ses.flush();
            tr.commit();

            SQLQuery query1 = ses.createSQLQuery(
                    "SELECT product_id,product_master_id FROM product_master WHERE product_id=:productId AND purchased_price=:pprice AND selling_price=:sprice");
            query1.setParameter("productId", Integer.valueOf(pid));
            query1.setParameter("pprice", Double.valueOf(pprice));
            query1.setParameter("sprice", Double.valueOf(sprice));
            List<Object[]> inList1 = query1.list();

            for (Object[] list : inList1) {
                System.out.println("PRODUCT MASTER IS CREATED...............ID : " + list[1].toString());
                bool = false;
                pmid = list[1].toString();
                return list[1].toString();
            }

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    ses.close();
    return pmid;
}

From source file:com.vertec.daoimpl.GINDAOImpl2.java

public String getItems(String id) {
    String html = "";

    Session session = NewHibernateUtil.getSessionFactory().openSession();

    if (session != null) {
        try {/*from   ww  w. j a  v  a  2s . c  o  m*/
            SQLQuery query = session.createSQLQuery(
                    "select p.product_code,p.product_name,gin.qty,gin.p_price,gin.s_price from gin gin inner join warehouse_stock whs on whs.warehouse_stock_id=gin.warehouse_stock_warehouse_stock_id inner join product_master pm on pm.product_master_id=whs.product_master_product_master_id inner join product p on pm.product_id=p.product_id where gin_info_gin_info_id='"
                            + id + "'");

            List<Object[]> inList = query.list();
            for (Object[] list : inList) {
                html += "<tr><td>" + list[0].toString() + " " + list[1].toString() + "</td><td>"
                        + list[2].toString() + "</td><td>" + list[3].toString() + "</td><td>"
                        + list[4].toString() + "</td><tr>";
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }

    return html;
}

From source file:com.vertec.daoimpl.GINDAOImpl2.java

public String ProductFromCategory(String id) {
    String html = "";

    Session session = NewHibernateUtil.getSessionFactory().openSession();

    if (session != null) {
        try {/* w  w w  . ja v a  2 s  .c om*/
            String hql = "SELECT p.product_id,p.product_code,p.product_name,w.qty,pm.purchased_price,pm.selling_price,w.warehouse_stock_id FROM warehouse_stock w INNER JOIN product_master pm ON pm.product_master_id=w.product_master_product_master_id INNER JOIN product p ON pm.product_id=p.product_id INNER JOIN sys_user su ON su.sysuser_id=w.updated_by where w.qty>0 and product_category_id='"
                    + id + "' ORDER BY p.product_code ASC";

            SQLQuery query = session.createSQLQuery(hql);

            List<Object[]> inList = query.list();
            for (Object[] list : inList) {
                html += list[0] + ":::::" + list[1] + ":::::" + list[2] + ":::::" + list[3] + ":::::" + list[4]
                        + ":::::" + list[5] + ":::::" + list[6] + ";;;;;";
            }

            if (!html.equals("")) {
                html = html.substring(0, html.length() - 5);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }

    return html;
}

From source file:com.vertec.daoimpl.GINDAOImpl2.java

public String ProductFromCategoryForPO(String id) {
    String html = "";

    Session session = NewHibernateUtil.getSessionFactory().openSession();

    if (session != null) {
        try {/*  w w  w  . j a  v  a 2s. c o  m*/
            String hql = "SELECT p.product_id,p.product_code,p.product_name FROM product p where p.is_available='1' and p.product_category_id='"
                    + id + "' ORDER BY p.product_code ASC";

            SQLQuery query = session.createSQLQuery(hql);

            List<Object[]> inList = query.list();
            for (Object[] list : inList) {
                html += list[0] + ":::::" + list[1] + ":::::" + list[2] + ";;;;;";
            }

            if (!html.equals("")) {
                html = html.substring(0, html.length() - 5);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }

    return html;
}