List of usage examples for org.hibernate Criteria setMaxResults
public Criteria setMaxResults(int maxResults);
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
public Phone getHomePhone(LinkSubjectStudy subject) { Phone result = null;/* w w w . j a v a2s . c om*/ Criteria criteria = getSession().createCriteria(Phone.class); criteria.add(Restrictions.eq("person", subject.getPerson())); criteria.createAlias("phoneType", "pt"); criteria.add(Restrictions.eq("pt.name", "Home")); criteria.setMaxResults(1); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("areaCode"), "areaCode"); projectionList.add(Projections.property("phoneNumber"), "phoneNumber"); criteria.setProjection(projectionList); // only return fields required for report criteria.setResultTransformer(Transformers.aliasToBean(Phone.class)); if (criteria.uniqueResult() != null) { result = (Phone) criteria.uniqueResult(); } return result; }
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
public Consent getStudyCompConsent(Consent consent) { // Note: Should never be possible to have more than one Consent record for a // given a particular subject and study component Criteria criteria = getSession().createCriteria(Consent.class); if (consent != null) { criteria.add(Restrictions.eq("study.id", consent.getStudy().getId())); // must only get consents for subject in context criteria.add(Restrictions.eq("linkSubjectStudy.id", consent.getLinkSubjectStudy().getId())); // must only get consents for specific studyComp criteria.add(Restrictions.eq("studyComp.id", consent.getStudyComp().getId())); // Do NOT constrain against consentStatus or consentDate here, because we want to be able to // tell if they are "Not Consented" vs "Consented" with different consentStatus or consentDate. // if (consent.getConsentStatus() != null) // {//from w ww.j av a 2 s.co m // criteria.add(Restrictions.eq("consentStatus.id", consent.getConsentStatus().getId())); // } // // if (consent.getConsentDate() != null) // { // criteria.add(Restrictions.eq("consentDate", consent.getConsentDate())); // } } ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("studyComp"), "studyComp"); projectionList.add(Projections.property("consentStatus"), "consentStatus"); projectionList.add(Projections.property("consentDate"), "consentDate"); criteria.setProjection(projectionList); criteria.setMaxResults(1); criteria.setResultTransformer(Transformers.aliasToBean(Consent.class)); Consent result = (Consent) criteria.uniqueResult(); return result; }
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
protected ArkFunction getArkFunctionByName(String functionName) { Criteria criteria = getSession().createCriteria(ArkFunction.class); criteria.add(Restrictions.eq("name", functionName)); criteria.setMaxResults(1); ArkFunction arkFunction = (ArkFunction) criteria.uniqueResult(); return arkFunction; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
protected SubjectUidSequence getSubjectUidSequence(Study study) { // log.info("Getting uid seq entity for study " + study.getName()); // Stateless sessions should be used to avoid locking the record for future update // by getSession(), which relies on the "open session filter" mechanism StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(SubjectUidSequence.class); criteria.add(Restrictions.eq(Constants.SUBJECTUIDSEQ_STUDYNAMEID, study.getName())); criteria.setMaxResults(1); SubjectUidSequence result = (SubjectUidSequence) criteria.uniqueResult(); session.close();// w w w .j a v a 2 s. c o m log.warn("and got entity with lock = " + result.getInsertLock() + " for study " + study.getName()); return result; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public LinkSubjectStudy getSubjectLinkedToStudy(Long personId, Study study) throws EntityNotFoundException, ArkSystemException { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); Person person = getPerson(personId); criteria.add(Restrictions.eq("person", person)); criteria.add(Restrictions.eq("study", study)); criteria.setMaxResults(1); return (LinkSubjectStudy) criteria.uniqueResult(); }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public boolean isStudyCompUnique(String studyComponentName, Study study, StudyComp studyComponentToUpdate) { boolean isUnique = true; StatelessSession stateLessSession = getStatelessSession(); Criteria criteria = stateLessSession.createCriteria(StudyComp.class); criteria.add(Restrictions.eq("name", studyComponentName)); criteria.add(Restrictions.eq("study", study)); criteria.setMaxResults(1); StudyComp existingComponent = (StudyComp) criteria.uniqueResult(); if ((studyComponentToUpdate.getId() != null && studyComponentToUpdate.getId() > 0)) { if (existingComponent != null && !studyComponentToUpdate.getId().equals(existingComponent.getId())) { isUnique = false;/*from www. j a v a 2 s.c o m*/ } } else { if (existingComponent != null) { isUnique = false; } } stateLessSession.close(); return isUnique; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
/** * Pageable person phone list./*from www . j a v a2 s.com*/ */ public List<Phone> pageablePersonPhoneLst(Long personId, Phone phoneCriteria, int first, int count) { Criteria criteria = buildGeneralPhoneCriteria(personId, phoneCriteria); criteria.setFirstResult(first); criteria.setMaxResults(count); List<Phone> personPhoneList = criteria.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
public List<Address> pageablePersonAddressLst(Long personId, Address addressCriteria, int first, int count) { Criteria criteria = buildGeneralAddressCriteria(personId, addressCriteria); criteria.setFirstResult(first);//from w w w . jav a 2s . co m criteria.setMaxResults(count); List<Address> personAddressList = criteria.list(); //log.info("Number of phones fetched " + personPhoneList.size() + " Person Id" + personId.intValue()); if (personAddressList.isEmpty()) { // throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found."); log.info(" personId " + personId + " had no addresses. No drama"); } return personAddressList; }
From source file:be.redlab.examples.databasetesting.common.AbstractJpaDao.java
License:Apache License
protected List<T> findByCriteria(final int firstResult, final int maxResults, final Order order, final Criterion... criterion) { Session session = (Session) getEntityManager().getDelegate(); Criteria crit = session.createCriteria(getEntityClass()); for (final Criterion c : criterion) { crit.add(c);//from w w w .j a v a 2 s.c o m } if (order != null) { crit.addOrder(order); } if (firstResult > 0) { crit.setFirstResult(firstResult); } if (maxResults > 0) { crit.setMaxResults(maxResults); } return crit.list(); }
From source file:benedict.zhang.addon.persistence.PersistenceManager.java
public AddonDescription loadAddonDescription() { session = sessionFactory.openSession(); session.beginTransaction();/*from ww w .j a va 2 s. c om*/ Criteria criteria = session.createCriteria(AddonDescription.class); criteria.addOrder(Order.desc("version")); criteria.setMaxResults(1); List addonDescriptions = criteria.list(); AddonDescription addonDescription = null; if (addonDescriptions.isEmpty()) { addonDescription = new AddonDescription(); session.save(addonDescription); } else { addonDescription = (AddonDescription) addonDescriptions.get(0); } session.getTransaction().commit(); session.close(); return addonDescription; }