Example usage for org.hibernate Criteria list

List of usage examples for org.hibernate Criteria list

Introduction

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

Prototype

public List list() throws HibernateException;

Source Link

Document

Get the results.

Usage

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

/**
 * This return both categories and the fields of phenodatasetfieldsDisplay tables.
 * Note:Not only the fields.          /*  ww  w . j ava2 s.c o  m*/
 */
@Override
public List<PhenoDataSetFieldDisplay> getPhenoDataSetFieldDisplayForPhenoDataSetFieldGroup(
        PhenoDataSetGroup phenoDataSetGroup) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroup));
    //Ordering first from the category and then from the field
    criteria.addOrder(Order.asc("phenoDataSetCategoryOrderNumber"))
            .addOrder(Order.asc("phenoDataSetFiledOrderNumber"));
    return criteria.list();
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public void deletePickedCategoriesAndAllTheirChildren(Study study, ArkFunction arkFunction, ArkUser arkUser) {
    //Delete all fields
    Criteria criteriaField = getSession().createCriteria(LinkPhenoDataSetCategoryField.class);
    criteriaField.add(Restrictions.eq("study", study));
    criteriaField.add(Restrictions.eq("arkFunction", arkFunction));
    criteriaField.add(Restrictions.eq("arkUser", arkUser));
    List<LinkPhenoDataSetCategoryField> linkPhenoDataSetCategoryFields = (List<LinkPhenoDataSetCategoryField>) criteriaField
            .list();//from   w  w w .  j  av  a 2 s  .c om
    for (LinkPhenoDataSetCategoryField linkPhenoDataSetCategoryField : linkPhenoDataSetCategoryFields) {
        getSession().delete(linkPhenoDataSetCategoryField);
    }
    //Delete all categories.
    Criteria criteriaCategory = getSession().createCriteria(PickedPhenoDataSetCategory.class);
    criteriaCategory.add(Restrictions.eq("study", study));
    criteriaCategory.add(Restrictions.eq("arkFunction", arkFunction));
    criteriaCategory.add(Restrictions.eq("arkUser", arkUser));
    List<PickedPhenoDataSetCategory> pickedPhenoDataSetCategories = (List<PickedPhenoDataSetCategory>) criteriaCategory
            .list();
    for (PickedPhenoDataSetCategory pickedPhenoDataSetCategory : pickedPhenoDataSetCategories) {
        getSession().delete(pickedPhenoDataSetCategory);
    }
    getSession().flush();
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public List<PhenoDataSetGroup> getPhenoDataSetFieldGroups(PhenoDataSetGroup phenoDataSetGroup, int first,
        int count) {

    Criteria criteria = buildGenericPhenoFieldGroupCriteria(phenoDataSetGroup);
    criteria.setFirstResult(first);//from   w  w  w. j  a  va2  s. co m
    criteria.setMaxResults(count);
    List<PhenoDataSetGroup> list = (List<PhenoDataSetGroup>) criteria.list();
    return list;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public List<PhenoDataSetFieldDisplay> getPhenoDataSetFieldDisplayForPhenoDataSetFieldGroupOrderByPhenoDataSetCategory(
        PhenoDataSetGroup phenoDataSetGroup) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroup));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("phenoDataSetGroup"), "phenoDataSetGroup");
    projectionList.add(Projections.groupProperty("phenoDataSetCategory"), "phenoDataSetCategory");
    projectionList.add(Projections.groupProperty("parentPhenoDataSetCategory"), "parentPhenoDataSetCategory");
    projectionList.add(Projections.groupProperty("phenoDataSetCategoryOrderNumber"),
            "phenoDataSetCategoryOrderNumber");
    criteria.setProjection(projectionList);
    criteria.addOrder(Order.asc("phenoDataSetCategoryOrderNumber"));
    criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetFieldDisplay.class));
    return (List<PhenoDataSetFieldDisplay>) criteria.list();
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public List<PhenoDataSetField> getPhenoDataSetFieldsLinkedToPhenoDataSetFieldGroupAndPhenoDataSetCategory(
        PhenoDataSetGroup phenoDataSetGroupCriteria, PhenoDataSetCategory phenoDataSetCategory) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroupCriteria));
    criteria.add(Restrictions.eq("phenoDataSetCategory", phenoDataSetCategory));
    criteria.add(Restrictions.isNotNull("phenoDataSetField"));
    criteria.addOrder(Order.asc("phenoDataSetFiledOrderNumber"));
    List<PhenoDataSetFieldDisplay> phenoDataSetFieldDisplays = (List<PhenoDataSetFieldDisplay>) criteria.list();
    List<PhenoDataSetField> phenoDataSetFields = new ArrayList<PhenoDataSetField>();
    for (PhenoDataSetFieldDisplay phenoDataSetFieldDisplay : phenoDataSetFieldDisplays) {
        phenoDataSetFields.add(phenoDataSetFieldDisplay.getPhenoDataSetField());
    }/*www.ja v  a 2s.  c o  m*/
    return phenoDataSetFields;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public List<Boolean> getPublishedSatusLst(Study study, ArkFunction arkFunction) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetGroup.class);
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("arkFunction", arkFunction));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("published"), "published");
    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetGroup.class));
    List<PhenoDataSetGroup> phenoDataSetGroups = (List<PhenoDataSetGroup>) criteria.list();
    List<Boolean> pubishStatusLst = new ArrayList<Boolean>();
    for (PhenoDataSetGroup phenoDataSetGroup : phenoDataSetGroups) {
        pubishStatusLst.add(phenoDataSetGroup.getPublished());
    }/*w  w  w .  j  a v  a 2  s  . c o m*/
    return pubishStatusLst;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public boolean isPhenoDataSetFieldCategoryBeingUsed(PhenoDataSetCategory phenoDataSetCategory) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetCategory", phenoDataSetCategory));
    return ((List<PhenoDataSetFieldDisplay>) criteria.list()).size() > 0;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public List<PhenoDataSetField> getAllPhenoDataSetFieldsLinkedToPhenoDataSetFieldGroup(
        PhenoDataSetGroup phenoDataSetGroupCriteria) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroupCriteria));
    criteria.add(Restrictions.isNotNull("phenoDataSetField"));
    criteria.addOrder(Order.asc("phenoDataSetCategoryOrderNumber"))
            .addOrder(Order.asc("phenoDataSetFiledOrderNumber"));
    List<PhenoDataSetFieldDisplay> phenoDataSetFieldDisplays = (List<PhenoDataSetFieldDisplay>) criteria.list();
    List<PhenoDataSetField> phenoDataSetFields = new ArrayList<PhenoDataSetField>();
    for (PhenoDataSetFieldDisplay phenoDataSetFieldDisplay : phenoDataSetFieldDisplays) {
        phenoDataSetFields.add(phenoDataSetFieldDisplay.getPhenoDataSetField());
    }/*from w  w  w .ja  v a 2s. co  m*/
    return phenoDataSetFields;
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public Map<String, Long> getSubjectStatusCounts(Study study) {
    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class);
    criteria.add(Restrictions.eq("study", study));
    ProjectionList projectionList = Projections.projectionList();
    criteria.createAlias("subjectStatus", "subjectStatusAlias");
    projectionList.add(Projections.groupProperty("subjectStatusAlias.name"));
    projectionList.add(Projections.rowCount());
    criteria.setProjection(projectionList);
    List results = criteria.list();
    Map<String, Long> statusMap = new HashMap<String, Long>();
    for (Object r : results) {
        Object[] obj = (Object[]) r;
        String statusName = (String) obj[0];
        statusMap.put(statusName, (Long) obj[1]);
    }/*from   w  w  w .j  av  a2  s.  c  o  m*/
    return statusMap;
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public Map<String, Long> getStudyConsentCounts(Study study) {
    Map<String, Long> statusMap = new HashMap<String, Long>();

    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class);
    criteria.add(Restrictions.eq("study", study));
    ProjectionList projectionList = Projections.projectionList();
    criteria.createAlias("consentStatus", "consentStatusAlias");
    projectionList.add(Projections.groupProperty("consentStatusAlias.name"));
    projectionList.add(Projections.rowCount());
    criteria.setProjection(projectionList);
    List results = criteria.list();
    for (Object r : results) {
        Object[] obj = (Object[]) r;
        String statusName = (String) obj[0];
        statusMap.put(statusName, (Long) obj[1]);
    }// ww w .  j  av  a2s .  c o m

    // Tack on count of when consentStatus = undefined (NULL)
    criteria = getSession().createCriteria(LinkSubjectStudy.class);
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.isNull("consentStatus"));
    projectionList = Projections.projectionList();
    projectionList.add(Projections.rowCount());
    criteria.setProjection(projectionList);
    Long undefCount = (Long) criteria.uniqueResult();
    String statusName = Constants.NOT_CONSENTED;
    statusMap.put(statusName, undefCount);

    return statusMap;
}