List of usage examples for org.hibernate Query uniqueResult
R uniqueResult();
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public Long isCustomFieldUsed(BioCollectionCustomFieldData bioCollectionCFData) { Long count = new Long("0"); CustomField customField = bioCollectionCFData.getCustomFieldDisplay().getCustomField(); // The Study//w ww. java 2 s . c om try { Long id = bioCollectionCFData.getBioCollection().getId(); BioCollection bioCollection = getBioCollection(id); //Study subjectStudy = bioCollection.getStudy(); ArkFunction arkFunction = customField.getArkFunction(); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(" SELECT COUNT(*) FROM BioCollectionCustomFieldData AS bccfd WHERE EXISTS "); stringBuffer.append(" ( "); stringBuffer.append(" SELECT cfd.id "); stringBuffer.append(" FROM CustomFieldDisplay AS cfd "); stringBuffer.append(" WHERE cfd.customField.study IN (:studyId)"); stringBuffer.append( " AND cfd.customField.arkFunction.id = :functionId AND bccfd.customFieldDisplay.id = :customFieldDisplayId"); stringBuffer.append(" )"); String theHQLQuery = stringBuffer.toString(); Query query = getSession().createQuery(theHQLQuery); //query.setParameter("studyId", subjectStudy.getId()); List studyList = new ArrayList(); studyList.add(bioCollection.getStudy()); if (bioCollection.getStudy().getParentStudy() != null && bioCollection.getStudy().getParentStudy() != bioCollection.getStudy()) { studyList.add(bioCollection.getStudy().getParentStudy()); } query.setParameterList("studyId", studyList); query.setParameter("functionId", arkFunction.getId()); query.setParameter("customFieldDisplayId", bioCollectionCFData.getCustomFieldDisplay().getId()); count = (Long) query.uniqueResult(); } catch (EntityNotFoundException e) { //The given BioCollection is not available, this should not happen since the person is editing custom fields for the LIMS collection e.printStackTrace(); } return count; }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public BioCollection getBioCollectionByUID(final String biocollectionUid, final Long studyId, final String subjectUID) { String GET_BIO_COLLECTION_BY_UID_AND_STUDY_ID_AND_SUBJECTUID = "select bio from BioCollection as bio " + "left outer join bio.linkSubjectStudy as linkStudy " + "left outer join linkStudy.study as study " + "where bio.biocollectionUid = :biocollectionUid " + "and study.id = :studyId " + " and linkStudy.subjectUID = :subjectUID"; Query query = getSession().createQuery(GET_BIO_COLLECTION_BY_UID_AND_STUDY_ID_AND_SUBJECTUID); query.setString("biocollectionUid", biocollectionUid); query.setLong("studyId", studyId); query.setString("subjectUID", subjectUID); BioCollection bioCollection = (BioCollection) query.uniqueResult(); return bioCollection; }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
public Long isCustomFieldUsed(BiospecimenCustomFieldData biospecimanCFData) { Long count = new Long("0"); CustomField customField = biospecimanCFData.getCustomFieldDisplay().getCustomField(); try {/*ww w .j a v a2 s. co m*/ Long id = biospecimanCFData.getBiospecimen().getId(); Biospecimen biospecimen = getBiospecimen(id); Study subjectStudy = biospecimen.getStudy(); ArkFunction arkFunction = customField.getArkFunction(); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(" SELECT COUNT(*) FROM BiospecimenCustomFieldData AS bscfd WHERE EXISTS "); stringBuffer.append(" ( "); stringBuffer.append( " SELECT cfd.id FROM CustomFieldDisplay AS cfd WHERE cfd.customField.study.id = :studyId"); stringBuffer.append( " AND cfd.customField.arkFunction.id = :functionId AND bscfd.customFieldDisplay.id = :customFieldDisplayId"); stringBuffer.append(" )"); String theHQLQuery = stringBuffer.toString(); Query query = getSession().createQuery(theHQLQuery); query.setParameter("studyId", subjectStudy.getId()); query.setParameter("functionId", arkFunction.getId()); query.setParameter("customFieldDisplayId", biospecimanCFData.getCustomFieldDisplay().getId()); count = (Long) query.uniqueResult(); } catch (EntityNotFoundException e) { //The given Biospecimen is not available, this should not happen since the person is editing custom fields for the LIMS biospecimen e.printStackTrace(); } return count; }
From source file:au.org.theark.lims.model.dao.InventoryDao.java
License:Open Source License
public BiospecimenLocationVO getBiospecimenLocation(Biospecimen biospecimen) { BiospecimenLocationVO biospecimenLocationVo = new BiospecimenLocationVO(); StringBuilder hqlString = new StringBuilder(); hqlString.append(/* w ww . j a v a2 s . c o m*/ "SELECT site.name AS siteName, freezer.name as freezerName, rack.name AS rackName, box.name AS boxName, cell.colno AS column, cell.rowno AS row, box.colnotype.name AS colNoType, box.rownotype.name AS rowNoType \n"); hqlString.append("FROM InvCell AS cell \n"); hqlString.append("LEFT JOIN cell.invBox AS box \n"); hqlString.append("LEFT JOIN box.invRack AS rack \n"); hqlString.append("LEFT JOIN rack.invFreezer AS freezer \n"); hqlString.append("LEFT JOIN freezer.invSite AS site \n"); hqlString.append("WHERE cell.biospecimen = :biospecimen"); Query q = getSession().createQuery(hqlString.toString()); q.setParameter("biospecimen", biospecimen); Object[] result = (Object[]) q.uniqueResult(); if (result != null) { biospecimenLocationVo.setIsAllocated(true); biospecimenLocationVo.setSiteName(result[0].toString()); biospecimenLocationVo.setFreezerName(result[1].toString()); biospecimenLocationVo.setRackName(result[2].toString()); biospecimenLocationVo.setBoxName(result[3].toString()); Long colno = new Long((Long) result[4]); Long rowno = new Long((Long) result[5]); biospecimenLocationVo.setColumn(colno); biospecimenLocationVo.setRow(rowno); String colNoType = result[6].toString(); String rowNoType = result[7].toString(); String colLabel = new String(); if (colNoType.equalsIgnoreCase("ALPHABET")) { char character = (char) (colno + 64); colLabel = new Character(character).toString(); } else { colLabel = new Integer(colno.intValue()).toString(); } biospecimenLocationVo.setColLabel(colLabel); String rowLabel = new String(); if (rowNoType.equalsIgnoreCase("ALPHABET")) { char character = (char) (rowno + 64); rowLabel = new Character(character).toString(); } else { rowLabel = new Integer(rowno.intValue()).toString(); } biospecimenLocationVo.setRowLabel(rowLabel); } return biospecimenLocationVo; }
From source file:au.org.theark.lims.model.dao.InventoryDao.java
License:Open Source License
public BiospecimenLocationVO getInvCellLocation(InvCell invCell) throws ArkSystemException { BiospecimenLocationVO biospecimenLocationVo = new BiospecimenLocationVO(); StringBuilder hqlString = new StringBuilder(); hqlString.append(/*w ww . j a v a 2 s .c o m*/ "SELECT site.name AS siteName, freezer.name as freezerName, rack.name AS rackName, box.name AS boxName, cell.colno AS column, cell.rowno AS row, box.colnotype.name AS colNoType, box.rownotype.name AS rowNoType \n"); hqlString.append("FROM InvCell AS cell \n"); hqlString.append("LEFT JOIN cell.invBox AS box \n"); hqlString.append("LEFT JOIN box.invRack AS rack \n"); hqlString.append("LEFT JOIN rack.invFreezer AS freezer \n"); hqlString.append("LEFT JOIN freezer.invSite AS site \n"); hqlString.append("WHERE cell.id = :id"); Query q = getSession().createQuery(hqlString.toString()); q.setParameter("id", invCell.getId()); Object[] result = (Object[]) q.uniqueResult(); if (result != null) { biospecimenLocationVo.setSiteName(result[0].toString()); biospecimenLocationVo.setFreezerName(result[1].toString()); biospecimenLocationVo.setRackName(result[2].toString()); biospecimenLocationVo.setBoxName(result[3].toString()); Long colno = new Long((Long) result[4]); Long rowno = new Long((Long) result[5]); biospecimenLocationVo.setColumn(colno); biospecimenLocationVo.setRow(rowno); String colNoType = result[6].toString(); String rowNoType = result[7].toString(); String colLabel = new String(); if (colNoType.equalsIgnoreCase("ALPHABET")) { char character = (char) (colno + 64); colLabel = new Character(character).toString(); } else { colLabel = new Integer(colno.intValue()).toString(); } biospecimenLocationVo.setColLabel(colLabel); String rowLabel = new String(); if (rowNoType.equalsIgnoreCase("ALPHABET")) { char character = (char) (rowno + 64); rowLabel = new Character(character).toString(); } else { rowLabel = new Integer(rowno.intValue()).toString(); } biospecimenLocationVo.setRowLabel(rowLabel); } return biospecimenLocationVo; }
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
public Long getWithoutStudyCompCount(Study study) { /*/*from ww w. jav a 2 s.c om*/ * The following HQL implements this MySQL query: SELECT COUNT(*) FROM study.link_subject_study AS lss LEFT JOIN study.consent AS c ON lss.id = * c.subject_id -- this line is implicit from annotations on the entity classes WHERE lss.study_id = 2 AND c.id IS NULL; */ String hqlString = "SELECT COUNT(*) FROM LinkSubjectStudy AS lss \n" + "LEFT JOIN lss.consents AS c \n" + "WHERE lss.study = :study \n" + "AND c.id IS NULL"; Query q = getSession().createQuery(hqlString); // if (hqlString.contains(":study_id")) { // q.setParameter("study_id", study.getId()); // } // if (hqlString.contains(":study")) { q.setParameter("study", study); // } Long undefCount = (Long) q.uniqueResult(); return undefCount; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
@Override public String getSubjectFamilyUId(Long studyId, String subjectUID) { String result = null;//from w w w . j a v a 2 s .c om StringBuffer sb = new StringBuffer("select scfd.TEXT_DATA_VALUE from " + "study.link_subject_study lss " + "left outer join study.study st on lss.STUDY_ID = st.ID " + "left outer join study.study_pedigree_config spc on spc.study_id = st.ID " + "left outer join study.custom_field cf on cf.ID = spc.family_id " + "left outer join study.custom_field_display cfd on cfd.custom_field_id = cf.id " + "left outer join study.subject_custom_field_data scfd on scfd.CUSTOM_FIELD_DISPLAY_ID = cfd.id " + "and scfd.LINK_SUBJECT_STUDY_ID = lss.ID " + "where st.ID= :studyId and lss.SUBJECT_UID = :subjectUID and spc.family_id is not null"); Query query = getSession().createSQLQuery(sb.toString()); query.setParameter("studyId", studyId); query.setParameter("subjectUID", subjectUID); result = (String) query.uniqueResult(); return result; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public Long isCustomFieldUsed(SubjectCustomFieldData subjectCustomFieldData) { Long count = new Long("0"); CustomField customField = subjectCustomFieldData.getCustomFieldDisplay().getCustomField(); Study study = customField.getStudy(); ArkFunction arkFunction = customField.getArkFunction(); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(" SELECT COUNT(*) FROM SubjectCustomFieldData AS scfd WHERE EXISTS "); stringBuffer.append(" ( "); stringBuffer.append(/*from ww w. ja v a 2 s . c o m*/ " SELECT cfd.id FROM CustomFieldDisplay AS cfd WHERE cfd.customField.study.id = :studyId"); stringBuffer.append( " AND cfd.customField.arkFunction.id = :functionId AND scfd.customFieldDisplay.id = :customFieldDisplayId"); stringBuffer.append(" )"); String theHQLQuery = stringBuffer.toString(); Query query = getSession().createQuery(theHQLQuery); query.setParameter("studyId", study.getId()); query.setParameter("functionId", arkFunction.getId()); query.setParameter("customFieldDisplayId", subjectCustomFieldData.getCustomFieldDisplay().getId()); count = (Long) query.uniqueResult(); return count; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public Long isFamilyCustomFieldUsed(FamilyCustomFieldData familyCustomFieldData) { Long count = new Long("0"); CustomField customField = familyCustomFieldData.getCustomFieldDisplay().getCustomField(); Study study = customField.getStudy(); ArkFunction arkFunction = customField.getArkFunction(); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(" SELECT COUNT(*) FROM FamilyCustomFieldData AS scfd WHERE EXISTS "); stringBuffer.append(" ( "); stringBuffer.append(/*from ww w . ja v a 2 s . c o m*/ " SELECT cfd.id FROM CustomFieldDisplay AS cfd WHERE cfd.customField.study.id = :studyId"); stringBuffer.append( " AND cfd.customField.arkFunction.id = :functionId AND scfd.customFieldDisplay.id = :customFieldDisplayId"); stringBuffer.append(" )"); String theHQLQuery = stringBuffer.toString(); Query query = getSession().createQuery(theHQLQuery); query.setParameter("studyId", study.getId()); query.setParameter("functionId", arkFunction.getId()); query.setParameter("customFieldDisplayId", familyCustomFieldData.getCustomFieldDisplay().getId()); count = (Long) query.uniqueResult(); return count; }
From source file:baking.dao.BaseDao.java
License:Open Source License
/** * ?count(*)?hql??/*from ww w .j av a 2 s .c o m*/ * * @param hql the hql * * @return the toatal by hql */ public int countHql(String hql) { // Query query = getSession().createQuery(hql); Long result = (Long) query.uniqueResult(); if (result != null) { return result.intValue(); } return 0; }