List of usage examples for org.hibernate FetchMode JOIN
FetchMode JOIN
To view the source code for org.hibernate FetchMode JOIN.
Click Source Link
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public List<PointOfContact> findOtherPointOfContactsBySampleId(String sampleId) throws Exception { if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) { throw new NoAccessException("User has no access to the sample " + sampleId); }//from w ww. j a va2s. co m CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .add(Property.forName("id").eq(new Long(sampleId))); crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); List<PointOfContact> pointOfContacts = new ArrayList<PointOfContact>(); for (int i = 0; i < results.size(); i++) { Sample sample = (Sample) results.get(i); Collection<PointOfContact> otherPOCs = sample.getOtherPointOfContactCollection(); for (PointOfContact poc : otherPOCs) { pointOfContacts.add(poc); } } return pointOfContacts; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public Sample findSampleById(String sampleId) throws Exception { if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) { throw new NoAccessException("User has no access to the sample " + sampleId); }/*from ww w . j a v a2s .co m*/ logger.debug("===============Finding a sample by id: " + System.currentTimeMillis()); Sample sample = null; CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .add(Property.forName("id").eq(new Long(sampleId))); crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN); crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN); crit.setFetchMode("keywordCollection", FetchMode.JOIN); crit.setFetchMode("characterizationCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.chemicalAssociationCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.nanomaterialEntityCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.nanomaterialEntityCollection.composingElementCollection", FetchMode.JOIN); crit.setFetchMode( "sampleComposition.nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.functionalizingEntityCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.functionalizingEntityCollection.functionCollection", FetchMode.JOIN); crit.setFetchMode("publicationCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); if (!result.isEmpty() || result.size() > 0) { sample = (Sample) result.get(0); } return sample; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public int getNumberOfPublicSampleSources() throws Exception { CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/*from w w w .j av a 2 s. c o m*/ Set<Organization> publicOrgs = new HashSet<Organization>(); DetachedCriteria crit = DetachedCriteria.forClass(PointOfContact.class); crit.setFetchMode("organization", FetchMode.JOIN); List results = appService.query(crit); // get organizations associated with public point of contacts for (int i = 0; i < results.size(); i++) { PointOfContact poc = (PointOfContact) results.get(i); if (springSecurityAclService.checkObjectPublic(poc.getId(), SecureClassesEnum.POC.getClazz())) publicOrgs.add(poc.getOrganization()); } return publicOrgs.size(); }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public PointOfContact findPointOfContactById(String pocId) throws Exception { PointOfContact poc = null;//from w w w . j a v a2s . c om CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(PointOfContact.class) .add(Property.forName("id").eq(new Long(pocId))); crit.setFetchMode("organization", FetchMode.JOIN); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { poc = (PointOfContact) results.get(i); } return poc; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public List<PointOfContact> findPointOfContactsBySampleId(String sampleId) throws Exception { if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) { throw new NoAccessException("User has no access to the sample " + sampleId); }//from w w w . j a v a 2 s. co m CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .add(Property.forName("id").eq(new Long(sampleId))); crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN); crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); List<PointOfContact> pointOfContacts = new ArrayList<PointOfContact>(); for (int i = 0; i < results.size(); i++) { Sample sample = (Sample) results.get(i); PointOfContact primaryPOC = sample.getPrimaryPointOfContact(); pointOfContacts.add(primaryPOC); Collection<PointOfContact> otherPOCs = sample.getOtherPointOfContactCollection(); pointOfContacts.addAll(otherPOCs); } return pointOfContacts; }
From source file:gov.nih.nci.cananolab.service.sample.impl.SampleServiceLocalImpl.java
License:BSD License
private Sample findFullyLoadedSampleByName(String sampleName) throws Exception { CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/* www . j a v a2 s. co m*/ // load composition and characterization separate because of Hibernate // join limitation DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .add(Property.forName("name").eq(sampleName).ignoreCase()); Sample sample = null; // load composition and characterization separate because of // Hibernate join limitation crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN); crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN); crit.setFetchMode("keywordCollection", FetchMode.JOIN); crit.setFetchMode("publicationCollection", FetchMode.JOIN); crit.setFetchMode("publicationCollection.authorCollection", FetchMode.JOIN); crit.setFetchMode("publicationCollection.keywordCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); if (!result.isEmpty()) { sample = (Sample) result.get(0); } if (sample == null) { throw new NotExistException("Sample doesn't exist in the database"); } // fully load composition SampleComposition comp = this.loadComposition(sample.getId().toString()); sample.setSampleComposition(comp); // fully load characterizations List<Characterization> chars = this.loadCharacterizations(sample.getId().toString()); if (chars != null && !chars.isEmpty()) { sample.setCharacterizationCollection(new HashSet<Characterization>(chars)); } else { sample.setCharacterizationCollection(null); } return sample; }
From source file:gov.nih.nci.cananolab.service.sample.impl.SampleServiceLocalImpl.java
License:BSD License
public List<PointOfContactBean> findPointOfContactsBySampleId(String sampleId) throws PointOfContactException { try {//from www . j a v a 2 s. c o m CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .add(Property.forName("id").eq(new Long(sampleId))); crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN); crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); List<PointOfContactBean> pointOfContactCollection = new ArrayList<PointOfContactBean>(); for (int i = 0; i < results.size(); i++) { Sample particle = (Sample) results.get(i); PointOfContact primaryPOC = particle.getPrimaryPointOfContact(); Collection<PointOfContact> otherPOCs = particle.getOtherPointOfContactCollection(); pointOfContactCollection.add(new PointOfContactBean(primaryPOC)); for (PointOfContact poc : otherPOCs) { pointOfContactCollection.add(new PointOfContactBean(poc)); } } return pointOfContactCollection; } catch (Exception e) { String err = "Problem finding all PointOfContact collections with the given sample ID."; logger.error(err, e); throw new PointOfContactException(err, e); } }
From source file:gov.nih.nci.eagle.service.handlers.EpidemiologicalQueryHandler.java
License:BSD License
public List getResults(QueryDTO queryDTO) { EPIQueryDTO epiQueryDTO = (EPIQueryDTO) queryDTO; Session session = sessionFactory.getCurrentSession(); Criteria targetCrit = session.createCriteria(StudyParticipant.class); targetCrit.createCriteria("epidemiologicalFinding", "finding").setFetchMode("relativeCollection", FetchMode.JOIN); targetCrit.createAlias("finding.tobaccoConsumptionCollection", "tc", CriteriaSpecification.LEFT_JOIN); targetCrit.createAlias("finding.behavioralAssessment", "ba", CriteriaSpecification.LEFT_JOIN); targetCrit.createAlias("finding.lifestyle", "ls", CriteriaSpecification.LEFT_JOIN); targetCrit.createAlias("finding.environmentalFactorCollection", "factors", CriteriaSpecification.LEFT_JOIN); /* 1. Handle PatientCharacteristics Criterion */ PatientCharacteristicsCriterion patCharacterCrit = epiQueryDTO.getPatientCharacteristicsCriterion(); if (patCharacterCrit != null) populatePatientCharacteristicsCriterion(patCharacterCrit, targetCrit); /* 2. Handle Tobacco Dependency Criterion */ BehavioralCriterion behaviorCrit = epiQueryDTO.getBehavioralCriterion(); if (behaviorCrit != null) populateBehaviorCriterion(behaviorCrit, targetCrit); /* Handle Tobacco Consumption Criterion */ TobaccoConsumptionCriterion tobaccoCrit = epiQueryDTO.getTobaccoConsumptionCriterion(); if (tobaccoCrit != null) populateTobaccoConsumptionCrit(tobaccoCrit, targetCrit); FamilyHistoryCriterion familyHistcrit = epiQueryDTO.getFamilyHistoryCriterion(); if (familyHistcrit != null) populateFamilyHistoryCrit(familyHistcrit, targetCrit); EnvironmentalTobaccoSmokeCriterion envCrit = epiQueryDTO.getEnvironmentalTobaccoSmokeCriterion(); if (envCrit != null && envCrit.getSmokingExposureCollection() != null) { Collection<SmokingExposure> exposure = envCrit.getSmokingExposureCollection(); List<String> exposures = new ArrayList<String>(); for (SmokingExposure ex : exposure) { exposures.add(ex.toString()); }/* ww w .j av a2 s. co m*/ targetCrit.add(Restrictions.in("factors.exposureType", exposures)); } // Handle patient ID criteria if (epiQueryDTO.getPatientIds() != null && epiQueryDTO.getPatientIds().size() > 0) { targetCrit.add(Restrictions.in("studySubjectIdentifier", epiQueryDTO.getPatientIds())); } targetCrit.addOrder(Order.asc("id")); List<StudyParticipant> l = targetCrit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); return l; }
From source file:gr.abiss.calipso.hibernate.HibernateDao.java
License:Open Source License
@Override public List<AbstractItem> findAllItems() { // return getHibernateTemplate().loadAll(AbstractItem.class); return (List<AbstractItem>) getHibernateTemplate().execute(new HibernateCallback() { @Override/*from w w w .ja va 2 s . c o m*/ public Object doInHibernate(Session session) { Criteria criteria = session.createCriteria(AbstractItem.class); criteria.setFetchMode("space", FetchMode.JOIN); return criteria.list(); } }); }
From source file:grails.orm.HibernateCriteriaBuilder.java
License:Apache License
/** * Use a join query//from w ww.j a v a 2 s.c o m * * @param associationPath The path of the association */ public void join(String associationPath) { criteria.setFetchMode(calculatePropertyName(associationPath), FetchMode.JOIN); }