Example usage for org.hibernate Criteria add

List of usage examples for org.hibernate Criteria add

Introduction

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

Prototype

public Criteria add(Criterion criterion);

Source Link

Document

Add a Criterion restriction to constrain the results to be retrieved.

Usage

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

License:Open Source License

private boolean linkSubjectStudyExists(LinkSubjectStudy linkSubjectStudy) {
    Criteria criteria = getStatelessSession().createCriteria(LinkSubjectStudy.class);
    criteria.add(Restrictions.eq("subjectUID", linkSubjectStudy.getSubjectUID()));
    criteria.add(Restrictions.eq("study", linkSubjectStudy.getStudy()));
    return criteria.uniqueResult() != null;
}

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

License:Open Source License

public LinkStudySubstudy isSubStudy(Study study) {
    Criteria criteria = getStatelessSession().createCriteria(LinkStudySubstudy.class);
    criteria.add(Restrictions.eq("subStudy", study));
    LinkStudySubstudy linkedStudy = (LinkStudySubstudy) criteria.uniqueResult();
    return linkedStudy;
}

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

License:Open Source License

public List<Study> getChildStudyListOfParent(Study study) {
    Criteria criteria = getStatelessSession().createCriteria(Study.class);
    criteria.add(Restrictions.ne("id", study.getId()));
    criteria.add(Restrictions.eq("parentStudy", study));

    try {/*from   w  ww .  j  a va  2s  .c om*/
        criteria.add(Restrictions.ne("studyStatus", getStudyStatus("Archive")));
    } catch (StatusNotAvailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    criteria.addOrder(Order.asc("name"));
    List<Study> childStudyList = (List<Study>) criteria.list();
    return childStudyList;
}

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  w w.  j  a va  2s .c  o m*/

    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  va2 s . com
    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();/*  w w  w  .  j  a va 2  s  .  c o  m*/
    return relatives;
}

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

License:Open Source License

public Integer getSubjectParentCount(final LinkSubjectStudy subject) {
    Criteria criteria = getSession().createCriteria(LinkSubjectPedigree.class);
    criteria.add(Restrictions.eq("subject", subject));
    criteria.setProjection(Projections.rowCount());
    return ((Integer) criteria.list().get(0)).intValue();
}

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

License:Open Source License

public List<LinkSubjectPedigree> getSubjectParentRelationshipList(final LinkSubjectStudy subject) {
    Criteria criteria = getSession().createCriteria(LinkSubjectPedigree.class);
    criteria.add(Restrictions.eq("subject", subject));
    return criteria.list();
}

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

License:Open Source License

public List<LinkSubjectPedigree> getParentNonSubjectRelationshipList(final LinkSubjectStudy subject,
        final LinkSubjectStudy parentSubject) {
    Criteria criteria = getSession().createCriteria(LinkSubjectPedigree.class);
    criteria.add(Restrictions.eq("relative", parentSubject));
    criteria.add(Restrictions.ne("subject", subject));
    return criteria.list();
}

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  va 2  s  . c  o m

    twins = criteria.list();

    return twins;

}