Example usage for org.hibernate Criteria setProjection

List of usage examples for org.hibernate Criteria setProjection

Introduction

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

Prototype

public Criteria setProjection(Projection projection);

Source Link

Document

Used to specify that the query results will be a projection (scalar in nature).

Usage

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

License:Open Source License

public long getCFDLinkedToQuestionnaireCount(PhenoDataSetGroup phenoDataSetGroup) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroup));
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult();
}

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

License:Open Source License

public List<PhenoDataSetGroup> getPhenoDataSetGroupsByLinkSubjectStudy(LinkSubjectStudy linkSubjectStudy) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetCollection.class);
    criteria.add(Restrictions.eq("linkSubjectStudy", linkSubjectStudy));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("questionnaire"), "questionnaire");
    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetCollection.class));
    List<PhenoDataSetCollection> phenoDataSetCollections = (List<PhenoDataSetCollection>) criteria.list();
    List<PhenoDataSetGroup> phenoDataSetGroups = new ArrayList<PhenoDataSetGroup>();
    for (PhenoDataSetCollection phenoDataSetCollection : phenoDataSetCollections) {
        phenoDataSetGroups.add(phenoDataSetCollection.getQuestionnaire());
    }/* w  ww.jav  a2  s.  co  m*/
    return phenoDataSetGroups;
}

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

License:Open Source License

@Override
public long getPhenoDataSetCategoryCount(PhenoDataSetCategory phenoDataSetCategoryCriteria) {
    // Handle for study or function not in context
    if (phenoDataSetCategoryCriteria.getStudy() == null
            || phenoDataSetCategoryCriteria.getArkFunction() == null) {
        return 0;
    }/*from w w  w.j  a va2s.  c o  m*/
    Criteria criteria = buildGeneralPhenoDataSetCategoryCritera(phenoDataSetCategoryCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

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

License:Open Source License

public long getPhenoFieldCount(PhenoDataSetField phenofieldcriteria) {
    // Handle for study or function not in context
    if (phenofieldcriteria.getStudy() == null || phenofieldcriteria.getArkFunction() == null) {
        return 0;
    }/*from  ww w. ja v  a  2  s.c  om*/
    Criteria criteria = buildGeneralPhenoFieldCritera(phenofieldcriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

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

License:Open Source License

@Override
public List<PhenoDataSetField> getPhenoDataSetFieldsLinkedToPhenoDataSetFieldGroup(
        PhenoDataSetGroup phenoDataSetGroupCriteria) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroupCriteria));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("phenoDataSetField"));
    criteria.setProjection(projectionList);
    criteria.addOrder(Order.asc("phenoDataSetFiledOrderNumber"));
    List<PhenoDataSetField> fieldsList = criteria.list();
    return fieldsList;
}

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

License:Open Source License

@Override
public long getPhenoDataSetFieldGroupCount(PhenoDataSetGroup phenoDataSetGroup) {
    // Handle for study or function not in context
    if (phenoDataSetGroup.getStudy() == null || phenoDataSetGroup.getArkFunction() == null) {
        return 0L;
    }/*from   w w  w.j ava 2  s .com*/
    Criteria criteria = buildGenericPhenoDataSetFieldGroupCriteria(phenoDataSetGroup);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

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

License:Open Source License

@Override
public Long getNextAvailbleNumberForPickedCategory(Study study, ArkFunction arkFunction, ArkUser arkUser) {
    Long maxNumber;/*from  w  w w.j a  v a  2 s  .c  om*/
    Criteria criteria = getSession().createCriteria(PickedPhenoDataSetCategory.class);
    criteria.add(Restrictions.eq("arkFunction", arkFunction));
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("arkUser", arkUser));
    //criteria.add(Restrictions.isNull("parentPickedPhenoDataSetCategory"));
    criteria.setProjection(Projections.max("orderNumber"));
    maxNumber = (Long) criteria.uniqueResult();
    if (maxNumber != null) {
        return ++maxNumber;
    } else {
        return new Long(1);
    }

}

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

License:Open Source License

@Override
public Long getNextAvailbleNumberForAssignedField(Study study, ArkFunction arkFunction, ArkUser arkUser,
        PhenoDataSetCategory phenoDataSetCategory) {
    Long maxNumber;//from   ww  w  .  j ava  2 s .co  m
    Criteria criteria = getSession().createCriteria(LinkPhenoDataSetCategoryField.class);
    criteria.add(Restrictions.eq("arkFunction", arkFunction));
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("arkUser", arkUser));
    criteria.add(Restrictions.eq("phenoDataSetCategory", phenoDataSetCategory));
    criteria.setProjection(Projections.max("orderNumber"));
    maxNumber = (Long) criteria.uniqueResult();
    if (maxNumber != null) {
        return ++maxNumber;
    } else {
        return new Long(1);
    }
}

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

License:Open Source License

@Override
public long getPhenoFieldGroupCount(Study study, ArkFunction arkFunction, Boolean status) {
    // Handle for study or function not in context
    /*if (phenoDataSetGroup.getStudy() == null || phenoDataSetGroup.getArkFunction() == null) {
       return 0L;//from   w ww.j av  a 2s.c o  m
    }*/
    //Criteria criteria = buildGenericPhenoFieldGroupCriteria(phenoDataSetGroup);
    Criteria criteria = getSession().createCriteria(PhenoDataSetGroup.class);
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("arkFunction", arkFunction));
    criteria.add(Restrictions.eq("published", true));
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

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();
}