List of usage examples for org.hibernate Criteria add
public Criteria add(Criterion criterion);
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) *///from w w w . ja v a2 s . co 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.BioCollectionDao.java
License:Open Source License
public boolean hasBiocllectionGotCustomFieldData(BioCollection bioCollection) { Criteria criteria = getSession().createCriteria(BioCollectionCustomFieldData.class); criteria.add(Restrictions.eq("bioCollection", bioCollection)); List<BioCollectionCustomFieldData> list = (List<BioCollectionCustomFieldData>) criteria.list(); return (list.size() > 0); }
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 2s . c o m * @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."); }/* w w w . j ava 2 s.com*/ return person; }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
public Biospecimen getBiospecimen(Long id) throws EntityNotFoundException { Criteria criteria = getSession().createCriteria(Biospecimen.class); criteria.add(Restrictions.eq("id", id)); Biospecimen biospecimen = (Biospecimen) criteria.uniqueResult(); if (biospecimen.getId() == null) { throw new EntityNotFoundException("The entity with id" + id.toString() + " cannot be found."); }//from w ww. j a v a2 s.c o m return biospecimen; }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
public List<Biospecimen> searchBiospecimen(Biospecimen biospecimen) throws ArkSystemException { Criteria criteria = getSession().createCriteria(Biospecimen.class); if (biospecimen.getId() != null) criteria.add(Restrictions.eq("id", biospecimen.getId())); if (biospecimen.getBiospecimenUid() != null) criteria.add(Restrictions.ilike("biospecimenUid", biospecimen.getBiospecimenUid(), MatchMode.ANYWHERE)); if (biospecimen.getLinkSubjectStudy() != null) criteria.add(Restrictions.eq("linkSubjectStudy", biospecimen.getLinkSubjectStudy())); if (biospecimen.getStudy() != null) criteria.add(Restrictions.eq("study", biospecimen.getStudy())); if (biospecimen.getSampleType() != null) criteria.add(Restrictions.eq("sampleType", biospecimen.getSampleType())); if (biospecimen.getSampleDate() != null) criteria.add(Restrictions.eq("sampleDate", biospecimen.getSampleDate())); if (biospecimen.getQtyCollected() != null) criteria.add(Restrictions.eq("qtyCollected", biospecimen.getQtyCollected())); List<Biospecimen> list = criteria.list(); return list;/*from www. j a v a 2 s.co m*/ }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
protected Criteria buildBiospecimenCriteria(Biospecimen biospecimen) { Criteria criteria = getSession().createCriteria(Biospecimen.class); if (biospecimen.getId() != null) criteria.add(Restrictions.eq("id", biospecimen.getId())); if (biospecimen.getBiospecimenUid() != null) criteria.add(Restrictions.ilike("biospecimenUid", biospecimen.getBiospecimenUid(), MatchMode.ANYWHERE)); if (biospecimen.getLinkSubjectStudy() != null) criteria.add(Restrictions.eq("linkSubjectStudy", biospecimen.getLinkSubjectStudy())); if (biospecimen.getStudy() != null) criteria.add(Restrictions.eq("study", biospecimen.getStudy())); if (biospecimen.getSampleType() != null) criteria.add(Restrictions.eq("sampleType", biospecimen.getSampleType())); if (biospecimen.getSampleDate() != null) criteria.add(Restrictions.eq("sampleDate", biospecimen.getSampleDate())); if (biospecimen.getQtyCollected() != null) criteria.add(Restrictions.eq("qtyCollected", biospecimen.getQtyCollected())); if (biospecimen.getParent() != null) { criteria.add(Restrictions.eq("parent", biospecimen.getParent())); } else {/* www . j a v a 2s . c o m*/ criteria.add(Restrictions.isNull("parent")); } return criteria; }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
public boolean doesSomeoneElseHaveThisUid(String biospecimenUid, final Study study, Long idToExcludeFromSearch) { Criteria criteria = getSession().createCriteria(Biospecimen.class); criteria.add(Restrictions.eq("biospecimenUid", biospecimenUid)); criteria.add(Restrictions.ne("id", idToExcludeFromSearch)); if (study != null) { criteria.add(Restrictions.eq("study", study)); }//from www . j a v a 2 s . co m return (criteria.list().size() > 0); }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
protected Criteria buildBiospecimenCriteria(LimsVO limsVo) { Criteria criteria = getSession().createCriteria(Biospecimen.class); Biospecimen biospecimen = limsVo.getBiospecimen(); criteria.createAlias("bioCollection", "bc"); criteria.createAlias("linkSubjectStudy", "lss"); // If study chosen, restrict otherwise restrict on users' studyList if (limsVo.getStudy() != null && limsVo.getStudy().getId() != null) { //if(limsVo.getStudy().isParentStudy()) { if (limsVo.getStudy().getParentStudy() != null && limsVo.getStudy().getParentStudy().getId() != null && limsVo.getStudy().getParentStudy().getId().equals(limsVo.getStudy().getId())) { // If parent study, show all children as well criteria.add(Restrictions.in("study", iStudyDao.getChildStudiesForStudy(limsVo.getStudy()))); } else {//from w w w .j ava 2 s .c o m criteria.add(Restrictions.eq("study", limsVo.getStudy())); } } else { criteria.add(Restrictions.in("study", limsVo.getStudyList())); criteria.createAlias("study", "st"); criteria.addOrder(Order.asc("st.name")); criteria.addOrder(Order.asc("lss.subjectUID")); criteria.addOrder(Order.asc("bc.biocollectionUid")); criteria.addOrder(Order.asc("biospecimenUid")); } // Restrict on linkSubjectStudy in the LimsVO (or biospecimen) if (limsVo.getLinkSubjectStudy() != null && limsVo.getLinkSubjectStudy().getId() != null) { criteria.add(Restrictions.eq("linkSubjectStudy", limsVo.getLinkSubjectStudy())); } else if (biospecimen.getLinkSubjectStudy() != null) { criteria.add(Restrictions.eq("linkSubjectStudy", biospecimen.getLinkSubjectStudy())); } if (limsVo.getLinkSubjectStudy() != null) { if (limsVo.getLinkSubjectStudy().getSubjectUID() != null) { criteria.add(Restrictions.ilike("lss.subjectUID", limsVo.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE)); } } if (limsVo.getBioCollection() != null && limsVo.getBioCollection().getBiocollectionUid() != null) { criteria.add(Restrictions.ilike("bc.biocollectionUid", limsVo.getBioCollection().getBiocollectionUid(), MatchMode.ANYWHERE)); } if (biospecimen.getId() != null) { criteria.add(Restrictions.eq("id", biospecimen.getId())); } if (biospecimen.getBiospecimenUid() != null) { criteria.add(Restrictions.ilike("biospecimenUid", biospecimen.getBiospecimenUid(), MatchMode.ANYWHERE)); } if (biospecimen.getSampleType() != null) { criteria.add(Restrictions.eq("sampleType", biospecimen.getSampleType())); } if (biospecimen.getSampleDate() != null) { criteria.add(Restrictions.eq("sampleDate", biospecimen.getSampleDate())); } if (biospecimen.getQtyCollected() != null) { criteria.add(Restrictions.eq("qtyCollected", biospecimen.getQtyCollected())); } return criteria; }