List of usage examples for org.hibernate Criteria createCriteria
public Criteria createCriteria(String associationPath) throws HibernateException;
From source file:edu.duke.cabig.c3pr.dao.PersonUserDao.java
License:BSD License
/** * Gets the research staff by organization ctep code from local. * * @param healthcareSite the healthcare site * @param isUser returns staff who are users if passed as true else returns all staff * @return the research staff by organization ctep code from local *//*from w w w. j a va2 s. c o m*/ public List<PersonUser> getResearchStaffByOrganizationCtepCodeFromLocal(HealthcareSite healthcareSite, boolean isUser) { //run a query against the updated database to get all research staff Criteria researchStaffCriteria = getHibernateTemplate().getSessionFactory().getCurrentSession() .createCriteria(PersonUser.class); if (isUser) { researchStaffCriteria.add(Expression.isNotNull("loginId")); } Criteria healthcareSiteCriteria = researchStaffCriteria.createCriteria("healthcareSites"); Criteria identifiersAssignedToOrganizationCriteria = healthcareSiteCriteria .createCriteria("identifiersAssignedToOrganization"); identifiersAssignedToOrganizationCriteria .add(Expression.eq("value", healthcareSite.getPrimaryIdentifier())); identifiersAssignedToOrganizationCriteria.add(Expression.eq("primaryIndicator", Boolean.TRUE)); return researchStaffCriteria.list(); }
From source file:edu.duke.cabig.c3pr.dao.StudyDao.java
License:BSD License
/** * Search by example.// w w w .j a va 2 s . c om * * @param study the exmple study * @param isWildCard the wild card * @param maxResults the max results * @param order the order * @param orderBy the order by * * @return the list< study> */ public List<Study> searchByExample(Study study, boolean isWildCard, int maxResults, String order, String orderBy) { List<Study> result = new ArrayList<Study>(); Example example = Example.create(study).excludeZeroes().ignoreCase(); Example subExample = Example.create(study.getStudyVersion()).excludeZeroes().ignoreCase(); Criteria studyCriteria = getSession().createCriteria(Study.class); if ("ascending".equals(order)) { studyCriteria.addOrder(Order.asc(orderBy)); } else if ("descending".equals(order)) { studyCriteria.addOrder(Order.desc(orderBy)); } studyCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); if (maxResults > 0) studyCriteria.setMaxResults(maxResults); if (isWildCard) { example.excludeProperty("doNotUse").enableLike(MatchMode.ANYWHERE); subExample.excludeProperty("doNotUse").enableLike(MatchMode.ANYWHERE); //studyCriteria.add(example); //studyCriteria.createCriteria("studyVersionsInternal").add(subExample); if (study.getIdentifiers().size() > 1) { studyCriteria.createCriteria("identifiers") .add(Restrictions.ilike("value", "%" + study.getIdentifiers().get(0).getValue() + "%")) .add(Restrictions.ilike("value", "%" + study.getIdentifiers().get(1).getValue() + "%")); } else if (study.getIdentifiers().size() > 0) { studyCriteria.createCriteria("identifiers") .add(Restrictions.ilike("value", "%" + study.getIdentifiers().get(0).getValue() + "%")); } //result = studyCriteria.list(); } studyCriteria.createCriteria("studyVersionsInternal").add(subExample); result = studyCriteria.add(example).list(); return result; }
From source file:edu.duke.cabig.c3pr.dao.StudySubjectDao.java
License:BSD License
/** * Reporting./*from ww w . ja v a 2 s . co m*/ * * @param registration * the registration * @param startDate * the start date * @param endDate * the end date * @param ccId * the cc id * * @return list of matching registration objects based on the date present * in the sample object that is passsed in. Also takes the date * range(startDate, endDate) and gets all objects having their * informedConsentSignedDate between these two dates. list of * StudySubject objects. */ public List<StudySubject> advancedSearch(StudySubject registration, Date startDate, Date endDate, String ccId) { Criteria registrationCriteria = getHibernateTemplate().getSessionFactory().getCurrentSession() .createCriteria(StudySubject.class); Criteria studySubjectStudyVersionCriteria = registrationCriteria .createCriteria("studySubjectStudyVersions"); Criteria studySubjectConsentVersionCriteria = studySubjectStudyVersionCriteria .createCriteria("studySubjectConsentVersionsInternal"); Criteria studySiteCriteria = studySubjectStudyVersionCriteria.createCriteria("studySiteStudyVersion") .createCriteria("studySite"); Criteria studySubjectDemographicsCriteria = registrationCriteria.createCriteria("studySubjectDemographics"); Criteria participantCriteria = studySubjectDemographicsCriteria.createCriteria("masterSubject"); Criteria studyCriteria = studySiteCriteria.createCriteria("studyInternal"); Criteria studyVersionCriteria = studyCriteria.createCriteria("studyVersionsInternal"); Criteria siteCriteria = studySiteCriteria.createCriteria("healthcareSite"); Criteria identifiersAssignedToOrganizationCriteria = siteCriteria .createCriteria("identifiersAssignedToOrganization"); Criteria identifiersCriteria = studyCriteria.createCriteria("identifiers"); // Study Criteria if (registration.getStudySite().getStudy().getShortTitleText() != null && !registration.getStudySite().getStudy().getShortTitleText().equals("")) { studyVersionCriteria.add(Expression.ilike("shortTitleText", "%" + registration.getStudySite().getStudy().getShortTitleText() + "%")); } // Site criteria if (registration.getStudySite().getHealthcareSite().getName() != null && !registration.getStudySite().getHealthcareSite().getName().equals("")) { siteCriteria.add(Expression.ilike("name", "%" + registration.getStudySite().getHealthcareSite().getName() + "%")); } if (registration.getStudySite().getHealthcareSite().getPrimaryIdentifier() != null && !registration.getStudySite().getHealthcareSite().getPrimaryIdentifier().equals("")) { identifiersAssignedToOrganizationCriteria.add(Expression.ilike("value", "%" + registration.getStudySite().getHealthcareSite().getPrimaryIdentifier() + "%")); } // registration consent criteria if (startDate != null && endDate != null) { studySubjectConsentVersionCriteria .add(Expression.between("informedConsentSignedTimestamp", startDate, endDate)); } else if (startDate != null) { studySubjectConsentVersionCriteria.add(Expression.ge("informedConsentSignedTimestamp", startDate)); } else if (endDate != null) { studySubjectConsentVersionCriteria.add(Expression.le("informedConsentSignedTimestamp", endDate)); } // participant/subject criteria if (registration.getStudySubjectDemographics().getMasterSubject().getBirthDate() != null) { participantCriteria.add(Expression.eq("birthDate", registration.getStudySubjectDemographics().getMasterSubject().getBirthDate())); } // if // (registration.getStudySubjectDemographics().getMasterSubject().getRaceCode() // != null // && // !registration.getStudySubjectDemographics().getMasterSubject().getRaceCode().equals("")) // { // participantCriteria.add(Expression.ilike("raceCode", "%" + // registration.getStudySubjectDemographics().getMasterSubject() // .getRaceCode() + "%" ) ); // } if (ccId != null && !ccId.equals("")) { identifiersCriteria.add(Expression.ilike("value", "%" + ccId + "%")); } registrationCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); registrationCriteria.addOrder(Order.asc("id")); return registrationCriteria.list(); }
From source file:edu.duke.cabig.c3pr.dao.StudySubjectDao.java
License:BSD License
/** * *.// w w w . j av a2s . c om * * @param registration * the registration * @param isWildCard * the is wild card * @param maxResults * the max results * * @return list of matching registration objects based on your sample * registration object */ public List<StudySubject> searchByExample(StudySubject registration, boolean isWildCard, int maxResults) { List<StudySubject> result = new ArrayList<StudySubject>(); Example example = Example.create(registration).excludeZeroes().ignoreCase(); try { Criteria studySubjectCriteria = getSession().createCriteria(StudySubject.class); studySubjectCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); if (isWildCard) { example.excludeProperty("doNotUse").enableLike(MatchMode.ANYWHERE); studySubjectCriteria.add(example); if (maxResults > 0) studySubjectCriteria.setMaxResults(maxResults); if (registration.getIdentifiers().size() > 1) { studySubjectCriteria.createCriteria("identifiers") .add(Restrictions.ilike("value", "%" + registration.getIdentifiers().get(0).getValue() + "%")) .add(Restrictions.ilike("value", "%" + registration.getIdentifiers().get(1).getValue() + "%")); } else if (registration.getIdentifiers().size() > 0) { studySubjectCriteria.createCriteria("identifiers").add(Restrictions.ilike("value", "%" + registration.getIdentifiers().get(0).getValue() + "%")); } result = studySubjectCriteria.list(); } result = studySubjectCriteria.add(example).list(); } catch (Exception e) { log.error(e.getMessage()); } return result; }
From source file:edu.duke.cabig.c3pr.dao.StudySubjectDao.java
License:BSD License
/** * *./*from w ww . j a v a2s. c o m*/ * * @param registration * the registration * * @return list of matching registration objects based on your sample * registration object */ public List<StudySubject> searchBySubjectAndStudySite(StudySubject registration) { Example example = Example.create(registration).excludeZeroes().ignoreCase(); Criteria registrationCriteria = getHibernateTemplate().getSessionFactory().getCurrentSession() .createCriteria(StudySubject.class); registrationCriteria.add(example); Criteria studySubjectDemographicsCriteria = registrationCriteria.createCriteria("studySubjectDemographics"); studySubjectDemographicsCriteria.createCriteria("masterSubject") .add(Restrictions.eq("id", registration.getStudySubjectDemographics().getMasterSubject().getId())); registrationCriteria.createCriteria("studySubjectStudyVersions").createCriteria("studySiteStudyVersion") .createCriteria("studySite").add(Restrictions.eq("id", registration.getStudySite().getId())); return registrationCriteria.list(); }
From source file:edu.duke.cabig.c3pr.dao.StudySubjectDao.java
License:BSD License
/** * Search by scheduled epoch./*w ww .ja v a 2 s . c om*/ * * @param scheduledEpoch * the scheduled epoch * * @return the list< study subject> */ public List<StudySubject> searchByScheduledEpoch(ScheduledEpoch scheduledEpoch) { StudySubject registration = new StudySubject(true); Example example = Example.create(registration).excludeZeroes().ignoreCase(); Criteria registrationCriteria = getHibernateTemplate().getSessionFactory().getCurrentSession() .createCriteria(StudySubject.class); registrationCriteria.add(example); registrationCriteria.createCriteria("studySubjectStudyVersions").createCriteria("scheduledEpochs") .createCriteria("epoch").add(Restrictions.eq("id", scheduledEpoch.getEpoch().getId())); return registrationCriteria.list(); }
From source file:edu.ku.brc.specify.dbsupport.customqueries.CustomStatQueries.java
License:Open Source License
protected boolean overdueLoans() { //String sql = "select loanId from Loan where (not (currentDueDate is null)) and (IsClosed = false or IsClosed is null) and datediff(CURDATE(), currentduedate) > 0; //select count(loanid) as OpenLoanCount from loan where loanid in (select loanid from loan where (not (currentduedate is null)) and loan.IsGift = false and (IsClosed = false or IsClosed is null) and datediff(CURDATE(), currentduedate) > 0) Session session = HibernateUtil.getNewSession(); Calendar today = Calendar.getInstance(); Criteria criteria = session.createCriteria(Loan.class); criteria.add(Restrictions.isNotNull("currentDueDate")); criteria.add(Restrictions.lt("currentDueDate", today)); criteria.add(Restrictions.or(Restrictions.isNull("isClosed"), Restrictions.eq("isClosed", false))); Criteria dsp = criteria.createCriteria("discipline"); dsp.add(Restrictions.eq("disciplineId", AppContextMgr.getInstance().getClassObject(Discipline.class).getDisciplineId())); criteria.setProjection(Projections.rowCount()); resultsList = criteria.list();/*from w ww. jav a 2s . co m*/ /*for (Object data : resultsList) { System.out.println("overdueLoans "+data); }*/ session.close(); return true; }
From source file:edu.monash.merc.dao.AccessionDAO.java
License:Open Source License
/** * {@inheritDoc}/*from w w w .j a v a2s . co m*/ */ public Accession getAccessionByAccessionAcType(String accession, String acType) { Criteria aCriteria = this.session().createCriteria(this.persistClass); aCriteria.add(Restrictions.eq("accession", accession)); Criteria actCriteria = aCriteria.createCriteria("acType"); actCriteria.add(Restrictions.eq("acType", acType)); return (Accession) aCriteria.uniqueResult(); }
From source file:edu.monash.merc.dao.GeneDAO.java
License:Open Source License
/** * {@inheritDoc}/* w ww .j a v a2s . c o m*/ */ public Gene getGeneByEnsgAndDbVersion(String ensgAccession, String dbSource, Date versionTime) { Criteria qCriteria = this.session().createCriteria(this.persistClass); Criteria dbsCriteria = qCriteria.createCriteria("dbSource"); qCriteria.add(Restrictions.eq("ensgAccession", ensgAccession).ignoreCase()) .add(Restrictions.eq("createdTime", versionTime)); dbsCriteria.add(Restrictions.eq("dbName", dbSource).ignoreCase()); return (Gene) qCriteria.uniqueResult(); }
From source file:edu.monash.merc.dao.PEEvidenceDAO.java
License:Open Source License
/** * {@inheritDoc}/* w w w . j a va 2s. co m*/ */ public PEEvidence getPESummaryByGeneAndType(long geneId, DataType dataType) { Criteria peCriteria = this.session().createCriteria(this.persistClass); Criteria gCriteria = peCriteria.createCriteria("gene"); Criteria dtypeCriteria = peCriteria.createCriteria("tpbDataType"); gCriteria.add(Restrictions.eq("id", geneId)); Disjunction dtypeOr = Restrictions.disjunction(); //PE if (dataType.equals(DataType.PE)) { dtypeOr.add(Restrictions.eq("dataType", DataType.PE.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_MS.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_MS_ANN.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_MS_PROB.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_MS_SAM.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI_ANN.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI_IHC.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI_IHC_NORM.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_OTH.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_OTH_CUR.type())); dtypeCriteria.add(dtypeOr); } else if (dataType.equals(DataType.PE_MS)) { dtypeOr.add(Restrictions.eq("dataType", DataType.PE_MS.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_MS_ANN.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_MS_PROB.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_MS_SAM.type())); dtypeCriteria.add(dtypeOr); } else if (dataType.equals(DataType.PE_MS_ANN)) { dtypeCriteria.add(Restrictions.eq("dataType", DataType.PE_MS_ANN.type())); } else if (dataType.equals(DataType.PE_MS_PROB)) { dtypeCriteria.add(Restrictions.eq("dataType", DataType.PE_MS_PROB.type())); } else if (dataType.equals(DataType.PE_MS_SAM)) { dtypeCriteria.add(Restrictions.eq("dataType", DataType.PE_MS_SAM.type())); } else if (dataType.equals(DataType.PE_ANTI)) { dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI_ANN.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI_IHC.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI_IHC_NORM.type())); dtypeCriteria.add(dtypeOr); } else if (dataType.equals(DataType.PE_ANTI_ANN)) { dtypeCriteria.add(Restrictions.eq("dataType", DataType.PE_ANTI_ANN.type())); } else if (dataType.equals(DataType.PE_ANTI_IHC)) { dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI_IHC.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI_IHC_NORM.type())); dtypeCriteria.add(dtypeOr); } else if (dataType.equals(DataType.PE_ANTI_IHC_NORM)) { dtypeOr.add(Restrictions.eq("dataType", DataType.PE_ANTI_IHC_NORM.type())); dtypeCriteria.add(dtypeOr); } else if (dataType.equals(DataType.PE_OTH)) { dtypeOr.add(Restrictions.eq("dataType", DataType.PE_OTH.type())); dtypeOr.add(Restrictions.eq("dataType", DataType.PE_OTH_CUR.type())); dtypeCriteria.add(dtypeOr); } else if (dataType.equals(DataType.PE_OTH_CUR)) { dtypeCriteria.add(Restrictions.eq("dataType", DataType.PE_OTH_CUR.type())); } else { //nothing to be added } peCriteria.addOrder(Order.desc("colorLevel")); peCriteria.setMaxResults(1); return (PEEvidence) peCriteria.uniqueResult(); }