List of usage examples for org.hibernate Criteria setFetchMode
public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException;
From source file:at.ac.tuwien.ifs.tita.dao.GenericHibernateDao.java
License:Apache License
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public T findById(ID id, String... joinProps) { T myEntity = null;/*w w w .j a va 2 s . c o m*/ Criteria criteria = null; try { criteria = getSession().createCriteria(this.persistenceClass); criteria.add(Restrictions.idEq(id)); for (String prop : joinProps) { criteria.setFetchMode(prop, FetchMode.JOIN); } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); myEntity = (T) criteria.uniqueResult(); } catch (Exception e) { throw new PersistenceException("Fehler beim lesen eines Entities: Class=" + this.persistenceClass.getSimpleName() + " Key=" + id.toString() + "\n" + e.getMessage(), e); } return myEntity; }
From source file:at.molindo.esi4j.module.hibernate.scrolling.DefaultQueryScrollingSession.java
License:Apache License
@Override public List<?> fetch(Session session, int batchSize) { Criteria criteria = session.createCriteria(_type); if (_lastId != null) { criteria.add(Restrictions.gt("id", _lastId)); }//from ww w . jav a 2s . com criteria.addOrder(Order.asc("id")); criteria.setMaxResults(batchSize); criteria.setCacheable(false); for (Map.Entry<String, FetchMode> e : _fetchModes.entrySet()) { criteria.setFetchMode(e.getKey(), e.getValue()); } List<?> list = criteria.list(); if (list.size() > 0) { ClassMetadata meta = session.getSessionFactory().getClassMetadata(_type); Object last = list.get(list.size() - 1); _lastId = meta.getIdentifier(last, (SessionImpl) session); } return list; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public GenderType getSubjectGenderType(final String subjectUID, final Long studyId) { GenderType genderType = null;//from www .ja v a 2s .c om Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class, "lss"); criteria.createAlias("study", "st", JoinType.INNER_JOIN); criteria.createAlias("person", "per", JoinType.INNER_JOIN); criteria.createAlias("per.genderType", "gen", JoinType.INNER_JOIN); criteria.setFetchMode("person", FetchMode.JOIN); criteria.add(Restrictions.eq("st.id", studyId)); criteria.add(Restrictions.eq("lss.subjectUID", subjectUID)); List list = criteria.list(); if (list.size() > 0) { LinkSubjectStudy subject = (LinkSubjectStudy) list.get(0); genderType = subject.getPerson().getGenderType(); } return genderType; }
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 .ja v a 2s . co m*/ 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
public RelationshipVo getSubjectRelative(final String subjectUID, final Long studyId) { List<RelationshipVo> relatives = new ArrayList<RelationshipVo>(); Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class, "sub"); criteria.createAlias("sub.study", "substudy", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("sub.person", "subPerson", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("subPerson.genderType", "subGender", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("subPerson.vitalStatus", "subVitStatus", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("substudy.pedigreeConfiguration", "spc", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("spc.customField", "cf", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("cf.customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("sub.subjectCustomFieldDataSet", "scfd", JoinType.LEFT_OUTER_JOIN, Restrictions.eqProperty("cfd.id", "scfd.customFieldDisplay.id")); criteria.add(Restrictions.eq("sub.subjectUID", subjectUID)); criteria.add(Restrictions.eq("substudy.id", studyId)); criteria.setFetchMode("subject", FetchMode.JOIN); criteria.setFetchMode("relative", FetchMode.JOIN); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("sub.subjectUID"), "individualId"); projectionList.add(Projections.property("subGender.name"), "gender"); projectionList.add(Projections.property("subPerson.dateOfBirth"), "dob"); projectionList.add(Projections.property("subPerson.dateOfDeath"), "dod"); projectionList.add(Projections.property("subVitStatus.name"), "deceased"); projectionList.add(Projections.property("scfd.textDataValue"), "affectedStatus"); criteria.setProjection(projectionList); criteria.setResultTransformer(Transformers.aliasToBean(RelationshipVo.class)); relatives = criteria.list();/*from w ww. j a v a 2s. co m*/ return relatives.size() > 0 ? relatives.get(0) : null; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public List<RelationshipVo> getSubjectParentRelatives(final String subjectUID, final Long studyId) { List<RelationshipVo> relatives = new ArrayList<RelationshipVo>(); Criteria criteria = getSession().createCriteria(LinkSubjectPedigree.class, "lsp"); criteria.createAlias("subject", "sub", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("sub.study", "substudy", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("relative", "rel", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("rel.study", "relstudy", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("relationship", "type", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("rel.person", "relPerson", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("relPerson.genderType", "relGender", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("relPerson.vitalStatus", "relVitStatus", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("relstudy.pedigreeConfiguration", "spc", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("spc.customField", "cf", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("cf.customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("rel.subjectCustomFieldDataSet", "scfd", JoinType.LEFT_OUTER_JOIN, Restrictions.eqProperty("cfd.id", "scfd.customFieldDisplay.id")); criteria.add(Restrictions.eq("sub.subjectUID", subjectUID)); criteria.add(Restrictions.eq("substudy.id", studyId)); criteria.add(Restrictions.eq("relstudy.id", studyId)); criteria.setFetchMode("subject", FetchMode.JOIN); criteria.setFetchMode("relative", FetchMode.JOIN); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("lsp.id"), "id"); projectionList.add(Projections.property("rel.subjectUID"), "individualId"); projectionList.add(Projections.property("relGender.name"), "gender"); projectionList.add(Projections.property("relPerson.dateOfBirth"), "dob"); projectionList.add(Projections.property("relPerson.dateOfDeath"), "dod"); projectionList.add(Projections.property("relPerson.firstName"), "firstName"); projectionList.add(Projections.property("relPerson.lastName"), "lastName"); projectionList.add(Projections.property("relVitStatus.name"), "deceased"); projectionList.add(Projections.property("scfd.textDataValue"), "affectedStatus"); criteria.setProjection(projectionList); criteria.setResultTransformer(Transformers.aliasToBean(RelationshipVo.class)); relatives = criteria.list();/*from w ww . j a va2s. co m*/ return relatives; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public List<RelationshipVo> getSubjectChildRelatives(final String subjectUID, final Long studyId) { List<RelationshipVo> relatives = new ArrayList<RelationshipVo>(); Criteria criteria = getSession().createCriteria(LinkSubjectPedigree.class, "lsp"); criteria.createAlias("subject", "sub", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("sub.study", "substudy", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("relative", "rel", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("rel.study", "relstudy", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("relationship", "type", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("sub.person", "subPerson", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("subPerson.genderType", "subGender", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("subPerson.vitalStatus", "subVitStatus", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("substudy.pedigreeConfiguration", "spc", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("spc.customField", "cf", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("cf.customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("sub.subjectCustomFieldDataSet", "scfd", JoinType.LEFT_OUTER_JOIN, Restrictions.eqProperty("cfd.id", "scfd.customFieldDisplay.id")); criteria.add(Restrictions.eq("rel.subjectUID", subjectUID)); criteria.add(Restrictions.eq("substudy.id", studyId)); criteria.add(Restrictions.eq("relstudy.id", studyId)); criteria.setFetchMode("subject", FetchMode.JOIN); criteria.setFetchMode("relative", FetchMode.JOIN); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("lsp.id"), "id"); projectionList.add(Projections.property("sub.subjectUID"), "individualId"); projectionList.add(Projections.property("subGender.name"), "gender"); projectionList.add(Projections.property("subPerson.dateOfBirth"), "dob"); projectionList.add(Projections.property("subPerson.dateOfDeath"), "dod"); projectionList.add(Projections.property("subPerson.firstName"), "firstName"); projectionList.add(Projections.property("subPerson.lastName"), "lastName"); projectionList.add(Projections.property("subVitStatus.name"), "deceased"); projectionList.add(Projections.property("scfd.textDataValue"), "affectedStatus"); criteria.setProjection(projectionList); criteria.setResultTransformer(Transformers.aliasToBean(RelationshipVo.class)); relatives = criteria.list();/*w ww. j a v a 2s . co m*/ return relatives; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public List<LinkSubjectTwin> getTwins(final Set<String> subjectUids, final Long studyId) { List<LinkSubjectTwin> twins = new ArrayList<LinkSubjectTwin>(); Criteria criteria = getSession().createCriteria(LinkSubjectTwin.class, "lst"); criteria.createAlias("firstSubject", "lssa", JoinType.INNER_JOIN); criteria.createAlias("lssa.study", "sta", JoinType.INNER_JOIN); criteria.createAlias("secondSubject", "lssb", JoinType.INNER_JOIN); criteria.createAlias("lssb.study", "stb", JoinType.INNER_JOIN); criteria.setFetchMode("firstSubject", FetchMode.JOIN); criteria.setFetchMode("secondSubject", FetchMode.JOIN); criteria.setFetchMode("twinType", FetchMode.JOIN); criteria.add(Restrictions.eq("sta.id", studyId)); criteria.add(Restrictions.eq("stb.id", studyId)); Disjunction or = Restrictions.disjunction(); or.add(Restrictions.in("lssa.subjectUID", subjectUids)); or.add(Restrictions.in("lssb.subjectUID", subjectUids)); criteria.add(or);// w w w.ja v a2s .c o m twins = criteria.list(); return twins; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public StudyPedigreeConfiguration getStudyPedigreeConfiguration(Long studyId) { StudyPedigreeConfiguration pedigreeConfig = null; Criteria criteria = getSession().createCriteria(StudyPedigreeConfiguration.class, "spc"); criteria.createAlias("study", "st", JoinType.INNER_JOIN); criteria.setFetchMode("customField", FetchMode.JOIN); criteria.add(Restrictions.eq("st.id", studyId)); List<StudyPedigreeConfiguration> list = criteria.list(); pedigreeConfig = list.size() == 1 ? list.get(0) : new StudyPedigreeConfiguration(); return pedigreeConfig; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
/** * Genenal Phone search./* w w w .j a v a 2 s. c om*/ * @param personId * @param phone * @return */ private Criteria buildGeneralPhoneCriteria(Long personId, Phone phone) { Criteria phoneCriteria = getSession().createCriteria(Phone.class); if (personId != null) { phoneCriteria.add(Restrictions.eq(Constants.PERSON_PERSON_ID, personId)); } 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); } return phoneCriteria; }