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.report.model.dao.ReportDao.java

License:Open Source License

public List<CustomFieldDetailsDataRow> getPhenoCustomFieldDetailsList(CustomFieldDetailsReportVO fdrVO) {
    List<CustomFieldDetailsDataRow> results = new ArrayList<CustomFieldDetailsDataRow>();
    if (fdrVO.getCustomFieldDisplay() != null) {
        /*//from  w  ww  .ja v  a  2s . co  m
         * Following query returns customFields whether or not they are 
         * associated with a customFieldGroups (via customFieldDisplay)
         */
        Criteria criteria = getSession().createCriteria(CustomField.class, "cf");
        criteria.createAlias("customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldDisplay
        criteria.createAlias("cfd.customFieldGroup", "cfg", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldGroup
        criteria.createAlias("fieldType", "ft", JoinType.LEFT_OUTER_JOIN); // Left join to FieldType
        criteria.createAlias("unitType", "ut", JoinType.LEFT_OUTER_JOIN); // Left join to UnitType
        criteria.add(Restrictions.eq("cf.study", fdrVO.getStudy()));
        ArkFunction function = iArkCommonService
                .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_PHENO_COLLECTION);
        criteria.add(Restrictions.eq("cf.arkFunction", function));

        if (fdrVO.getCustomFieldDisplay().getCustomFieldGroup() != null) {
            criteria.add(
                    Restrictions.eq("cfg.id", fdrVO.getCustomFieldDisplay().getCustomFieldGroup().getId()));
        }
        if (fdrVO.getFieldDataAvailable()) {
            DetachedCriteria fieldDataCriteria = DetachedCriteria.forClass(PhenoDataSetData.class, "pd");
            // Join CustomFieldDisplay and PhenoData on ID FK
            fieldDataCriteria.add(Property.forName("cfd.id").eqProperty("pd." + "customFieldDisplay.id"));
            criteria.add(Subqueries
                    .exists(fieldDataCriteria.setProjection(Projections.property("pd.customFieldDisplay"))));
        }

        ProjectionList projectionList = Projections.projectionList();
        projectionList.add(Projections.property("cfg.name"), "questionnaire");
        projectionList.add(Projections.property("cf.name"), "fieldName");
        projectionList.add(Projections.property("cf.description"), "description");
        projectionList.add(Projections.property("cf.minValue"), "minValue");
        projectionList.add(Projections.property("cf.maxValue"), "maxValue");
        projectionList.add(Projections.property("cf.encodedValues"), "encodedValues");
        projectionList.add(Projections.property("cf.missingValue"), "missingValue");
        projectionList.add(Projections.property("ut.name"), "units");
        projectionList.add(Projections.property("ft.name"), "type");

        criteria.setProjection(projectionList); // only return fields required for report
        criteria.setResultTransformer(Transformers.aliasToBean(CustomFieldDetailsDataRow.class));
        criteria.addOrder(Order.asc("cfg.id"));
        criteria.addOrder(Order.asc("cfd.sequence"));
        results = criteria.list();
    }

    return results;
}

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

License:Open Source License

public List<PhenoDataSetFieldDetailsDataRow> getPhenoDataSetFieldDetailsList(
        PhenoDataSetFieldDetailsReportVO reportVO) {
    List<PhenoDataSetFieldDetailsDataRow> results = new ArrayList<PhenoDataSetFieldDetailsDataRow>();
    if (reportVO.getPhenoDataSetFieldDisplay() != null) {
        /*/*from w  ww .jav  a 2  s  . com*/
         * Following query returns customFields whether or not they are
         * associated with a customFieldGroups (via customFieldDisplay)
         */
        Criteria criteria = getSession().createCriteria(PhenoDataSetField.class, "pf");
        criteria.createAlias("phenoDatasetFieldDisplay", "pdfd", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldDisplay
        criteria.createAlias("pdfd.phenoDatasetFieldGroup", "pdfg", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldGroup
        criteria.createAlias("fieldType", "ft", JoinType.LEFT_OUTER_JOIN); // Left join to FieldType
        criteria.createAlias("unitType", "ut", JoinType.LEFT_OUTER_JOIN); // Left join to UnitType
        criteria.add(Restrictions.eq("pf.study", reportVO.getStudy()));
        ArkFunction function = iArkCommonService
                .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_PHENO_COLLECTION);
        criteria.add(Restrictions.eq("pf.arkFunction", function));

        if (reportVO.getPhenoDataSetFieldDisplay().getPhenoDataSetGroup() != null) {
            criteria.add(Restrictions.eq("pdfg.id",
                    reportVO.getPhenoDataSetFieldDisplay().getPhenoDataSetGroup().getId()));
        }
        if (reportVO.getFieldDataAvailable()) {
            DetachedCriteria fieldDataCriteria = DetachedCriteria.forClass(PhenoDataSetData.class, "pd");
            // Join CustomFieldDisplay and PhenoData on ID FK
            fieldDataCriteria
                    .add(Property.forName("pdfd.id").eqProperty("pd." + "phenoDatasetFieldDisplay.id"));
            criteria.add(Subqueries.exists(
                    fieldDataCriteria.setProjection(Projections.property("pd.phenoDatasetFieldDisplay"))));
        }

        ProjectionList projectionList = Projections.projectionList();
        projectionList.add(Projections.property("pdfg.name"), "questionnaire");
        projectionList.add(Projections.property("pf.name"), "fieldName");
        projectionList.add(Projections.property("pf.description"), "description");
        projectionList.add(Projections.property("pf.minValue"), "minValue");
        projectionList.add(Projections.property("pf.maxValue"), "maxValue");
        projectionList.add(Projections.property("pf.encodedValues"), "encodedValues");
        projectionList.add(Projections.property("pf.missingValue"), "missingValue");
        projectionList.add(Projections.property("ut.name"), "units");
        projectionList.add(Projections.property("ft.name"), "type");

        criteria.setProjection(projectionList); // only return fields required for report
        criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetFieldDetailsDataRow.class));
        criteria.addOrder(Order.asc("pdfg.id"));
        criteria.addOrder(Order.asc("pdfd.sequence"));
        results = criteria.list();
    }

    return results;
}

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

License:Open Source License

public List<PhenoDataSetGroup> getQuestionnaireList(Study study) {
    List<PhenoDataSetGroup> results = null;
    Criteria criteria = getSession().createCriteria(PhenoDataSetGroup.class);
    criteria.add(Restrictions.eq("study", study));
    ArkFunction function = iArkCommonService
            .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_PHENO_COLLECTION);
    criteria.add(Restrictions.eq("arkFunction", function));
    results = criteria.list();
    return results;
}

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

License:Open Source License

public List<ResearcherCostDataRow> getResearcherBillableItemTypeCostData(
        final ResearcherCostResportVO researcherCostResportVO) {
    List<ResearcherCostDataRow> results = new ArrayList<ResearcherCostDataRow>();
    Criteria criteria = getSession().createCriteria(BillableItem.class, "bi");
    criteria.createAlias("workRequest", "wr", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("billableItemType", "bit", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bit.billableItemTypeStatus", "bitst", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("wr.researcher", "re", JoinType.LEFT_OUTER_JOIN);

    criteria.add(Restrictions.eq("re.id", researcherCostResportVO.getResearcherId()));
    criteria.add(Restrictions.eq("bi.studyId", researcherCostResportVO.getStudyId()));
    criteria.add(Restrictions.eq("bi.invoice", researcherCostResportVO.getInvoice()));
    criteria.add(Restrictions.le("bi.commenceDate", researcherCostResportVO.getToDate()));
    criteria.add(Restrictions.ge("bi.commenceDate", researcherCostResportVO.getFromDate()));
    criteria.add(Restrictions.eq("bitst.name", "ACTIVE"));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("bit.id"));
    projectionList.add(Projections.property("bit.itemName"), "costType");
    projectionList.add(Projections.sum("bi.totalCost"), "totalCost");
    projectionList.add(Projections.sum("bi.totalGST"), "totalGST");

    criteria.setProjection(projectionList); // only return fields required for report
    criteria.setResultTransformer(Transformers.aliasToBean(ResearcherCostDataRow.class));

    criteria.addOrder(Order.asc("bit.itemName"));
    results = criteria.list();
    return results;
}

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

License:Open Source License

public List<Researcher> searchResearcherByStudyId(final Long studyId) {
    Criteria criteria = getSession().createCriteria(Researcher.class);
    criteria.add(Restrictions.eq("studyId", studyId));
    List<Researcher> list = criteria.list();
    return list;//from   w  w w.  jav  a 2  s .c o m
}

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

License:Open Source License

public List<ResearcherDetailCostDataRow> getBillableItemDetailCostData(
        ResearcherCostResportVO researcherCostResportVO) {
    List<ResearcherDetailCostDataRow> results = new ArrayList<ResearcherDetailCostDataRow>();
    Criteria criteria = getSession().createCriteria(BillableItem.class, "bi");
    criteria.createAlias("workRequest", "wr", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("billableItemType", "bit", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("wr.researcher", "re", JoinType.LEFT_OUTER_JOIN);

    if (researcherCostResportVO.getResearcherId() != null) {
        criteria.add(Restrictions.eq("re.id", researcherCostResportVO.getResearcherId()));
    }/*w  w w.  j a v  a2  s  .c om*/

    criteria.add(Restrictions.eq("bi.studyId", researcherCostResportVO.getStudyId()));
    criteria.add(Restrictions.eq("bi.invoice", researcherCostResportVO.getInvoice()));
    criteria.add(Restrictions.le("bi.commenceDate", researcherCostResportVO.getToDate()));
    criteria.add(Restrictions.ge("bi.commenceDate", researcherCostResportVO.getFromDate()));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("bi.description"), "description");
    projectionList.add(Projections.property("bi.commenceDate"), "commencedDate");
    projectionList.add(Projections.property("bi.invoice"), "invoice");
    projectionList.add(Projections.property("bi.quantity"), "quantity");
    projectionList.add(Projections.property("bi.totalCost"), "totalAmount");
    projectionList.add(Projections.property("bi.totalGST"), "totalGST");
    projectionList.add(Projections.property("bit.itemName"), "itemType");
    projectionList.add(Projections.property("bit.id"), "typeId");
    projectionList.add(Projections.property("bit.quantityType"), "quantityType");
    projectionList.add(Projections.property("wr.gstAllow"), "gstAllowed");

    projectionList.add(Projections.property("wr.name"), "requestName");

    criteria.setProjection(projectionList); // only return fields required for report
    criteria.setResultTransformer(Transformers.aliasToBean(ResearcherDetailCostDataRow.class));
    criteria.addOrder(Order.asc("bit.id"));
    criteria.addOrder(Order.asc("bi.commenceDate"));
    results = criteria.list();
    return results;
}

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

License:Open Source License

public List<BiospecimenSummaryDataRow> getBiospecimenSummaryData(
        BiospecimenSummaryReportVO biospecimenSummaryReportVO) {
    List<BiospecimenSummaryDataRow> results = new ArrayList<BiospecimenSummaryDataRow>();

    Criteria criteria = getSession().createCriteria(BioTransaction.class, "bt");

    criteria.createAlias("status", "bts", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("biospecimen", "bs", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bs.study", "st", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bs.linkSubjectStudy", "lss", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bs.sampleType", "sat", JoinType.LEFT_OUTER_JOIN);

    criteria.add(Restrictions.eq("st.id", biospecimenSummaryReportVO.getStudy().getId()));
    if (biospecimenSummaryReportVO.getSubjectUID() != null) {
        criteria.add(Restrictions.eq("lss.subjectUID", biospecimenSummaryReportVO.getSubjectUID()));
    }/*from ww w . j  a va2  s.  c  o  m*/

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.min("bt.id"));
    projectionList.add(Projections.groupProperty("bs.id"));

    projectionList.add(Projections.property("st.name"), "studyName");
    projectionList.add(Projections.property("lss.subjectUID"), "subjectUId");
    projectionList.add(Projections.property("bs.id"), "biospecimenId");
    projectionList.add(Projections.property("bs.biospecimenUid"), "biospecimenUid");
    projectionList.add(Projections.property("bs.parentUid"), "parentId");
    projectionList.add(Projections.property("sat.name"), "sampleType");
    projectionList.add(Projections.property("bs.quantity"), "quantity");
    projectionList.add(Projections.property("bts.name"), "initialStatus");

    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(BiospecimenSummaryDataRow.class));
    criteria.addOrder(Order.asc("lss.subjectUID"));
    criteria.addOrder(Order.asc("bs.biospecimenUid"));
    results = criteria.list();

    return results;
}

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

License:Open Source License

public List<BiospecimenDetailsDataRow> getBiospecimenDetailsData(
        BiospecimenDetailsReportVO biospecimenDetailReportVO) {
    List<BiospecimenDetailsDataRow> results = new ArrayList<BiospecimenDetailsDataRow>();

    Criteria criteria = getSession().createCriteria(BioTransaction.class, "bt");

    criteria.createAlias("status", "bts", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("biospecimen", "bs", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bs.study", "st", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bs.bioCollection", "bc", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bs.linkSubjectStudy", "lss", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bs.sampleType", "sat", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bs.invCell", "inc", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("inc.invBox", "inb", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("inb.invRack", "inr", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("inr.invFreezer", "inf", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("inf.invSite", "ins", JoinType.LEFT_OUTER_JOIN);

    criteria.add(Restrictions.eq("st.id", biospecimenDetailReportVO.getStudy().getId()));
    if (biospecimenDetailReportVO.getSubjectUID() != null) {
        criteria.add(Restrictions.eq("lss.subjectUID", biospecimenDetailReportVO.getSubjectUID()));
    }/*from  w w w. j a v  a2  s .  c om*/

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.min("bt.id"));
    projectionList.add(Projections.groupProperty("bs.id"));

    projectionList.add(Projections.property("st.name"), "studyName");
    projectionList.add(Projections.property("lss.subjectUID"), "subjectUId");
    projectionList.add(Projections.property("bs.id"), "biospecimenId");
    projectionList.add(Projections.property("bc.biocollectionUid"), "biocollectionUid");
    projectionList.add(Projections.property("bs.sampleDate"), "sampleDate");
    projectionList.add(Projections.property("bs.biospecimenUid"), "biospecimenUid");
    projectionList.add(Projections.property("bs.parentUid"), "parentId");
    projectionList.add(Projections.property("sat.name"), "sampleType");
    projectionList.add(Projections.property("bs.quantity"), "quantity");
    projectionList.add(Projections.property("bts.name"), "initialStatus");

    projectionList.add(Projections.property("inb.name"), "box");
    projectionList.add(Projections.property("inr.name"), "rack");
    projectionList.add(Projections.property("inf.name"), "freezer");
    projectionList.add(Projections.property("ins.name"), "site");

    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(BiospecimenDetailsDataRow.class));
    criteria.addOrder(Order.asc("lss.subjectUID"));
    criteria.addOrder(Order.asc("bs.biospecimenUid"));
    results = criteria.list();

    return results;
}

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

License:Open Source License

public List<StudyStatus> getListOfStudyStatus() {
    Example studyStatus = Example.create(new StudyStatus());
    Criteria studyStatusCriteria = getSession().createCriteria(StudyStatus.class).add(studyStatus);
    return studyStatusCriteria.list();
}

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

License:Open Source License

/**
 * Given a status name will return the StudyStatus object.
 *//*from w  ww.ja  v a  2s .com*/
public StudyStatus getStudyStatus(String statusName) throws StatusNotAvailableException {
    StudyStatus studyStatus = new StudyStatus();
    studyStatus.setName("Archive");
    Example studyStatusExample = Example.create(studyStatus);

    Criteria studyStatusCriteria = getSession().createCriteria(StudyStatus.class).add(studyStatusExample);
    if (studyStatusCriteria != null && studyStatusCriteria.list() != null
            && studyStatusCriteria.list().size() > 0) {
        return (StudyStatus) studyStatusCriteria.list().get(0);
    } else {
        log.error("Study Status Table maybe out of synch. Please check if it has an entry for Archive status");
        System.out.println("Cannot locate a study status with " + statusName + " in the database");
        throw new StatusNotAvailableException();
    }
}