List of usage examples for org.hibernate.criterion DetachedCriteria setFetchMode
public DetachedCriteria setFetchMode(String associationPath, FetchMode mode)
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public PointOfContact findPrimaryPointOfContactBySampleId(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); }//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.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); PointOfContact poc = null; for (int i = 0; i < results.size(); i++) { Sample sample = (Sample) results.get(i); poc = sample.getPrimaryPointOfContact(); } return poc; }
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); }/*w w w .j a v a 2s . c om*/ 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 w w w .j a v a 2s . c o 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 ww w. ja v a 2 s .co 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 av a 2s .c o m 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 . ja va 2 s .com*/ 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();//from ww w . j ava 2 s. c o 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 w w w. 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:org.encuestame.persistence.dao.imp.AccountDaoImp.java
License:Apache License
public final List<UserAccount> retrieveListOwnerUsers(final Account account, final Integer maxResults, final Integer start) { final DetachedCriteria criteria = DetachedCriteria.forClass(UserAccount.class); criteria.add(Restrictions.eq("account", account)); criteria.setFetchMode("secUserPermissions", FetchMode.SELECT); criteria.addOrder(Order.asc("enjoyDate")); getHibernateTemplate().setCacheQueries(true); return (List<UserAccount>) getHibernateTemplate().findByCriteria(criteria, start, maxResults); }
From source file:org.eulerframework.web.core.base.dao.impl.hibernate5.BaseDao.java
License:Apache License
@Override public PageResponse<T> pageQuery(PageQueryRequest pageQueryRequest, List<Criterion> criterions, List<Order> orders, Projection projection, Map<String, FetchMode> fetchMode) { DetachedCriteria detachedCriteria = this.analyzeQueryRequest(pageQueryRequest); if (!CollectionUtils.isEmpty(criterions)) { for (Criterion c : criterions) { detachedCriteria.add(c);/*w w w.j av a2 s . c om*/ } } if (!CollectionUtils.isEmpty(orders)) { for (Order d : orders) { detachedCriteria.addOrder(d); } } if (!CollectionUtils.isEmpty(fetchMode)) { for (Map.Entry<String, FetchMode> entry : fetchMode.entrySet()) { String property = entry.getKey(); FetchMode propertyFetchMode = entry.getValue(); detachedCriteria.setFetchMode(property, propertyFetchMode); } } return this.pageQuery(detachedCriteria, pageQueryRequest.getPageIndex(), pageQueryRequest.getPageSize(), projection); }