List of usage examples for org.hibernate Criteria setProjection
public Criteria setProjection(Projection projection);
From source file:au.org.theark.lims.model.dao.BioTransactionDao.java
License:Open Source License
public long getBioTransactionCount(BioTransaction bioTransaction) { // Handle for biospecimen not in context if (bioTransaction.getBiospecimen() == null) { return 0L; }/*from w w w . j a v a 2 s .com*/ Criteria criteria = buildBioTransactionCriteria(bioTransaction); criteria.setProjection(Projections.rowCount()); return (Long) criteria.uniqueResult(); }
From source file:au.org.theark.lims.model.dao.InventoryDao.java
License:Open Source License
public List<InvSite> searchInvSite(InvSite invSite, List<Study> studyList) throws ArkSystemException { List<InvSite> invSiteList = new ArrayList<InvSite>(0); if (studyList == null || studyList.isEmpty()) { return invSiteList; }/* ww w . j ava2s . c o m*/ Criteria criteria = getSession().createCriteria(StudyInvSite.class); /* * if (invSite.getId() != null) { criteria.add(Restrictions.eq("id", invSite.getId())); } * * if (invSite.getName() != null) { criteria.add(Restrictions.eq("name", invSite.getName())); } * * if (invSite.getContact() != null) { criteria.add(Restrictions.eq("contact", invSite.getContact())); } * * if (invSite.getAddress() != null) { criteria.add(Restrictions.eq("address", invSite.getAddress())); } * * if (invSite.getPhone() != null) { criteria.add(Restrictions.eq("phone", invSite.getPhone())); } */ /*if you have an empty grouping, hibernate will do this sort of this; * select this_.INV_SITE_ID as y0_ from lims.study_inv_site this_ where this_.STUDY_ID in ( ) group by this_.INV_SITE_ID ...therefore always null check before checking if something is in a group of nothing */ criteria.add(Restrictions.in("study", studyList)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("invSite"), "invSite"); criteria.setProjection(projectionList); // List<StudyInvSite> list = criteria.list(); invSiteList = criteria.list(); /* * for(StudyInvSite studyInvSite : list){ invSiteList.add(studyInvSite.getInvSite()); } */ return invSiteList; }
From source file:au.org.theark.lims.model.dao.InventoryDao.java
License:Open Source License
public boolean boxesExist() { Criteria criteria = getSession().createCriteria(InvBox.class); criteria.setProjection(Projections.count("id")); Long count = (Long) criteria.uniqueResult(); return count > 0L; }
From source file:au.org.theark.lims.model.dao.InventoryDao.java
License:Open Source License
public boolean hasAllocatedCells(InvBox invBox) { Criteria criteria = getSession().createCriteria(InvCell.class); criteria.add(Restrictions.eq("invBox", invBox)); criteria.add(Restrictions.isNotNull("biospecimen")); criteria.setProjection(Projections.count("id")); Long count = (Long) criteria.uniqueResult(); return count > 0L; }
From source file:au.org.theark.lims.model.dao.LimsSubjectDao.java
License:Open Source License
public long getSubjectCount(LimsVO limsVo, List<Study> studyList) { if (studyList != null && !studyList.isEmpty()) { Criteria criteria = buildGeneralSubjectCriteria(limsVo, studyList); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); return totalCount.intValue(); } else {/* ww w.j a v a2s .c o m*/ // Fixes to handle for if the studyList is empty (i.e. don't bother querying the database) return 0; } }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
public long getCountOfCollectionsWithDataInStudy(Study study) { long count = 0; if (study.getId() != null) { Collection<PhenoDataSetCollection> phenoCollectionColn = getPhenoCollectionByStudy(study); for (Iterator iterator = phenoCollectionColn.iterator(); iterator.hasNext();) { PhenoDataSetCollection phenoCollection = (PhenoDataSetCollection) iterator.next(); Criteria criteria = getSession().createCriteria(PhenoDataSetData.class); criteria.add(Restrictions.eq("phenCollection", phenoCollection)); ProjectionList projList = Projections.projectionList(); projList.add(Projections.countDistinct("collection")); criteria.setProjection(projList); List list = criteria.list(); count = count + ((Long) list.get(0)); }/* www .jav a 2 s . com*/ } return count; }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
public Long isCustomFieldUsed(PhenoDataSetData phenoData) { Long count = new Long("0"); PhenoDataSetField phenoDataSetField = phenoData.getPhenoDataSetFieldDisplay().getPhenoDataSetField(); Study study = phenoDataSetField.getStudy(); ArkFunction arkFunction = phenoDataSetField.getArkFunction(); Criteria criteria = getSession().createCriteria(PhenoDataSetData.class, "pd"); criteria.createAlias("pd.customFieldDisplay", "cfd"); criteria.createAlias("cfd.customField", "cf"); criteria.createAlias("cf.arkFunction", "aF"); criteria.createAlias("cf.study", "s"); criteria.add(Restrictions.eq("aF.id", arkFunction.getId())); criteria.add(Restrictions.eq("cfd.id", phenoData.getPhenoDataSetFieldDisplay().getId())); criteria.add(Restrictions.eq("s.id", study.getId())); count = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); return count; }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
public long getPhenoDataCount(PhenoDataSetCollection phenoCollection, PhenoDataSetCategory phenoDataSetCategory) { Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class); criteria.createAlias("phenoDataSetGroup", "qnaire"); if (phenoCollection.getQuestionnaire() != null) { criteria.add(Restrictions.eq("qnaire.id", phenoCollection.getQuestionnaire().getId())); }//from w ww . ja va 2 s .c o m criteria.setProjection(Projections.rowCount()); Long count = (Long) criteria.uniqueResult(); return count.intValue(); }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
public long getPhenoCollectionCount(PhenoDataCollectionVO collectionCriteria) { Criteria criteria = getSession().createCriteria(PhenoDataSetCollection.class); criteria.createAlias("questionnaire", "qnaire"); criteria.add(Restrictions.eq("linkSubjectStudy", collectionCriteria.getPhenoDataSetCollection().getLinkSubjectStudy())); // Just a precaution (PhenoCollection to should always map to a CustomFieldGroup where the ArkFunction will correspond to Pheno) //criteria.add(Restrictions.eq("qnaire.arkFunction", collectionCriteria.getArkFunction())); criteria.setProjection(Projections.rowCount()); Long count = (Long) criteria.uniqueResult(); return count; }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
public List<CustomField> getCustomFieldsLinkedToCustomFieldGroup(CustomFieldGroup customFieldCriteria) { Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class); criteria.add(Restrictions.eq("customFieldGroup", customFieldCriteria)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("customField")); criteria.setProjection(projectionList); criteria.addOrder(Order.asc("sequence")); List<CustomField> fieldsList = criteria.list(); //log.warn("______________customFieldsList = " + fieldsList.size()); return fieldsList; }