List of usage examples for org.hibernate Criteria add
public Criteria add(Criterion criterion);
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
/** * Look up a Person based on the supplied Long ID that represents a Person primary key. This id is the primary key of the Person table that can * represent a subject or contact./*from w w w. j av a 2 s . c o m*/ * * @param personId * @return * @throws EntityNotFoundException * @throws ArkSystemException */ public Person getPerson(Long personId) throws EntityNotFoundException, ArkSystemException { Criteria personCriteria = getSession().createCriteria(Person.class); personCriteria.add(Restrictions.eq(Constants.ID, personId)); List<Person> listOfPerson = personCriteria.list(); if (listOfPerson != null && listOfPerson.size() > 0) { return listOfPerson.get(0); } else { throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found."); } }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Phone> getPersonPhoneList(Long personId) throws ArkSystemException { Criteria phoneCriteria = getSession().createCriteria(Phone.class); phoneCriteria.add(Restrictions.eq(Constants.PERSON_PERSON_ID, personId)); List<Phone> personPhoneList = phoneCriteria.list(); //log.info("Number of phones fetched " + personPhoneList.size() + " Person Id" + personId.intValue()); if (personPhoneList.isEmpty()) { log.error("this person has no phone; " + personId); // throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found."); }// www .j a va 2 s. c o m //log.info("Number of phone items retrieved for person Id " + personId + " " + personPhoneList.size()); return personPhoneList; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Phone> getPersonPhoneList(Long personId, Phone phone) throws ArkSystemException { Criteria phoneCriteria = getSession().createCriteria(Phone.class); if (personId != null) { phoneCriteria.add(Restrictions.eq(Constants.PERSON_PERSON_ID, personId)); }/* w w w. j a va 2 s . c om*/ if (phone != null) { if (phone.getId() != null) { phoneCriteria.add(Restrictions.eq(Constants.PHONE_ID, phone.getId())); } if (phone.getPhoneNumber() != null) { phoneCriteria.add(Restrictions.ilike(Constants.PHONE_NUMBER, phone.getPhoneNumber())); } if (phone.getPhoneType() != null) { phoneCriteria.add(Restrictions.eq(Constants.PHONE_TYPE, phone.getPhoneType())); } if (phone.getAreaCode() != null) { phoneCriteria.add(Restrictions.eq(Constants.AREA_CODE, phone.getAreaCode())); } phoneCriteria.setFetchMode("silentMode", FetchMode.JOIN); } List<Phone> personPhoneList = phoneCriteria.list(); //log.info("Number of phones fetched " + personPhoneList.size() + " Person Id" + personId.intValue()); //if (personPhoneList.isEmpty()) { // throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found."); // log.info(" personId " + personId + " had no phones. No drama"); // } return personPhoneList; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
/** * Looks up all the addresses for a person. * /*from w w w . j a v a 2s. c om*/ * @param personId * @param address * @return List<Address> * @throws EntityNotFoundException * @throws ArkSystemException */ @SuppressWarnings("unchecked") public List<Address> getPersonAddressList(Long personId, Address address) throws ArkSystemException { Criteria criteria = getSession().createCriteria(Address.class); if (personId != null) { criteria.add(Restrictions.eq(Constants.PERSON_PERSON_ID, personId)); } if (address != null) { // Add criteria for address if (address.getStreetAddress() != null) { criteria.add(Restrictions.ilike(Constants.STREET_ADDRESS, address.getStreetAddress(), MatchMode.ANYWHERE)); } if (address.getCountry() != null) { criteria.add(Restrictions.eq(Constants.COUNTRY_NAME, address.getCountry())); } if (address.getPostCode() != null) { criteria.add(Restrictions.eq(Constants.POST_CODE, address.getPostCode())); } if (address.getCity() != null) { criteria.add(Restrictions.ilike(Constants.CITY, address.getCity())); } if (address.getState() != null) { criteria.add(Restrictions.eq(Constants.STATE_NAME, address.getState())); } if (address.getAddressType() != null) { criteria.add(Restrictions.eq(Constants.ADDRESS_TYPE, address.getAddressType())); } } List<Address> personAddressList = criteria.list(); // if (personAddressList.isEmpty()) { // throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found."); // log.info("person " + personId + " does not have any addresses"); // } return personAddressList; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public List<Consent> searchConsent(Consent consent) throws EntityNotFoundException, ArkSystemException { Criteria criteria = getSession().createCriteria(Consent.class); if (consent != null) { criteria.add(Restrictions.eq("study.id", consent.getStudy().getId())); if (consent.getStudyComp() != null) { criteria.add(Restrictions.eq("studyComp", consent.getStudyComp())); }// w ww . ja v a 2 s .c o m if (consent.getStudyComponentStatus() != null) { criteria.add(Restrictions.eq("studyComponentStatus", consent.getStudyComponentStatus())); } if (consent.getConsentedBy() != null) { criteria.add(Restrictions.ilike("consentedBy", consent.getConsentedBy(), MatchMode.ANYWHERE)); } if (consent.getConsentStatus() != null) { criteria.add(Restrictions.eq("consentStatus", consent.getConsentStatus())); } if (consent.getConsentDate() != null) { criteria.add(Restrictions.eq("consentDate", consent.getConsentDate())); } if (consent.getConsentType() != null) { criteria.add(Restrictions.eq("consentType", consent.getConsentType())); } } return criteria.list(); }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Consent> searchConsent(ConsentVO consentVO) throws EntityNotFoundException, ArkSystemException { Criteria criteria = getSession().createCriteria(Consent.class); if (consentVO != null) { criteria.add(Restrictions.eq("study.id", consentVO.getConsent().getStudy().getId())); // must only get consents for subject in context criteria.add(Restrictions.eq("linkSubjectStudy", consentVO.getConsent().getLinkSubjectStudy())); if (consentVO.getConsent().getStudyComp() != null) { criteria.add(Restrictions.eq("studyComp", consentVO.getConsent().getStudyComp())); }//from w w w. j ava2 s .c o m if (consentVO.getConsent().getStudyComponentStatus() != null) { criteria.add( Restrictions.eq("studyComponentStatus", consentVO.getConsent().getStudyComponentStatus())); } if (consentVO.getConsent().getConsentedBy() != null) { criteria.add(Restrictions.ilike("consentedBy", consentVO.getConsent().getConsentedBy(), MatchMode.ANYWHERE)); } if (consentVO.getConsent().getConsentStatus() != null) { criteria.add(Restrictions.eq("consentStatus", consentVO.getConsent().getConsentStatus())); } if (consentVO.getConsent().getConsentDate() != null) { criteria.add(Restrictions.between("consentDate", consentVO.getConsent().getConsentDate(), consentVO.getConsentDateEnd())); } if (consentVO.getConsent().getConsentType() != null) { criteria.add(Restrictions.eq("consentType", consentVO.getConsent().getConsentType())); } } List<Consent> list = criteria.list(); return list; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public List<Correspondences> getCorrespondenceList(LinkSubjectStudy lss, Correspondences correspondence) throws ArkSystemException { Criteria criteria = getSession().createCriteria(Correspondences.class, "co"); criteria.createAlias("lss", "lss", JoinType.LEFT_OUTER_JOIN); //criteria.createAlias("study", "st", JoinType.LEFT_OUTER_JOIN); //criteria.createAlias("st.parentStudy", "pstudy", JoinType.LEFT_OUTER_JOIN); if (lss != null) { criteria.add(Restrictions.eq("lss", lss)); }/* w ww. jav a 2 s .c o m*/ if (correspondence != null) { // Check context study is match with correspondence study or it's parent study if (correspondence.getLss() != null && correspondence.getLss().getStudy() != null) { criteria.add(Restrictions.disjunction() .add(Restrictions.eq("lss.study", correspondence.getLss().getStudy())));//.add(Restrictions.eq("pstudy", correspondence.getLss().getStudy()))); } if (correspondence.getCorrespondenceDirectionType() != null) { criteria.add(Restrictions.eq("co.correspondenceDirectionType", correspondence.getCorrespondenceDirectionType())); } if (correspondence.getCorrespondenceModeType() != null) { criteria.add( Restrictions.eq("co.correspondenceModeType", correspondence.getCorrespondenceModeType())); } if (correspondence.getCorrespondenceOutcomeType() != null) { criteria.add(Restrictions.eq("co.correspondenceOutcomeType", correspondence.getCorrespondenceOutcomeType())); } if (correspondence.getDate() != null) { criteria.add(Restrictions.eq("co.date", correspondence.getDate())); } if (correspondence.getTime() != null) { criteria.add(Restrictions.eq("co.time", correspondence.getTime())); } if (correspondence.getDetails() != null) { criteria.add(Restrictions.ilike("co.details", correspondence.getDetails(), MatchMode.ANYWHERE)); } if (correspondence.getReason() != null) { criteria.add(Restrictions.ilike("co.reason", correspondence.getDetails(), MatchMode.ANYWHERE)); } if (correspondence.getComments() != null) { criteria.add(Restrictions.ilike("co.comments", correspondence.getComments(), MatchMode.ANYWHERE)); } if (correspondence.getOperator() != null) { criteria.add(Restrictions.eq("co.operator", correspondence.getOperator())); } } List<Correspondences> personCorrespondenceList = criteria.list(); return personCorrespondenceList; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public List<ConsentFile> searchConsentFile(ConsentFile consentFile) throws EntityNotFoundException, ArkSystemException { Criteria criteria = getSession().createCriteria(ConsentFile.class); if (consentFile != null) { if (consentFile.getId() != null) { criteria.add(Restrictions.eq("id", consentFile.getId())); }//from w w w . ja v a 2s .c om if (consentFile.getConsent() != null) { criteria.add(Restrictions.eq("consent", consentFile.getConsent())); } if (consentFile.getFilename() != null) { criteria.add(Restrictions.ilike("filename", consentFile.getFilename(), MatchMode.ANYWHERE)); } } criteria.addOrder(Order.desc("id")); @SuppressWarnings("unchecked") List<ConsentFile> list = criteria.list(); return list; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
private boolean isSubjectUIDUnique(String subjectUID, Long studyId, String action) { boolean isUnique = true; Session session = getSession();//from w w w . j a v a 2 s. c o m Criteria criteria = session.createCriteria(LinkSubjectStudy.class); criteria.add(Restrictions.eq("subjectUID", subjectUID)); criteria.add(Restrictions.eq("study.id", studyId)); if (action.equalsIgnoreCase(au.org.theark.core.Constants.ACTION_INSERT)) { if (criteria.list().size() > 0) { isUnique = false; } } else if (action.equalsIgnoreCase(au.org.theark.core.Constants.ACTION_UPDATE)) { if (criteria.list().size() > 1) { isUnique = false; } } return isUnique; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
private ConsentOption getConsentOption(String value) { Criteria criteria = getSession().createCriteria(ConsentOption.class); criteria.add(Restrictions.ilike("name", value)); return (ConsentOption) criteria.list().get(0); }