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:benchmark.BenchmarkHnP.java

License:Apache License

/** Create database and using SELECT */
@SuppressWarnings("unchecked")
public void useMultiSelect() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    String hql = "from HbmOrder where deleted = :deleted";
    Query query = session.createQuery(hql);
    query.setParameter("deleted", false);
    List<HbmOrder> orders = (List<HbmOrder>) query.list();

    int i = 0;/*from   www. j  a  va 2 s.  c o  m*/
    for (HbmOrder order : orders) {
        String surename = order.getUser().getSurename();
        if (false) {
            System.out.println("Usr.surename: " + surename);
        }

        hql = "from HbmOrderItem where deleted = :deleted and order = :order";
        query = session.createQuery(hql);
        query.setParameter("deleted", false);
        query.setParameter("order", order);
        List<HbmOrderItem> items = (List<HbmOrderItem>) query.list();

        for (HbmOrderItem item : items) {
            ++i;
            BigDecimal price = item.getPrice();
            BigDecimal charge = item.getCharge();
            if (true) {
                String lang = item.getOrder().getLanguage();
                String name = item.getUser().getLastname();
                if (false) {
                    System.out.println(">>> Order.lang: " + lang + " User.lastname" + name);
                }
            }
        }
    }

    tr.commit();
    printTime("MULTI SELECT " + i, time1, System.currentTimeMillis());
}

From source file:benchmark.BenchmarkHnP.java

License:Apache License

/** Update a charge of the order items */
@SuppressWarnings("unchecked")
public void useUpdate() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    String hql = "from HbmOrderItem where deleted = :deleted and order.deleted = :deleted";
    Query query = session.createQuery(hql);
    query.setParameter("deleted", false);
    List<HbmOrderItem> items = (List<HbmOrderItem>) query.list();

    int i = 0;/*  ww w.ja  v  a2 s  .co m*/
    for (HbmOrderItem item : items) {
        ++i;
        item.setCharge(item.getCharge().add(BigDecimal.ONE));
        session.update(item);
    }

    tr.commit();
    printTime("UPDATE " + i, time1, System.currentTimeMillis());
}

From source file:benchmark.BenchmarkHnP.java

License:Apache License

/** Create database and using DELETE */
@SuppressWarnings("unchecked")
public void useDelete() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    String hql = "from HbmOrder";
    Query query = session.createQuery(hql);
    List<HbmOrder> orders = (List<HbmOrder>) query.list();

    for (HbmOrder order : orders) {

        hql = "delete from HbmOrderItem it where it.order = :order";
        query = session.createQuery(hql);
        query.setParameter("order", order);
        int rows = query.executeUpdate();

        session.delete(order);/*from w w w  . ja v a  2s. com*/
    }

    session.flush();

    hql = "delete from HbmUser";
    query = session.createQuery(hql);
    int rows = query.executeUpdate();

    tr.commit();
    printTime("DELETE", time1, System.currentTimeMillis());
}

From source file:benchmark.BenchmarkHnU.java

License:Apache License

/** Create database and using SELECT */
@SuppressWarnings("unchecked")
public void useSingleSelect() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    String hql = "from PrfOrderItem where deleted = :deleted and order.deleted = :deleted";
    Query query = session.createQuery(hql);
    query.setParameter("deleted", false);
    List<PrfOrderItem> items = (List<PrfOrderItem>) query.list();

    int i = 0;//from   ww w  .  j  av a2 s . c  o  m
    for (PrfOrderItem item : items) {
        ++i;
        Long id = item.getId();
        BigDecimal price = item.getPrice();
        if (false) {
            System.out.println(">>> Item.id: " + id + " " + price);
        }
    }

    tr.commit();
    printTime("SINGLE SELECT " + i, time1, System.currentTimeMillis());
}

From source file:benchmark.BenchmarkHnU.java

License:Apache License

/** Create database and using SELECT */
@SuppressWarnings("unchecked")
public void useEmptySelect() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    for (int i = -ORDER_COUNT; i < 0; i++) {
        String hql = "from PrfOrder where id = :id and deleted = :deleted";
        Query query = session.createQuery(hql);
        query.setParameter("id", new Long(i));
        query.setParameter("deleted", true);
        List<PrfOrder> items = (List<PrfOrder>) query.list();
    }// w ww .ja v a2  s.c om

    tr.commit();
    printTime("EMPTY SELECT " + ORDER_COUNT, time1, System.currentTimeMillis());
    ;

}

From source file:benchmark.BenchmarkHnU.java

License:Apache License

/** Create database and using SELECT */
@SuppressWarnings("unchecked")
public void useMultiSelect() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    String hql = "from PrfOrder where deleted = :deleted";
    Query query = session.createQuery(hql);
    query.setParameter("deleted", false);
    List<PrfOrder> orders = (List<PrfOrder>) query.list();

    int i = 0;//from   w  ww.  ja  v  a  2 s  .c  o  m
    for (PrfOrder order : orders) {
        String surename = order.getUser().getSurename();
        if (false) {
            System.out.println("Usr.surename: " + surename);
        }

        hql = "from PrfOrderItem where deleted = :deleted and order = :order";
        query = session.createQuery(hql);
        query.setParameter("deleted", false);
        query.setParameter("order", order);
        List<PrfOrderItem> items = (List<PrfOrderItem>) query.list();

        for (PrfOrderItem item : items) {
            ++i;
            BigDecimal price = item.getPrice();
            BigDecimal charge = item.getCharge();
            if (true) {
                String lang = item.getOrder().getLanguage();
                String name = item.getUser().getLastname();
                if (false) {
                    System.out.println(">>> Order.lang: " + lang + " User.lastname" + name);
                }
            }
        }
    }

    tr.commit();
    printTime("MULTI SELECT " + i, time1, System.currentTimeMillis());
}

From source file:benchmark.BenchmarkHnU.java

License:Apache License

/** Update a charge of the order items */
@SuppressWarnings("unchecked")
public void useUpdate() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    String hql = "from PrfOrderItem where deleted = :deleted and order.deleted = :deleted";
    Query query = session.createQuery(hql);
    query.setParameter("deleted", false);
    List<PrfOrderItem> items = (List<PrfOrderItem>) query.list();

    int i = 0;/*www.j  av a2  s.c  o  m*/
    for (PrfOrderItem item : items) {
        ++i;
        item.setCharge(item.getCharge().add(BigDecimal.ONE));
        session.update(item);
    }

    tr.commit();
    printTime("UPDATE " + i, time1, System.currentTimeMillis());
}

From source file:benchmark.BenchmarkHnU.java

License:Apache License

/** Create database and using DELETE */
@SuppressWarnings("unchecked")
public void useDelete() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    String hql = "from PrfOrder";
    Query query = session.createQuery(hql);
    List<PrfOrder> orders = (List<PrfOrder>) query.list();

    for (PrfOrder order : orders) {

        hql = "delete from PrfOrderItem it where it.order = :order";
        query = session.createQuery(hql);
        query.setParameter("order", order);
        int rows = query.executeUpdate();

        session.delete(order);/*  ww w. j av  a 2 s . co m*/
    }

    session.flush();

    hql = "delete from PrfUser";
    query = session.createQuery(hql);
    int rows = query.executeUpdate();

    tr.commit();
    printTime("DELETE", time1, System.currentTimeMillis());
}

From source file:bernardo.venda.controle.ProdutoControle.java

public List<Produto> findAllAbaixoStock() {
    String sql = "from Produto where quantidade_actual < quantidade_min and quantidade_actual !=0 order by descricao";
    Query query = getSession().createQuery(sql);
    List<Produto> l = query.list();
    return l;//from  ww  w .j  av a2 s. c  o  m
}

From source file:bgroup.oracle.dao.ContractDaoImpl.java

@Override
public Contract getContract(int PATIENT_ID) {
    logger.debug("Start getDog");

    Session session = getSession();/*  ww w .  ja va 2 s  . com*/
    logger.debug("session:" + session.toString());
    Query query = session.createSQLQuery("SELECT  p.KeyID as keyId"
            + ",(SELECT text FROM lu WHERE keyid = 93114) AS \"doverennost\""
            + ",(SELECT text FROM lu WHERE keyid = 93114) AS \"doverennost2\""
            + ",(SELECT text FROM lu WHERE keyid = 93114) AS \"doverennost3\""
            + ",(SELECT text FROM lu WHERE keyid = 93114) AS \"doverennost4\""
            + ",(SELECT text FROM lu WHERE keyid = 93116) AS \"license\""
            + ",(SELECT text FROM lu WHERE keyid = 93116) AS \"license2\""
            + ",(SELECT text FROM lu WHERE keyid = 93116) AS \"license3\""
            + ",(SELECT text FROM lu WHERE keyid = 93116) AS \"license4\""
            + ",fn_pat_name_by_id (p.KeyID) AS \"fio\"" + ",fn_pat_name_by_id (p.KeyID) AS \"fio2\""
            + ",fn_pat_name_by_id (p.KeyID) AS \"fio3\"" + ",fn_pat_name_by_id (p.KeyID) AS \"fio4\""
            + ",fn_pat_name_by_id (p.KeyID) AS \"fio5\"" + ",fn_pat_name_by_id (p.KeyID) AS \"fio6\""
            + ",p.num AS patnum" + ",p.num AS patnum2" + ",pkg_kladr.get_address(P.KeyID,1) AS \"region1\""
            + ",pkg_kladr.get_address(P.KeyID,1) AS \"address\""
            + ",pkg_kladr.get_address(P.KeyID,1) AS \"address2\""
            + ",pkg_kladr.get_address(P.KeyID,1) AS \"address3\""
            + ",pkg_kladr.get_address(P.KeyID,1) AS \"address4\"" + ",fn_pat_phone_by_id(p.keyid) AS phone"
            + ",fn_pat_phone_by_id(p.keyid) AS phone2" + ",decode (p.sex, 1, '.','.') AS sex_name"
            + ",fn_man_by_id (gsp_get_user_id()) AS registrator"
            + ",fn_man_by_id (gsp_get_user_id()) AS registrator2"
            + ",fn_man_by_id (gsp_get_user_id()) AS registrator3"
            + ",fn_man_by_id (gsp_get_user_id()) AS registrator4"
            + ",fn_man_by_id (gsp_get_user_id()) AS registrator5"
            + ",TO_CHAR (p.birthdate, 'dd-mm-yyyy') AS birth_date"
            + ", NVL ((SELECT c.text FROM company c,agr a WHERE a.keyid = p.agrid AND c.keyid = a.companyid),'') AS company"
            + ", NVL ((SELECT MAX('? ' || l.ser || ' N ' || l.code) FROM police l,agr a WHERE a.keyid = p.agrid "
            + "AND l.patientid = p.keyid AND l.agrid = a.keyid AND NVL (l.status,0) <> 1),'') AS police"
            + ", '' AS privils\n" + ",P.CELLULAR\n" + "FROM PATIENT p WHERE p.keyid = :PATIENT_ID")
            .setResultTransformer(Transformers.aliasToBean(Contract.class))
    //.addEntity(Contract.class)
    ;
    query.setParameter("PATIENT_ID", PATIENT_ID);
    //List<Object[]> result = null;
    List<Contract> result = null;
    try {
        result = query.list();
    } catch (Exception e) {
        logger.error(e.toString());
    }
    Contract contract = null;
    if (result != null && result.size() == 1) {
        logger.info("- ");
        return result.get(0);
        //for (Object[] row : result) {
        //  for (Contract row : result) {
        //contract = new Contract();
        //    try {
        //   contract = (Contract) row[0];
        // for (Object obj : row) {
        //   System.out.print(obj + "::");
        // }

        /*         int i = 0;
                
            contract.setKeyId(Integer.parseInt(row[i++].toString()));
            contract.setDoverennost(getRowValue(row[i++]));
            contract.setDoverennost2(getRowValue(row[i++]));
            contract.setDoverennost3(getRowValue(row[i++]));
            contract.setDoverennost4(getRowValue(row[i++]));
            contract.setLicense(getRowValue(row[i++]));
            contract.setLicense2(getRowValue(row[i++]));
            contract.setLicense3(getRowValue(row[i++]));
            contract.setLicense4(getRowValue(row[i++]));
            contract.setFio(getRowValue(row[i++]));
            contract.setFio2(getRowValue(row[i++]));
            contract.setFio3(getRowValue(row[i++]));
            contract.setFio4(getRowValue(row[i++]));
            contract.setFio5(getRowValue(row[i++]));
            contract.setFio6(getRowValue(row[i++]));
            contract.setPatnum(getRowValue(row[i++]));
            contract.setPatnum2(getRowValue(row[i++]));
            contract.setRegion1(getRowValue(row[i++]));
            contract.setAddress(getRowValue(row[i++]));
            contract.setAddress2(getRowValue(row[i++]));
            contract.setAddress3(getRowValue(row[i++]));
            contract.setAddress4(getRowValue(row[i++]));
            contract.setPhone(getRowValue(row[i++]));
            contract.setPhone2(getRowValue(row[i++]));
            contract.setSEX_NAME(getRowValue(row[i++]));
            contract.setRegistrator(getRowValue(row[i++]));
            contract.setREGISTRATOR2(getRowValue(row[i++]));
            contract.setREGISTRATOR3(getRowValue(row[i++]));
            contract.setREGISTRATOR4(getRowValue(row[i++]));
            contract.setREGISTRATOR5(getRowValue(row[i++]));
            contract.setBIRTH_DATE(getRowValue(row[i++]));
            contract.setCOMPANY(getRowValue(row[i++]));
            contract.setPOLICE(getRowValue(row[i++]));
            contract.setPRIVILS(getRowValue(row[i++]));
            contract.setCELLULAR(getRowValue(row[i++]));
            //System.out.println("\n");
            */
        //    } catch (Exception e) {
        //      logger.error(e.toString());
        //}

        // }
    } else {
        logger.info("  ");
    }
    return null;
}