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:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

/**
 * <p>//from w  ww  . j  ava2s  .c o m
 * Builds a HQL to Left Join wtih SubjectCustomFieldData and applies a condition using the WITH clause to get a sub-set for the given Subject and
 * then applies the restrictions on study and module.
 * </p>
 */
public List<FamilyCustomFieldData> getFamilyCustomFieldDataList(LinkSubjectStudy linkSubjectStudyCriteria,
        ArkFunction arkFunction, CustomFieldCategory customFieldCategory, CustomFieldType customFieldType,
        int first, int count) {

    List<FamilyCustomFieldData> familyCustomFieldDataList = new ArrayList<FamilyCustomFieldData>();

    StringBuffer sb = new StringBuffer();

    sb.append("SELECT cfd, fieldList");
    sb.append(" FROM  CustomFieldDisplay AS cfd ");
    sb.append("LEFT JOIN cfd.customField AS cf ");
    sb.append("LEFT JOIN cf.customFieldType AS cft ");
    sb.append("LEFT JOIN cfd.familyCustomFieldData as fieldList ");
    sb.append(" with fieldList.familyUid = :familyUid ");
    sb.append("  where cfd.customField.study.id = :studyId");
    sb.append(" and cfd.customField.arkFunction.id = :functionId");
    //Add new requirement for the category
    if (customFieldCategory != null) {
        sb.append(" and cfd.customField.customFieldCategory.id = :customFieldCategotyId");
    }
    //      if(type == null || "SUBJECT".equalsIgnoreCase(type)){
    //         sb.append(" and (cft is null or cft.name = :type)");
    //      }else{
    sb.append(" and cft.name = :type");
    //      }
    sb.append(" order by cfd.sequence");

    Query query = getSession().createQuery(sb.toString());
    query.setParameter("familyUid", getSubjectFamilyUId(linkSubjectStudyCriteria.getStudy().getId(),
            linkSubjectStudyCriteria.getSubjectUID()));
    query.setParameter("studyId", linkSubjectStudyCriteria.getStudy().getId());
    query.setParameter("functionId", arkFunction.getId());
    //Add type and category
    if (customFieldCategory != null) {
        query.setParameter("customFieldCategotyId", customFieldCategory.getId());
    }
    query.setParameter("type", customFieldType.getName());
    query.setFirstResult(first);
    query.setMaxResults(count);

    List<Object[]> listOfObjects = query.list();
    for (Object[] objects : listOfObjects) {
        CustomFieldDisplay cfd = new CustomFieldDisplay();
        FamilyCustomFieldData fcfd = new FamilyCustomFieldData();
        if (objects.length > 0 && objects.length >= 1) {

            cfd = (CustomFieldDisplay) objects[0];
            if (objects[1] != null) {
                fcfd = (FamilyCustomFieldData) objects[1];
            } else {
                fcfd.setCustomFieldDisplay(cfd);
            }

            familyCustomFieldDataList.add(fcfd);
        }
    }
    return familyCustomFieldDataList;
}

From source file:au.org.theark.study.model.dao.UserDao.java

License:Open Source License

public List<Person> searchPerson(Person personVO) throws PersonNotFoundException {
    // Return all persons
    String queryString = "from Person";
    Query query = getSession().createQuery(queryString);
    List<Person> personList = query.list();
    return personList;
}

From source file:automata.gui.BuscaAutomata.java

private void Carga_Inicial() {
    try {/*from w w w.  j a v a  2 s  . co m*/
        Transaction transaction = session.beginTransaction();
        Query q = session.createQuery("from Estado e where e.inicial = true");
        miEstado = (Estado) q.list().get(0);
        txtEstado.setText(miEstado.getStrEstado());
        transaction.commit();
    } catch (HibernateException he) {
        JOptionPane.showMessageDialog(null, "Error: " + he.getMessage());
    }
}

From source file:automata.gui.IngresoAutomata.java

private void Update_Estado() {
    try {/* w w w .  j a  v  a  2  s  .c  o m*/
        Transaction transaction = session.beginTransaction();
        Query query = session.createQuery(
                "from Transicion t where t.idTransicion = " + cbTransiciones.getSelectedItem().toString());
        Transicion transicion = (Transicion) query.list().get(0);
        session.update(transicion);
        transicion.setIdEstadoSiguiente(miEstado.getIdEstado());
        transaction.commit();
    } catch (HibernateException he) {
        JOptionPane.showMessageDialog(null, "Erro update: " + he.getMessage());
    }
}

From source file:automata.gui.IngresoAutomata.java

private void Carga_Box() {
    Query q = session.createQuery("from Transicion");
    List resultList = q.list();
    for (Object o : resultList) {
        Transicion transicion = (Transicion) o;
        cbTransiciones.addItem(transicion.getIdTransicion());
    }//from w w  w .ja  va2 s .  co m
}

From source file:automatedbillingsoftware_DA.Categories_DA.java

public List<Categories> searchCategories(String searchKeyWord) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createSQLQuery("Select * from categories_tbl  where catName like  '%" + searchKeyWord
            + "%' OR catDesc like  '%" + searchKeyWord + "%'AND status=1");
    Categories category = new Categories();
    List list = query.list();
    List<Categories> catList = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
        Object[] cat = (Object[]) list.get(i);
        int id = (Integer) cat[0];
        String name = (String) cat[3];
        String description = (String) cat[1];
        Date dt = (Date) cat[2];
        int status = (Integer) cat[5];
        double discount = (Double) cat[4];
        category = new Categories();
        category.setCatDesc(description);
        category.setCatName(name);//  w w w .jav a2  s  .  c o m
        category.setCatModifiedDate(dt);
        category.setDiscount(discount);
        category.setStatus(status);
        category.setCatid(id);
        catList.add(category);

    }

    beginTransaction.commit();
    return catList;
}

From source file:automatedbillingsoftware_DA.Categories_DA.java

public List<Categories> fetchCategorieses() {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Categories c where c.status=:status");
    query.setParameter("status", 1);
    List<Categories> catList = (List<Categories>) query.list();
    beginTransaction.commit();//from   w ww. ja v a  2s  . c o  m
    return catList;
}

From source file:automatedbillingsoftware_DA.Categories_DA.java

public Categories fetchCategoryByName(String name) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Categories c where c.status=:status AND c.catName LIKE :name");
    query.setParameter("status", 1);
    query.setParameter("name", name);
    List<Categories> catList = (List<Categories>) query.list();
    beginTransaction.commit();/* w  w  w  .j  a  v  a2s.  c  o  m*/
    if (catList.size() > 0)
        return catList.get(0);
    else
        return null;
}

From source file:automatedbillingsoftware_DA.Categories_DA.java

public Categories fetchCategoryById(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Categories c where c.catid =:catid AND c.status=:status");
    query.setParameter("catid", id);
    query.setParameter("status", 1);
    List<Categories> catList = (List<Categories>) query.list();
    Categories cat = new Categories();
    if (catList.size() > 0) {
        cat = catList.get(0);/*from   ww  w.j  av  a  2 s.  c o  m*/
    }
    beginTransaction.commit();
    return cat;
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public ChallanGenerated fetchChallanGenById(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from ChallanGenerated where status=:status and id=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<ChallanGenerated> challanList = (List<ChallanGenerated>) query.list();
    beginTransaction.commit();//w  w w . j  a  v a2  s  . com

    return (challanList == null || challanList.size() == 0) ? null : challanList.get(0);
}