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.AdvancedSampleServiceHelper.java
License:BSD License
/** * Find sample details as an AdvancedSampleBean for the given sample name * and advanced search parameters/*from w w w .j av a 2s.c o m*/ * * @param sampleId * @param searchBean * @return * @throws Exception */ public AdvancedSampleBean findAdvancedSampleByAdvancedSearch(String sampleId, AdvancedSampleSearchBean searchBean) throws Exception { if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) { throw new NoAccessException(); } // load sample first with point of contact info and function info and // datum info DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .add(Restrictions.eq("id", 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("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("characterizationCollection", FetchMode.JOIN); crit.setFetchMode("characterizationCollection.findingCollection", FetchMode.JOIN); crit.setFetchMode("characterizationCollection.findingCollection.datumCollection", FetchMode.JOIN); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); Sample sample = null; if (!result.isEmpty()) { sample = (Sample) result.get(0); } List<PointOfContact> pocs = findPointOfContactsBy(sample, searchBean); List<Function> functions = findFunctionsBy(sampleId, searchBean); List<NanomaterialEntity> nanoEntities = findNanomaterialEntitiesBy(sampleId, searchBean); List<FunctionalizingEntity> funcEntities = findFunctionalizingEntitiesBy(sampleId, searchBean); List<Characterization> charas = findCharacterizationsBy(sampleId, searchBean); List<Datum> data = findDataBy(sample, searchBean); AdvancedSampleBean advancedSampleBean = new AdvancedSampleBean(sampleId, pocs, functions, nanoEntities, funcEntities, charas, data, searchBean, sample); return advancedSampleBean; }
From source file:gov.nih.nci.cananolab.service.sample.helper.AdvancedSampleServiceHelper.java
License:BSD License
private List<FunctionalizingEntity> findFunctionalizingEntitiesBy(String sampleId, AdvancedSampleSearchBean searchBean) throws Exception { List<FunctionalizingEntity> entities = new ArrayList<FunctionalizingEntity>(); if (!searchBean.getHasAgentMaterial()) { return entities; }/* www. j av a 2 s .co m*/ Long id = new Long(sampleId); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(FunctionalizingEntity.class); Junction junction = getFunctionalizingEntityJunction(searchBean, crit); if (junction != null) { crit.createAlias("sampleComposition", "comp", CriteriaSpecification.LEFT_JOIN); crit.createAlias("comp.sample", "sample", CriteriaSpecification.LEFT_JOIN); crit.add(Restrictions.eq("sample.id", id)); crit.add(junction); crit.setFetchMode("functionCollection", FetchMode.JOIN); crit.setFetchMode("functionCollection.targetCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { FunctionalizingEntity entity = (FunctionalizingEntity) results.get(i); entities.add(entity); } } else if (searchBean.getFuncEntityCount() > 1) { // Hibernate Criteria API doesn't support union, union in java for (CompositionQueryBean query : searchBean.getCompositionQueries()) { if (query.getCompositionType().equals("functionalizing entity")) { crit = DetachedCriteria.forClass(FunctionalizingEntity.class); crit.createAlias("sampleComposition", "comp", CriteriaSpecification.LEFT_JOIN); crit.createAlias("comp.sample", "sample", CriteriaSpecification.LEFT_JOIN); crit.add(Restrictions.eq("sample.id", id)); DetachedCriteria subCrit = getFunctionalizingEntitySubquery(query, "", "id"); crit.add(Subqueries.exists(subCrit)); crit.setFetchMode("functionCollection", FetchMode.JOIN); crit.setFetchMode("functionCollection.targetCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { FunctionalizingEntity entity = (FunctionalizingEntity) results.get(i); if (!entities.contains(entity)) { entities.add(entity); } } } } } return entities; }
From source file:gov.nih.nci.cananolab.service.sample.helper.AdvancedSampleServiceHelper.java
License:BSD License
private List<Function> findFunctionsBy(String sampleId, AdvancedSampleSearchBean searchBean) throws Exception { List<Function> functions = new ArrayList<Function>(); if (!searchBean.getHasFunction()) { return functions; }/*from w ww. j a va 2 s .c o m*/ Long id = new Long(sampleId); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Function.class); Junction junction = getFunctionJunction(searchBean, crit); if (junction != null) { crit.createAlias("composingElement", "ce", CriteriaSpecification.LEFT_JOIN); crit.createAlias("ce.nanomaterialEntity", "nanoEntity", CriteriaSpecification.LEFT_JOIN); crit.createAlias("nanoEntity.sampleComposition", "comp", CriteriaSpecification.LEFT_JOIN); crit.createAlias("comp.sample", "sample", CriteriaSpecification.LEFT_JOIN); crit.createAlias("functionalizingEntity", "funcEntity", CriteriaSpecification.LEFT_JOIN); crit.createAlias("funcEntity.sampleComposition", "comp2", CriteriaSpecification.LEFT_JOIN); crit.createAlias("comp2.sample", "sample2", CriteriaSpecification.LEFT_JOIN); crit.add(Restrictions.or(Restrictions.eq("sample.id", id), Restrictions.eq("sample2.id", id))); crit.add(junction); crit.setFetchMode("targetCollection", FetchMode.JOIN); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Function function = (Function) results.get(i); functions.add(function); } } else if (searchBean.getFuncCount() > 1) { // Hibernate Criteria API doesn't support union, union in java for (CompositionQueryBean query : searchBean.getCompositionQueries()) { if (query.getCompositionType().equals("function")) { crit = DetachedCriteria.forClass(Function.class); crit.createAlias("composingElement", "ce", CriteriaSpecification.LEFT_JOIN); crit.createAlias("ce.nanomaterialEntity", "nanoEntity", CriteriaSpecification.LEFT_JOIN); crit.createAlias("nanoEntity.sampleComposition", "comp", CriteriaSpecification.LEFT_JOIN); crit.createAlias("comp.sample", "sample", CriteriaSpecification.LEFT_JOIN); crit.createAlias("functionalizingEntity", "funcEntity", CriteriaSpecification.LEFT_JOIN); crit.createAlias("funcEntity.sampleComposition", "comp2", CriteriaSpecification.LEFT_JOIN); crit.createAlias("comp2.sample", "sample2", CriteriaSpecification.LEFT_JOIN); crit.add(Restrictions.or(Restrictions.eq("sample.id", id), Restrictions.eq("sample2.id", id))); DetachedCriteria subCrit = getFunctionSubquery(query, "", "", "id"); crit.add(Subqueries.exists(subCrit)); crit.setFetchMode("targetCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Function function = (Function) results.get(i); if (!functions.contains(function)) { functions.add(function); } } } } } return functions; }
From source file:gov.nih.nci.cananolab.service.sample.helper.AdvancedSampleServiceHelper.java
License:BSD License
private List<NanomaterialEntity> findNanomaterialEntitiesBy(String sampleId, AdvancedSampleSearchBean searchBean) throws Exception { List<NanomaterialEntity> entities = new ArrayList<NanomaterialEntity>(); Long id = new Long(sampleId); if (!searchBean.getHasNanomaterial()) { return entities; }//w ww.j a v a 2 s .c o m DetachedCriteria crit = DetachedCriteria.forClass(NanomaterialEntity.class); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); Junction junction = getNanomaterialEntityJunction(searchBean, crit); if (junction != null) { // join nanomaterialEntity if (searchBean.getHasNanomaterial() && !searchBean.getHasFunction()) { if (searchBean.getHasChemicalName()) { crit.createAlias("composingElementCollection", "compElement", CriteriaSpecification.LEFT_JOIN); } } crit.createAlias("sampleComposition", "comp"); crit.createAlias("comp.sample", "sample"); crit.add(Restrictions.eq("sample.id", id)); crit.add(junction); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection.targetCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { NanomaterialEntity entity = (NanomaterialEntity) results.get(i); entities.add(entity); } } else if (searchBean.getNanoEntityCount() > 1) { // Hibernate Criteria API doesn't support union, union in java for (CompositionQueryBean query : searchBean.getCompositionQueries()) { if (query.getCompositionType().equals("nanomaterial entity")) { crit = DetachedCriteria.forClass(NanomaterialEntity.class); crit.createAlias("sampleComposition", "comp", CriteriaSpecification.LEFT_JOIN); crit.createAlias("comp.sample", "sample", CriteriaSpecification.LEFT_JOIN); if (!StringUtils.isEmpty(query.getChemicalName())) { crit.createAlias("composingElementCollection", "compElement"); } crit.add(Restrictions.eq("sample.id", id)); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection.targetCollection", FetchMode.JOIN); DetachedCriteria subCrit = getNanomaterialEntitySubquery(query, "", "id"); crit.add(Subqueries.exists(subCrit)); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { NanomaterialEntity entity = (NanomaterialEntity) results.get(i); if (!entities.contains(entity)) { entities.add(entity); } } } } } return entities; }
From source file:gov.nih.nci.cananolab.service.sample.helper.AdvancedSampleServiceHelper.java
License:BSD License
private List<PointOfContact> findPointOfContactsBy(Sample sample, AdvancedSampleSearchBean searchBean) throws Exception { if (!searchBean.getHasPOC()) { return null; }//from w w w . j ava2s .com // get POCs associated with the sample List<PointOfContact> samplePOCs = new ArrayList<PointOfContact>(); samplePOCs.add(sample.getPrimaryPointOfContact()); samplePOCs.addAll(sample.getOtherPointOfContactCollection()); List<PointOfContact> pocs = new ArrayList<PointOfContact>(samplePOCs); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); if (searchBean.getCharacterizationQueries().size() == 1 || searchBean.getSampleLogicalOperator().equals("or")) { DetachedCriteria crit = DetachedCriteria.forClass(PointOfContact.class); crit.createAlias("organization", "organization"); crit.add(getPointOfContactDisjunction(searchBean, "", "")); crit.setFetchMode("organization", FetchMode.JOIN); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { PointOfContact poc = (PointOfContact) results.get(i); // check if in sample POCs if (!samplePOCs.contains(poc)) { pocs.remove(poc); } } } else { for (SampleQueryBean query : searchBean.getSampleQueries()) { if (query.getNameType().equals("point of contact name")) { DetachedCriteria crit = DetachedCriteria.forClass(PointOfContact.class); crit.createAlias("organization", "organization"); DetachedCriteria subCrit = getPointOfContactSubquery(query, "", "", "id"); crit.add(Subqueries.exists(subCrit)); crit.setFetchMode("organization", FetchMode.JOIN); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { PointOfContact poc = (PointOfContact) results.get(i); // check if in sample POCs if (!samplePOCs.contains(poc)) { pocs.remove(poc); } } } } } return pocs; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CharacterizationServiceHelper.java
License:BSD License
public List<Finding> findFindingsByCharacterizationId(String charId) throws Exception { // if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(charId), SecureClassesEnum.CHAR.getClazz()) && // !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(charId), SecureClassesEnum.CHAR.getClazz())) { // new NoAccessException("User has no access to the characterization " + charId); // }/* www.j a v a 2s . co m*/ List<Finding> findings = new ArrayList<Finding>(); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class) .add(Property.forName("id").eq(new Long(charId))); crit.setFetchMode("findingCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection.conditionCollection", FetchMode.JOIN); List result = appService.query(crit); if (!result.isEmpty()) { Characterization achar = (Characterization) result.get(0); findings.addAll(achar.getFindingCollection()); } return findings; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CharacterizationServiceHelper.java
License:BSD License
public List<ExperimentConfig> findExperimentConfigsByCharacterizationId(String charId) throws Exception { if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(charId), SecureClassesEnum.CHAR.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(charId), SecureClassesEnum.CHAR.getClazz())) { new NoAccessException("User has no access to the characterization " + charId); }//from w ww. ja v a 2 s . c o m List<ExperimentConfig> configs = new ArrayList<ExperimentConfig>(); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class) .add(Property.forName("id").eq(new Long(charId))); crit.setFetchMode("experimentConfigCollection", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.technique", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.instrumentCollection", FetchMode.JOIN); List result = appService.query(crit); if (!result.isEmpty()) { Characterization achar = (Characterization) result.get(0); configs.addAll(achar.getExperimentConfigCollection()); } return configs; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CharacterizationServiceHelper.java
License:BSD License
public ExperimentConfig findExperimentConfigById(String sampleId, String id) throws Exception { if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) { new NoAccessException("User has no access to the experiment config " + id); }/* ww w . j ava 2 s .c o m*/ ExperimentConfig config = null; CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(ExperimentConfig.class) .add(Property.forName("id").eq(new Long(id))); crit.setFetchMode("technique", FetchMode.JOIN); crit.setFetchMode("instrumentCollection", FetchMode.JOIN); List result = appService.query(crit); if (!result.isEmpty()) { config = (ExperimentConfig) result.get(0); } return config; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CharacterizationServiceHelper.java
License:BSD License
public List<Characterization> findCharacterizationsBySampleId(String sampleId) throws Exception { List<Characterization> chars = new ArrayList<Characterization>(); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/*from www . j av a 2 s . c o m*/ DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class); crit.createAlias("sample", "sample"); crit.add(Property.forName("sample.id").eq(new Long(sampleId))); // fully load characterization crit.setFetchMode("pointOfContact", FetchMode.JOIN); crit.setFetchMode("pointOfContact.organization", FetchMode.JOIN); crit.setFetchMode("protocol", FetchMode.JOIN); crit.setFetchMode("protocol.file", FetchMode.JOIN); crit.setFetchMode("protocol.file.keywordCollection", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.technique", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.instrumentCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection.conditionCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Characterization achar = (Characterization) results.get(i); if (springSecurityAclService.currentUserHasReadPermission(achar.getId(), SecureClassesEnum.CHAR.getClazz()) || springSecurityAclService.currentUserHasWritePermission(achar.getId(), SecureClassesEnum.CHAR.getClazz())) { checkAssociatedVisibility(achar); chars.add(achar); } else { logger.debug("User doesn't have access ot characterization with id " + achar.getId()); } } return chars; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CharacterizationServiceHelper.java
License:BSD License
public Characterization findCharacterizationById(String charId) throws Exception { if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(charId), SecureClassesEnum.CHAR.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(charId), SecureClassesEnum.CHAR.getClazz())) { new NoAccessException("User has no access to the characterization " + charId); }//from www . jav a2 s . co m Characterization achar = null; CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class) .add(Property.forName("id").eq(new Long(charId))); // fully load characterization crit.setFetchMode("pointOfContact", FetchMode.JOIN); crit.setFetchMode("pointOfContact.organization", FetchMode.JOIN); crit.setFetchMode("protocol", FetchMode.JOIN); crit.setFetchMode("protocol.file", FetchMode.JOIN); crit.setFetchMode("protocol.file.keywordCollection", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.technique", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.instrumentCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection.conditionCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); if (!result.isEmpty()) { achar = (Characterization) result.get(0); checkAssociatedVisibility(achar); } return achar; }