List of usage examples for org.hibernate Criteria uniqueResult
public Object uniqueResult() throws HibernateException;
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;/*w w w. ja va 2 s . c o m*/ 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;// w w w .j av a2 s .c om 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 PhenoDataSetCategory getPhenoDataSetCategoryForAssignedPhenoDataSetField(Study study, ArkFunction arkFunction, ArkUser arkUser, PhenoDataSetField phenoDataSetField) { 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("phenoDataSetField", phenoDataSetField)); LinkPhenoDataSetCategoryField linkPhenoDataSetCategoryField = (LinkPhenoDataSetCategoryField) criteria .uniqueResult();/* w w w. j ava 2s.c o m*/ return linkPhenoDataSetCategoryField.getPhenoDataSetCategory(); }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
@Override public PhenoDataSetCategory getPhenoDataFieldCategoryByNameStudyAndArkFunction(String name, Study study, ArkFunction arkFunction) {/*from w ww.j av a2 s .co m*/ Criteria criteria = getSession().createCriteria(PhenoDataSetCategory.class); criteria.add(Restrictions.eq("name", name)); criteria.add(Restrictions.eq("study", study)); criteria.add(Restrictions.eq("arkFunction", arkFunction)); return (PhenoDataSetCategory) criteria.uniqueResult(); }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
@Override public PhenoDataSetField getPhenoDataSetFieldByNameStudyArkFunction(String name, Study study, ArkFunction arkFunction) {//from w w w . j a v a2s . c o m Criteria criteria = getSession().createCriteria(PhenoDataSetField.class); criteria.add(Restrictions.eq("name", name)); criteria.add(Restrictions.eq("study", study)); criteria.add(Restrictions.eq("arkFunction", arkFunction)); return (PhenoDataSetField) criteria.uniqueResult(); }
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 w w . java2s .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.report.model.dao.ReportDao.java
License:Open Source License
public long getTotalSubjectCount(Study study) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.add(Restrictions.eq("study", study)); criteria.setProjection(Projections.rowCount()); return (Long) criteria.uniqueResult(); }
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
public Map<String, Long> getStudyConsentCounts(Study study) { Map<String, Long> statusMap = new HashMap<String, Long>(); Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.add(Restrictions.eq("study", study)); ProjectionList projectionList = Projections.projectionList(); criteria.createAlias("consentStatus", "consentStatusAlias"); projectionList.add(Projections.groupProperty("consentStatusAlias.name")); projectionList.add(Projections.rowCount()); criteria.setProjection(projectionList); List results = criteria.list(); for (Object r : results) { Object[] obj = (Object[]) r; String statusName = (String) obj[0]; statusMap.put(statusName, (Long) obj[1]); }/*from www. j a v a 2 s . com*/ // Tack on count of when consentStatus = undefined (NULL) criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.add(Restrictions.eq("study", study)); criteria.add(Restrictions.isNull("consentStatus")); projectionList = Projections.projectionList(); projectionList.add(Projections.rowCount()); criteria.setProjection(projectionList); Long undefCount = (Long) criteria.uniqueResult(); String statusName = Constants.NOT_CONSENTED; statusMap.put(statusName, undefCount); return statusMap; }
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
public Address getBestAddress(LinkSubjectStudy subject) { Address result = null;/* www.ja va 2s. c om*/ // Attempt to get the preferred address first Criteria criteria = getSession().createCriteria(Address.class); criteria.add(Restrictions.eq("person", subject.getPerson())); criteria.add(Restrictions.eq("preferredMailingAddress", true)); criteria.setMaxResults(1); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("streetAddress"), "streetAddress"); projectionList.add(Projections.property("city"), "city"); projectionList.add(Projections.property("country"), "country"); projectionList.add(Projections.property("state"), "state"); projectionList.add(Projections.property("otherState"), "otherState"); projectionList.add(Projections.property("postCode"), "postCode"); criteria.setProjection(projectionList); // only return fields required for report criteria.setResultTransformer(Transformers.aliasToBean(Address.class)); if (criteria.uniqueResult() != null) { result = (Address) criteria.uniqueResult(); } else { // Get any address criteria = getSession().createCriteria(Address.class); criteria.add(Restrictions.eq("person", subject.getPerson())); criteria.setMaxResults(1); criteria.setProjection(projectionList); // only return fields required for report criteria.setResultTransformer(Transformers.aliasToBean(Address.class)); result = (Address) criteria.uniqueResult(); } return result; }
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
public Phone getWorkPhone(LinkSubjectStudy subject) { Phone result = null;//from w ww . ja v a 2s.com Criteria criteria = getSession().createCriteria(Phone.class); criteria.add(Restrictions.eq("person", subject.getPerson())); criteria.createAlias("phoneType", "pt"); criteria.add(Restrictions.eq("pt.name", "Work")); criteria.setMaxResults(1); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("areaCode"), "areaCode"); projectionList.add(Projections.property("phoneNumber"), "phoneNumber"); criteria.setProjection(projectionList); // only return fields required for report criteria.setResultTransformer(Transformers.aliasToBean(Phone.class)); if (criteria.uniqueResult() != null) { result = (Phone) criteria.uniqueResult(); } return result; }