List of usage examples for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY
ResultTransformer DISTINCT_ROOT_ENTITY
To view the source code for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY.
Click Source Link
From source file:es.sm2.openppm.core.dao.ProjectCostsDAO.java
License:Open Source License
/** * Return Project costs/*from w ww . jav a 2s . c om*/ * @param proj * @return */ @SuppressWarnings("unchecked") public List<Projectcosts> findByProject(Project proj) { List<Projectcosts> costs = null; if (proj != null) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.setFetchMode("directcostses", FetchMode.JOIN); crit.setFetchMode("directcostses.budgetaccounts", FetchMode.JOIN); crit.setFetchMode("expenseses", FetchMode.JOIN); crit.setFetchMode("expenseses.budgetaccounts", FetchMode.JOIN); crit.add(Restrictions.eq("project", proj)); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); costs = crit.list(); } return costs; }
From source file:es.sm2.openppm.core.dao.ProjectCostsDAO.java
License:Open Source License
/** * Return Project direct costs/*from w ww . j av a2 s . com*/ * @param proj * @return */ @SuppressWarnings("unchecked") public List<Projectcosts> findDirectCostsByProject(Project proj) { List<Projectcosts> costs = null; if (proj != null) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.setFetchMode("directcostses", FetchMode.JOIN); crit.setFetchMode("directcostses.budgetaccounts", FetchMode.JOIN); crit.add(Restrictions.eq("project", proj)); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); costs = crit.list(); } return costs; }
From source file:es.sm2.openppm.core.dao.ProjectDAO.java
License:Open Source License
/** * /*from ww w. j a v a 2 s .c o m*/ * @param employee * @return */ @SuppressWarnings("unchecked") public List<Project> findByEmployee(Employee employee, List<String> joins) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.createCriteria(Project.PROJECTACTIVITIES).createCriteria(Projectactivity.TEAMMEMBERS) .add(Restrictions.eq(Teammember.EMPLOYEE, employee)); crit.addOrder(Order.asc(Project.PROJECTNAME)); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return crit.list(); }
From source file:es.sm2.openppm.core.dao.ProjectDAO.java
License:Open Source License
/** * /*from ww w.j a v a2 s . com*/ * @param employee * @param initDate * @param endDate * @return */ @SuppressWarnings("unchecked") public List<Project> findByEmployee(Employee employee, Date initDate, Date endDate) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).createCriteria(Project.PROJECTACTIVITIES) .createCriteria(Projectactivity.TIMESHEETS).add(Restrictions.eq(Timesheet.EMPLOYEE, employee)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.ge(Timesheet.INITDATE, initDate)) .add(Restrictions.le(Timesheet.ENDDATE, endDate)); crit.addOrder(Order.asc(Project.PROJECTNAME)); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return crit.list(); }
From source file:es.sm2.openppm.core.dao.SellerDAO.java
License:Open Source License
/** * Sellers by projects/*ww w . j a v a2s . c o m*/ * * @param projects * @return */ public List<Seller> findByProcurement(Project... projects) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.createCriteria(Seller.ACTIVITYSELLERS).createCriteria(Activityseller.PROJECTACTIVITY) .add(Restrictions.in(Projectactivity.PROJECT, projects)); crit.addOrder(Order.asc(Seller.NAME)); return crit.list(); }
From source file:gov.nih.nci.caarray.dao.AbstractCaArrayDaoImpl.java
License:BSD License
private <T extends PersistentObject> Criteria getCriteriaForExampleQuery(ExampleSearchCriteria<T> criteria) { final T entityToMatch = criteria.getExample(); CaArrayUtils.blankStringPropsToNull(entityToMatch); final Criteria c = getCurrentSession().createCriteria(getPersistentClass(entityToMatch.getClass())) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); c.add(createExample(entityToMatch, criteria.getMatchMode(), criteria.isExcludeNulls(), criteria.isExcludeZeroes(), criteria.getExcludeProperties())); new SearchCriteriaHelper<T>(this, c, criteria).addCriteriaForAssociations(); return c;/*from w w w . j a v a 2 s.c om*/ }
From source file:gov.nih.nci.cananolab.service.admin.impl.OwnershipTransferServiceImpl.java
License:BSD License
private Sample findFullyLoadedSampleById(String sampleId) throws Exception { CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/*from w w w. j ava2 s. co m*/ // load composition and characterization separate because of Hibernate // join limitation DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .add(Property.forName("id").eq(new Long(sampleId))); 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.admin.impl.OwnershipTransferServiceImpl.java
License:BSD License
private SampleComposition loadComposition(String sampleId) throws Exception { SampleComposition composition = null; CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();//from w w w .j a va 2 s . co m DetachedCriteria crit = DetachedCriteria.forClass(SampleComposition.class); crit.createAlias("sample", "sample"); crit.add(Property.forName("sample.id").eq(new Long(sampleId))); crit.setFetchMode("nanomaterialEntityCollection", FetchMode.JOIN); crit.setFetchMode("nanomaterialEntityCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("nanomaterialEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("nanomaterialEntityCollection.composingElementCollection", FetchMode.JOIN); crit.setFetchMode("nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection", FetchMode.JOIN); crit.setFetchMode( "nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection.targetCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.functionCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.functionCollection.targetCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.activationMethod", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection.associatedElementA", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection.associatedElementB", FetchMode.JOIN); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); if (!result.isEmpty()) { composition = (SampleComposition) result.get(0); } return composition; }
From source file:gov.nih.nci.cananolab.service.admin.impl.OwnershipTransferServiceImpl.java
License:BSD License
private List<Characterization> loadCharacterizations(String sampleId) throws Exception { List<Characterization> chars = new ArrayList<Characterization>(); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/* ww w. jav a 2 s. co 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); chars.add(achar); } return chars; }
From source file:gov.nih.nci.cananolab.service.protocol.helper.ProtocolServiceHelper.java
License:BSD License
public List<Protocol> findProtocolsBy(String protocolType, String protocolName, String protocolAbbreviation, String fileTitle) throws Exception { List<Protocol> protocols = new ArrayList<Protocol>(); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/*from w w w. j a v a2s. c o m*/ DetachedCriteria crit = DetachedCriteria.forClass(Protocol.class); crit.createAlias("file", "file", CriteriaSpecification.LEFT_JOIN); crit.setFetchMode("file.keywordCollection", FetchMode.JOIN); if (!StringUtils.isEmpty(protocolType)) { // case insensitive crit.add(Restrictions.ilike("type", protocolType, MatchMode.EXACT)); } if (!StringUtils.isEmpty(protocolName)) { TextMatchMode protocolNameMatchMode = new TextMatchMode(protocolName); crit.add(Restrictions.ilike("name", protocolNameMatchMode.getUpdatedText(), protocolNameMatchMode.getMatchMode())); } if (!StringUtils.isEmpty(protocolAbbreviation)) { TextMatchMode protocolAbbreviationMatchMode = new TextMatchMode(protocolAbbreviation); crit.add(Restrictions.ilike("abbreviation", protocolAbbreviationMatchMode.getUpdatedText(), protocolAbbreviationMatchMode.getMatchMode())); } if (!StringUtils.isEmpty(fileTitle)) { TextMatchMode titleMatchMode = new TextMatchMode(fileTitle); crit.add(Restrictions.ilike("file.title", titleMatchMode.getUpdatedText(), titleMatchMode.getMatchMode())); } crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Protocol protocol = (Protocol) results.get(i); if (springSecurityAclService.currentUserHasReadPermission(protocol.getId(), SecureClassesEnum.PROTOCOL.getClazz()) || springSecurityAclService.currentUserHasWritePermission(protocol.getId(), SecureClassesEnum.PROTOCOL.getClazz())) { protocols.add(protocol); } else { logger.debug("User doesn't have access ot protocol with id " + protocol.getId()); } } return protocols; }