List of usage examples for org.hibernate Criteria uniqueResult
public Object uniqueResult() throws HibernateException;
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
@Override public UploadType getUploadTypeByModuleAndName(ArkModule arkModule, String name) { Criteria criteria = getSession().createCriteria(UploadType.class); criteria.add(Restrictions.eq("name", name)); criteria.add(Restrictions.eq("arkModule", arkModule)); return (UploadType) criteria.uniqueResult(); }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public BioCollection getBioCollection(Long id) throws EntityNotFoundException { Criteria criteria = getSession().createCriteria(BioCollection.class); criteria.add(Restrictions.eq("id", id)); BioCollection bioCollection = (BioCollection) criteria.uniqueResult(); if (bioCollection == null) { throw new EntityNotFoundException("The BioCollection entity cannot be found."); }//from w w w . ja v a 2 s . c o m return bioCollection; }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public BioCollectionUidTemplate getBioCollectionUidTemplate(Study study) { Criteria criteria = getSession().createCriteria(BioCollectionUidTemplate.class); criteria.add(Restrictions.eq("study", study)); BioCollectionUidTemplate biocollectionUidTemplate = (BioCollectionUidTemplate) criteria.uniqueResult(); return biocollectionUidTemplate; }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public Boolean hasBioCollections(LinkSubjectStudy linkSubjectStudy) { // Use WHERE EXIST to optimise query even further StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(LinkSubjectStudy.class, "lss"); DetachedCriteria sizeCriteria = DetachedCriteria.forClass(BioCollection.class, "bc"); criteria.add(Restrictions.eq("lss.id", linkSubjectStudy.getId())); sizeCriteria.add(Property.forName("lss.id").eqProperty("bc.linkSubjectStudy.id")); criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("bc.id")))); criteria.setProjection(Projections.rowCount()); Boolean result = ((Long) criteria.uniqueResult()) > 0L; session.close();/*from ww w . j av a 2 s . c om*/ return result; }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public Boolean hasBiospecimens(BioCollection bioCollection) { // Use WHERE EXIST to optimise query even further StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(BioCollection.class, "bc"); DetachedCriteria sizeCriteria = DetachedCriteria.forClass(Biospecimen.class, "b"); criteria.add(Restrictions.eq("bc.id", bioCollection.getId())); sizeCriteria.add(Property.forName("bc.id").eqProperty("b.bioCollection.id")); criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("b.id")))); criteria.setProjection(Projections.rowCount()); Boolean result = ((Long) criteria.uniqueResult()) > 0L; session.close();//w ww . ja v a 2s . c o m return result; }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public long getBioCollectionCount(BioCollection bioCollectionCriteria) { // Handle for study not in context if (bioCollectionCriteria.getStudy() == null) { return 0; }// w w w . j a v a 2 s . c o m Criteria criteria = buildBioCollectionCriteria(bioCollectionCriteria); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); return totalCount; }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
/** * This count can be based on CustomFieldDisplay alone (i.e. does not need left join to BioCollectionCustomFieldData) *//* ww w. j ava 2s .c o m*/ public long getBioCollectionCustomFieldDataCount(BioCollection bioCollectionCriteria, ArkFunction arkFunction) { Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class); criteria.createAlias("customField", "cfield"); // criteria.add(Restrictions.eq("cfield.study", bioCollectionCriteria.getStudy())); // Added to allow child studies to inherit parent defined custom fields List studyList = new ArrayList(); studyList.add(bioCollectionCriteria.getStudy()); if (bioCollectionCriteria.getStudy().getParentStudy() != null && bioCollectionCriteria.getStudy().getParentStudy() != bioCollectionCriteria.getStudy()) { studyList.add(bioCollectionCriteria.getStudy().getParentStudy()); } criteria.add(Restrictions.in("cfield.study", studyList)); criteria.add(Restrictions.eq("cfield.arkFunction", arkFunction)); criteria.setProjection(Projections.rowCount()); return (Long) criteria.uniqueResult(); }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public BioCollection getBioCollectionForStudySubjectByUID(String biocollectionUid, Study study, LinkSubjectStudy linkSubjectStudy) { Criteria criteria = getSession().createCriteria(BioCollection.class, "biocollection"); criteria.add(Restrictions.eq("biocollection.biocollectionUid", biocollectionUid)); criteria.add(Restrictions.eq("study", study)); criteria.add(Restrictions.eq("linkSubjectStudy", linkSubjectStudy)); return (BioCollection) criteria.uniqueResult(); }
From source file:au.org.theark.lims.model.dao.BioCollectionUidGenerator.java
License:Open Source License
/** * TODO this should use a real fkey/*from w w w . jav a 2 s . c om*/ * @param studyNameKy * @return */ public Integer getUidAndIncrement(String studyNameKy, int numToInsert) { Criteria criteria = getSession().createCriteria(BioCollectionUidSequence.class); criteria.add(Restrictions.eq("studyNameId", studyNameKy)); BioCollectionUidSequence seqData = (BioCollectionUidSequence) criteria.uniqueResult(); if (seqData == null) { log.warn("sequence does not exist...creating"); BioCollectionUidSequence seq = new BioCollectionUidSequence(); seq.setInsertLock(false); seq.setStudyNameId(studyNameKy); seq.setUidSequence(numToInsert); getSession().persist(seq); getSession().flush(); return new Integer(0); } else { int currentSeqNumber = seqData.getUidSequence(); seqData.setUidSequence((currentSeqNumber + numToInsert)); getSession().update(seqData); getSession().flush(); return currentSeqNumber;//TODO ...perhaps this should be handled transactionally in one class, and probably with generators...although this isnt really even a key } }
From source file:au.org.theark.lims.model.dao.BioPersonDao.java
License:Open Source License
public Person getPerson(Long id) throws EntityNotFoundException, ArkSystemException { Criteria criteria = getSession().createCriteria(Person.class); criteria.add(Restrictions.eq("id", id)); Person person = (Person) criteria.uniqueResult(); if (person.getId() == null) { throw new EntityNotFoundException("The entity with id" + id.toString() + " cannot be found."); }/*from w w w. j a va2 s . co m*/ return person; }