List of usage examples for org.hibernate Criteria setProjection
public Criteria setProjection(Projection projection);
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public long getStudySubjectCount(SubjectVO subjectVO) { // Handle for study not in context // GEORGE - 30/1/15 Removed handle to allow for global search. Need to test to see if this fails anywhere. // if (subjectVO.getLinkSubjectStudy().getStudy() == null) { // return 0; // }// www. j ava2s . c om Criteria criteria = buildGeneralSubjectCriteria(subjectVO); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); return totalCount.intValue(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
private Criteria buildGeneralSubjectCriteria(SubjectVO subjectVO) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.createAlias("person", "p"); if (subjectVO.getLinkSubjectStudy().getStudy() != null) { criteria.add(Restrictions.eq("study.id", subjectVO.getLinkSubjectStudy().getStudy().getId())); } else {// ww w . ja v a 2 s . com criteria.add(Restrictions.in("study", subjectVO.getStudyList())); criteria.createAlias("study", "st"); criteria.addOrder(Order.asc("st.name")); } if (subjectVO.getLinkSubjectStudy().getPerson() != null) { if (subjectVO.getLinkSubjectStudy().getPerson().getId() != null) { criteria.add(Restrictions.eq("p.id", subjectVO.getLinkSubjectStudy().getPerson().getId())); } if (subjectVO.getLinkSubjectStudy().getPerson().getFirstName() != null) { criteria.add(Restrictions.ilike("p.firstName", subjectVO.getLinkSubjectStudy().getPerson().getFirstName(), MatchMode.ANYWHERE)); } if (subjectVO.getLinkSubjectStudy().getPerson().getMiddleName() != null) { criteria.add(Restrictions.ilike("p.middleName", subjectVO.getLinkSubjectStudy().getPerson().getMiddleName(), MatchMode.ANYWHERE)); } if (subjectVO.getLinkSubjectStudy().getPerson().getLastName() != null) { /* old code pre George adding personlastname lookup criteria.add(Restrictions.ilike("p.lastName", subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE));*/ //log.info("Lastname: " + subjectVO.getLinkSubjectStudy().getPerson().getLastName()); DetachedCriteria previousLastNames = DetachedCriteria.forClass(PersonLastnameHistory.class, "l") .setProjection(Projections.property("l.lastName")) .add(Restrictions.ilike("l.lastName", subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE)) .add(Restrictions.eqProperty("p.id", "l.person.id")); criteria.add(Restrictions.or(Restrictions.ilike("p.lastName", subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE), Subqueries.exists(previousLastNames))); } if (subjectVO.getLinkSubjectStudy().getPerson().getDateOfBirth() != null) { criteria.add(Restrictions.eq("p.dateOfBirth", subjectVO.getLinkSubjectStudy().getPerson().getDateOfBirth())); } if (subjectVO.getLinkSubjectStudy().getPerson().getGenderType() != null) { criteria.add(Restrictions.eq("p.genderType.id", subjectVO.getLinkSubjectStudy().getPerson().getGenderType().getId())); } if (subjectVO.getLinkSubjectStudy().getPerson().getVitalStatus() != null) { criteria.add(Restrictions.eq("p.vitalStatus.id", subjectVO.getLinkSubjectStudy().getPerson().getVitalStatus().getId())); } if (!subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().isEmpty()) { OtherID o = (OtherID) subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().toArray()[0]; if (o != null && o.getOtherID() != null && !o.getOtherID().isEmpty()) { log.info("OtherID search"); // DetachedCriteria otherID = DetachedCriteria.forClass(OtherID.class, "O") // .setProjection(Projections.projectionList().add(Projections.property("O.otherID"))) // .add(Restrictions.ilike("O.otherID", ((OtherID) subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().toArray()[0]).getOtherID(), MatchMode.EXACT)) // .add(Restrictions.eqProperty("p.id", "O.person.id")); // criteria.add(Subqueries.exists(otherID)); criteria.createAlias("p.otherIDs", "o"); criteria.add(Restrictions.ilike("o.otherID", ((OtherID) subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().toArray()[0]) .getOtherID(), MatchMode.ANYWHERE)); criteria.setProjection(Projections.distinct( Projections.projectionList().add(Projections.property("o.personid"), "lss.person.id"))); } } } if (subjectVO.getLinkSubjectStudy().getSubjectUID() != null && subjectVO.getLinkSubjectStudy().getSubjectUID().length() > 0) { criteria.add(Restrictions.ilike("subjectUID", subjectVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE)); } if (subjectVO.getLinkSubjectStudy().getSubjectStatus() != null) { criteria.add(Restrictions.eq("subjectStatus", subjectVO.getLinkSubjectStudy().getSubjectStatus())); SubjectStatus subjectStatus = getSubjectStatus("Archive"); if (subjectStatus != null) { criteria.add(Restrictions.ne("subjectStatus", subjectStatus)); } } else { SubjectStatus subjectStatus = getSubjectStatus("Archive"); if (subjectStatus != null) { criteria.add(Restrictions.ne("subjectStatus", subjectStatus)); } } if (subjectVO.getRelativeUIDs().size() > 0) { criteria.add(Restrictions.not(Restrictions.in("subjectUID", subjectVO.getRelativeUIDs().toArray()))); } criteria.setProjection(Projections.distinct(Projections.projectionList().add(Projections.id()))); criteria.addOrder(Order.asc("subjectUID")); return criteria; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public Boolean studyHasSubjects(Study study) { StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(LinkSubjectStudy.class); criteria.add(Restrictions.eq("study", study)); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); session.close();/*www . j a v a 2 s . com*/ return totalCount.intValue() > 0; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public List<Study> getStudiesForUser(ArkUser arkUser, Study study) { Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.createAlias("arkStudy", "arkStudy"); criteria.add(Restrictions.eq("arkUser", arkUser));// Represents the user // either who is // logged in or one // that is provided if (study.getId() != null) { criteria.add(Restrictions.eq("arkStudy.id", study.getId())); }// w w w . j a va2 s .co m if (study.getName() != null) { criteria.add(Restrictions.ilike("arkStudy.name", study.getName(), MatchMode.ANYWHERE)); } criteria.setProjection(Projections.distinct(Projections.property("study"))); List<Study> studies = (List<Study>) criteria.list(); return studies; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public String getDelimiterTypeNameByDelimiterChar(char delimiterCharacter) { String delimiterTypeName = null; Criteria criteria = getSession().createCriteria(DelimiterType.class); criteria.add(Restrictions.eq("delimiterCharacter", delimiterCharacter)); criteria.setProjection(Projections.property("name")); delimiterTypeName = (String) criteria.uniqueResult(); return delimiterTypeName; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public List<Study> getStudyListAssignedToBiospecimenUidTemplate() { Criteria criteria = getSession().createCriteria(BiospecimenUidTemplate.class); criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("study"))); return criteria.list(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public Boolean studyHasBiospecimen(Study study) { StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(Biospecimen.class); criteria.add(Restrictions.eq("study", study)); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); session.close();/* w w w .ja v a 2 s . c om*/ return totalCount.intValue() > 0; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public Boolean studyHasBioCollection(Study study) { StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(BioCollection.class); criteria.add(Restrictions.eq("study", study)); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); session.close();/* w w w . j a v a 2 s. co m*/ return totalCount.intValue() > 0; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public List<Study> getAssignedChildStudyListForPerson(Study study, Person person) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.createAlias("study", "s"); criteria.add(Restrictions.eq("person", person)); criteria.add(Restrictions.eq("s.parentStudy", study)); criteria.add(Restrictions.ne("s.id", study.getId())); criteria.add(Restrictions.ne("subjectStatus", getSubjectStatus("Archive"))); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("study"), "study"); criteria.setProjection(projectionList); return criteria.list(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public List<Long> getSubjectIdsforSearch(Search search) { Criteria criteria = getSession().createCriteria(SearchSubject.class); criteria.add(Restrictions.eq("search", search)); criteria.setProjection(Projections.property("linkSubjectStudy.id")); return criteria.list(); }