Example usage for org.hibernate Criteria createAlias

List of usage examples for org.hibernate Criteria createAlias

Introduction

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

Prototype

@Deprecated
public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException;

Source Link

Document

Join an association using the specified join-type, assigning an alias to the joined association.

Usage

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 va 2  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  va2 s  .  co  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("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<Correspondences> getCorrespondenceList(LinkSubjectStudy lss, Correspondences correspondence)
        throws ArkSystemException {

    Criteria criteria = getSession().createCriteria(Correspondences.class, "co");
    criteria.createAlias("lss", "lss", JoinType.LEFT_OUTER_JOIN);
    //criteria.createAlias("study", "st", JoinType.LEFT_OUTER_JOIN);
    //criteria.createAlias("st.parentStudy", "pstudy", JoinType.LEFT_OUTER_JOIN);

    if (lss != null) {
        criteria.add(Restrictions.eq("lss", lss));
    }//from ww w. ja v  a 2 s .c o m

    if (correspondence != null) {

        // Check context study is match with correspondence study or it's parent study
        if (correspondence.getLss() != null && correspondence.getLss().getStudy() != null) {
            criteria.add(Restrictions.disjunction()
                    .add(Restrictions.eq("lss.study", correspondence.getLss().getStudy())));//.add(Restrictions.eq("pstudy", correspondence.getLss().getStudy())));
        }
        if (correspondence.getCorrespondenceDirectionType() != null) {
            criteria.add(Restrictions.eq("co.correspondenceDirectionType",
                    correspondence.getCorrespondenceDirectionType()));
        }
        if (correspondence.getCorrespondenceModeType() != null) {
            criteria.add(
                    Restrictions.eq("co.correspondenceModeType", correspondence.getCorrespondenceModeType()));
        }
        if (correspondence.getCorrespondenceOutcomeType() != null) {
            criteria.add(Restrictions.eq("co.correspondenceOutcomeType",
                    correspondence.getCorrespondenceOutcomeType()));
        }
        if (correspondence.getDate() != null) {
            criteria.add(Restrictions.eq("co.date", correspondence.getDate()));
        }
        if (correspondence.getTime() != null) {
            criteria.add(Restrictions.eq("co.time", correspondence.getTime()));
        }
        if (correspondence.getDetails() != null) {
            criteria.add(Restrictions.ilike("co.details", correspondence.getDetails(), MatchMode.ANYWHERE));
        }
        if (correspondence.getReason() != null) {
            criteria.add(Restrictions.ilike("co.reason", correspondence.getDetails(), MatchMode.ANYWHERE));
        }
        if (correspondence.getComments() != null) {
            criteria.add(Restrictions.ilike("co.comments", correspondence.getComments(), MatchMode.ANYWHERE));
        }
        if (correspondence.getOperator() != null) {
            criteria.add(Restrictions.eq("co.operator", correspondence.getOperator()));
        }
    }

    List<Correspondences> personCorrespondenceList = criteria.list();
    return personCorrespondenceList;
}

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

License:Open Source License

/**
 * The count can be based on CustomFieldDisplay only instead of a left join with it using SubjectCustomFieldData
 *//*from   w ww. j a v a  2  s. co m*/
public long getSubjectCustomFieldDataCount(LinkSubjectStudy linkSubjectStudyCriteria, ArkFunction arkFunction) {
    Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class);
    criteria.createAlias("customField", "cfield", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("cfield.customFieldType", "cfieldType", JoinType.LEFT_OUTER_JOIN);
    criteria.add(Restrictions.eq("cfield.study", linkSubjectStudyCriteria.getStudy()));
    criteria.add(Restrictions.eq("cfield.arkFunction", arkFunction));
    criteria.add(Restrictions.or(Restrictions.isNull("cfield.customFieldType"),
            Restrictions.eq("cfieldType.name", "SUBJECT")));
    criteria.setProjection(Projections.rowCount());

    return (Long) criteria.uniqueResult();
}

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

License:Open Source License

/**
 * The count can be based on CustomFieldDisplay only instead of a left join with it using FamilyCustomFieldData
 *//*from  www .  j a v a2s . co m*/
public long getFamilyCustomFieldDataCount(LinkSubjectStudy linkSubjectStudyCriteria, ArkFunction arkFunction) {
    Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class);
    criteria.createAlias("customField", "cfield", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("cfield.customFieldType", "cfieldType", JoinType.LEFT_OUTER_JOIN);
    criteria.add(Restrictions.eq("cfield.study", linkSubjectStudyCriteria.getStudy()));
    criteria.add(Restrictions.eq("cfield.arkFunction", arkFunction));
    criteria.add(Restrictions.eq("cfieldType.name", "FAMILY"));
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult();
}

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

License:Open Source License

public RelationshipVo getSubjectRelative(final String subjectUID, final Long studyId) {
    List<RelationshipVo> relatives = new ArrayList<RelationshipVo>();
    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class, "sub");
    criteria.createAlias("sub.study", "substudy", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("sub.person", "subPerson", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("subPerson.genderType", "subGender", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("subPerson.vitalStatus", "subVitStatus", JoinType.LEFT_OUTER_JOIN);

    criteria.createAlias("substudy.pedigreeConfiguration", "spc", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("spc.customField", "cf", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("cf.customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("sub.subjectCustomFieldDataSet", "scfd", JoinType.LEFT_OUTER_JOIN,
            Restrictions.eqProperty("cfd.id", "scfd.customFieldDisplay.id"));

    criteria.add(Restrictions.eq("sub.subjectUID", subjectUID));
    criteria.add(Restrictions.eq("substudy.id", studyId));

    criteria.setFetchMode("subject", FetchMode.JOIN);
    criteria.setFetchMode("relative", FetchMode.JOIN);

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("sub.subjectUID"), "individualId");
    projectionList.add(Projections.property("subGender.name"), "gender");
    projectionList.add(Projections.property("subPerson.dateOfBirth"), "dob");
    projectionList.add(Projections.property("subPerson.dateOfDeath"), "dod");
    projectionList.add(Projections.property("subVitStatus.name"), "deceased");

    projectionList.add(Projections.property("scfd.textDataValue"), "affectedStatus");

    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(RelationshipVo.class));

    relatives = criteria.list();/*from w ww  .j av a2s .  com*/

    return relatives.size() > 0 ? relatives.get(0) : null;
}

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

License:Open Source License

public List<RelationshipVo> getSubjectParentRelatives(final String subjectUID, final Long studyId) {
    List<RelationshipVo> relatives = new ArrayList<RelationshipVo>();
    Criteria criteria = getSession().createCriteria(LinkSubjectPedigree.class, "lsp");
    criteria.createAlias("subject", "sub", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("sub.study", "substudy", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("relative", "rel", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("rel.study", "relstudy", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("relationship", "type", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("rel.person", "relPerson", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("relPerson.genderType", "relGender", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("relPerson.vitalStatus", "relVitStatus", JoinType.LEFT_OUTER_JOIN);

    criteria.createAlias("relstudy.pedigreeConfiguration", "spc", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("spc.customField", "cf", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("cf.customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("rel.subjectCustomFieldDataSet", "scfd", JoinType.LEFT_OUTER_JOIN,
            Restrictions.eqProperty("cfd.id", "scfd.customFieldDisplay.id"));

    criteria.add(Restrictions.eq("sub.subjectUID", subjectUID));
    criteria.add(Restrictions.eq("substudy.id", studyId));
    criteria.add(Restrictions.eq("relstudy.id", studyId));

    criteria.setFetchMode("subject", FetchMode.JOIN);
    criteria.setFetchMode("relative", FetchMode.JOIN);

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("lsp.id"), "id");
    projectionList.add(Projections.property("rel.subjectUID"), "individualId");
    projectionList.add(Projections.property("relGender.name"), "gender");
    projectionList.add(Projections.property("relPerson.dateOfBirth"), "dob");
    projectionList.add(Projections.property("relPerson.dateOfDeath"), "dod");
    projectionList.add(Projections.property("relPerson.firstName"), "firstName");
    projectionList.add(Projections.property("relPerson.lastName"), "lastName");
    projectionList.add(Projections.property("relVitStatus.name"), "deceased");

    projectionList.add(Projections.property("scfd.textDataValue"), "affectedStatus");

    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(RelationshipVo.class));

    relatives = criteria.list();/*from w  w  w . j  a  v  a 2s  .  c om*/
    return relatives;
}

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

License:Open Source License

public List<RelationshipVo> getSubjectChildRelatives(final String subjectUID, final Long studyId) {
    List<RelationshipVo> relatives = new ArrayList<RelationshipVo>();
    Criteria criteria = getSession().createCriteria(LinkSubjectPedigree.class, "lsp");
    criteria.createAlias("subject", "sub", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("sub.study", "substudy", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("relative", "rel", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("rel.study", "relstudy", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("relationship", "type", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("sub.person", "subPerson", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("subPerson.genderType", "subGender", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("subPerson.vitalStatus", "subVitStatus", JoinType.LEFT_OUTER_JOIN);

    criteria.createAlias("substudy.pedigreeConfiguration", "spc", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("spc.customField", "cf", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("cf.customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("sub.subjectCustomFieldDataSet", "scfd", JoinType.LEFT_OUTER_JOIN,
            Restrictions.eqProperty("cfd.id", "scfd.customFieldDisplay.id"));

    criteria.add(Restrictions.eq("rel.subjectUID", subjectUID));
    criteria.add(Restrictions.eq("substudy.id", studyId));
    criteria.add(Restrictions.eq("relstudy.id", studyId));

    criteria.setFetchMode("subject", FetchMode.JOIN);
    criteria.setFetchMode("relative", FetchMode.JOIN);

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("lsp.id"), "id");
    projectionList.add(Projections.property("sub.subjectUID"), "individualId");
    projectionList.add(Projections.property("subGender.name"), "gender");
    projectionList.add(Projections.property("subPerson.dateOfBirth"), "dob");
    projectionList.add(Projections.property("subPerson.dateOfDeath"), "dod");
    projectionList.add(Projections.property("subPerson.firstName"), "firstName");
    projectionList.add(Projections.property("subPerson.lastName"), "lastName");
    projectionList.add(Projections.property("subVitStatus.name"), "deceased");

    projectionList.add(Projections.property("scfd.textDataValue"), "affectedStatus");

    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(RelationshipVo.class));

    relatives = criteria.list();/*from w w  w  .j  a  v  a 2s  .  c o  m*/
    return relatives;
}

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

License:Open Source License

public List<LinkSubjectTwin> getTwins(final Set<String> subjectUids, final Long studyId) {
    List<LinkSubjectTwin> twins = new ArrayList<LinkSubjectTwin>();
    Criteria criteria = getSession().createCriteria(LinkSubjectTwin.class, "lst");
    criteria.createAlias("firstSubject", "lssa", JoinType.INNER_JOIN);
    criteria.createAlias("lssa.study", "sta", JoinType.INNER_JOIN);
    criteria.createAlias("secondSubject", "lssb", JoinType.INNER_JOIN);
    criteria.createAlias("lssb.study", "stb", JoinType.INNER_JOIN);

    criteria.setFetchMode("firstSubject", FetchMode.JOIN);
    criteria.setFetchMode("secondSubject", FetchMode.JOIN);
    criteria.setFetchMode("twinType", FetchMode.JOIN);

    criteria.add(Restrictions.eq("sta.id", studyId));
    criteria.add(Restrictions.eq("stb.id", studyId));
    Disjunction or = Restrictions.disjunction();
    or.add(Restrictions.in("lssa.subjectUID", subjectUids));
    or.add(Restrictions.in("lssb.subjectUID", subjectUids));
    criteria.add(or);//ww  w.ja  v a2s.com

    twins = criteria.list();

    return twins;

}

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

License:Open Source License

public long getRelationshipCount(final String subjectUID, final Long studyId) {
    long count = 0;
    Criteria criteria = getSession().createCriteria(LinkSubjectPedigree.class, "lsp");
    criteria.createAlias("subject", "sub", JoinType.INNER_JOIN);
    criteria.createAlias("relative", "rel", JoinType.INNER_JOIN);
    criteria.createAlias("sub.study", "substudy", JoinType.INNER_JOIN);
    criteria.createAlias("rel.study", "relstudy", JoinType.INNER_JOIN);
    criteria.add(Restrictions.eq("substudy.id", studyId));
    criteria.add(Restrictions.eq("relstudy.id", studyId));
    Disjunction or = Restrictions.disjunction();
    or.add(Restrictions.eq("sub.subjectUID", subjectUID));
    or.add(Restrictions.eq("rel.subjectUID", subjectUID));
    criteria.add(or);/*from w w w .  j av  a2s.co m*/
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.count("lsp.id"));
    criteria.setProjection(projList);
    List list = criteria.list();
    if (list.size() > 0) {
        count = Integer.parseInt(list.get(0).toString());
    }
    return count;
}