List of usage examples for org.hibernate.criterion Projections projectionList
public static ProjectionList projectionList()
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java
License:CeCILL license
@Override public Long countConceptsAlignedToIntThes(String idThesaurus) throws BusinessException { DetachedCriteria alignmentCriteria = DetachedCriteria.forClass(Alignment.class, "al") .add(Restrictions.isNotNull("al.internalTargetThesaurus")).setProjection( Projections.projectionList().add(Projections.property("al.sourceConcept.identifier"))); DetachedCriteria conceptCriteria = DetachedCriteria.forClass(ThesaurusConcept.class, "stc") .add(Restrictions.eq("stc.thesaurus.identifier", idThesaurus)) .setProjection(Projections.projectionList().add(Projections.property("stc.identifier"))); Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc") .add(Restrictions.and(Subqueries.propertyIn("tc.identifier", alignmentCriteria), Subqueries.propertyIn("tc.identifier", conceptCriteria))) .setProjection(Projections.rowCount()); return (Long) criteria.list().get(0); }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java
License:CeCILL license
@Override public Long countConceptsAlignedToExtThes(String idThesaurus) throws BusinessException { DetachedCriteria alignmentCriteria = DetachedCriteria.forClass(Alignment.class, "al") .add(Restrictions.isNotNull("al.externalTargetThesaurus")).setProjection( Projections.projectionList().add(Projections.property("al.sourceConcept.identifier"))); DetachedCriteria conceptCriteria = DetachedCriteria.forClass(ThesaurusConcept.class, "stc") .add(Restrictions.eq("stc.thesaurus.identifier", idThesaurus)) .setProjection(Projections.projectionList().add(Projections.property("stc.identifier"))); Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc") .add(Restrictions.and(Subqueries.propertyIn("tc.identifier", alignmentCriteria), Subqueries.propertyIn("tc.identifier", conceptCriteria))) .setProjection(Projections.rowCount()); return (Long) criteria.list().get(0); }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java
License:CeCILL license
@Override public Long countConceptsAlignedToMyThes(String idThesaurus) throws BusinessException { DetachedCriteria alignmentCriteria = DetachedCriteria.forClass(Alignment.class, "al") .add(Restrictions.eq("al.internalTargetThesaurus.identifier", idThesaurus)).setProjection( Projections.projectionList().add(Projections.property("al.sourceConcept.identifier"))); Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc") .add(Subqueries.propertyIn("tc.identifier", alignmentCriteria)) .setProjection(Projections.rowCount()); return (Long) criteria.list().get(0); }
From source file:gov.nih.nci.cananolab.service.protocol.helper.ProtocolServiceHelper.java
License:BSD License
public List<String> findProtocolIdsByOwner(String currentOwner) throws Exception { List<String> protocolIds = new ArrayList<String>(); DetachedCriteria crit = DetachedCriteria.forClass(Protocol.class) .setProjection(Projections.projectionList().add(Projections.property("id"))); Criterion crit1 = Restrictions.eq("createdBy", currentOwner); // in case of copy createdBy is like lijowskim:COPY Criterion crit2 = Restrictions.like("createdBy", currentOwner + ":", MatchMode.START); crit.add(Expression.or(crit1, crit2)); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/*from www.java 2 s . c om*/ List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { String protocolId = results.get(i).toString(); if (springSecurityAclService.currentUserHasReadPermission(Long.valueOf(protocolId), SecureClassesEnum.PROTOCOL.getClazz()) || springSecurityAclService.currentUserHasWritePermission(Long.valueOf(protocolId), SecureClassesEnum.PROTOCOL.getClazz())) { protocolIds.add(protocolId); } else { logger.debug("User doesn't have access to protocol of ID: " + protocolId); } } return protocolIds; }
From source file:gov.nih.nci.cananolab.service.sample.helper.AdvancedSampleServiceHelper.java
License:BSD License
/** * Find sample names based on advanced search parameters * //w w w . j a va2 s . com * @param searchBean * @return * @throws Exception */ public Map<String, String> findSampleIdNamesByAdvancedSearch(AdvancedSampleSearchBean searchBean) throws Exception { List<String> sampleIds = new ArrayList<String>(); Map<String, String> sampleIdNameMap = new HashMap<String, String>(); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); ProjectionList projList = Projections.projectionList(); projList.add(Property.forName("id")); projList.add(Property.forName("name")); // AND or all empty if (searchBean.getLogicalOperator().equals("and") || searchBean.getSampleQueries().isEmpty() && searchBean.getCharacterizationQueries().isEmpty() && searchBean.getCompositionQueries().isEmpty()) { DetachedCriteria crit = DetachedCriteria.forClass(Sample.class, "rootCrit") .setProjection(Projections.distinct(projList)); //Projections.distinct(Property.forName("id"))); setSampleCriteria(searchBean, crit); setCompositionCriteria(searchBean, crit); setCharacterizationCriteria(searchBean, crit); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Object[] row = (Object[]) results.get(i); String id = row[0].toString(); String name = row[1].toString(); logger.debug("id is: " + id); logger.debug("name is: " + name); String sampleId = id; sampleIds.add(sampleId); sampleIdNameMap.put(id, name); } } // OR union the results else { Set<String> sampleIdSet = new HashSet<String>(); // sample if (!searchBean.getSampleQueries().isEmpty()) { // ProjectionList projList = Projections.projectionList(); // projList.add(Property.forName("id")); // projList.add(Property.forName("name")); DetachedCriteria crit = DetachedCriteria.forClass(Sample.class, "rootCrit") .setProjection(Projections.distinct(projList)); //Projections.distinct(Property.forName("id"))); setSampleCriteria(searchBean, crit); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Object[] row = (Object[]) results.get(i); String id = row[0].toString(); String name = row[1].toString(); logger.debug("id is: " + id); logger.debug("name is: " + name); String sampleId = id; sampleIds.add(sampleId); sampleIdNameMap.put(id, name); } } // // composition if (!searchBean.getCompositionQueries().isEmpty()) { if (searchBean.getCompositionLogicalOperator().equals("and")) { for (CompositionQueryBean query : searchBean.getCompositionQueries()) { List<String> subSampleIds = new ArrayList<String>(); DetachedCriteria crit = DetachedCriteria.forClass(Sample.class, "rootCrit") .setProjection(Projections.distinct(projList)); //Projections.distinct(Property.forName("id"))); setSampleCriteria(searchBean, crit); setCharacterizationCriteria(searchBean, crit); setCompositionCriteriaBase(searchBean, crit); if (query.getCompositionType().equals("function")) { DetachedCriteria subCrit = getFunctionSubquery(query, "inherentFunction.", "function.", "id"); crit.add(Subqueries.exists(subCrit)); } else if (query.getCompositionType().equals("nanomaterial entity")) { DetachedCriteria subCrit = getNanomaterialEntitySubquery(query, "nanoEntity.", "id"); crit.add(Subqueries.exists(subCrit)); } else if (query.getCompositionType().equals("functionalizing entity")) { DetachedCriteria subCrit = getFunctionalizingEntitySubquery(query, "funcEntity.", "id"); crit.add(Subqueries.exists(subCrit)); } List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Object[] row = (Object[]) results.get(i); String id = row[0].toString(); String name = row[1].toString(); logger.debug("id is: " + id); logger.debug("name is: " + name); String sampleId = id; //String sampleId = obj.toString(); subSampleIds.add(sampleId); sampleIdNameMap.put(id, name); } if (sampleIds.size() > 0) sampleIds.retainAll(subSampleIds); else sampleIds.addAll(subSampleIds); } } else { DetachedCriteria crit = DetachedCriteria.forClass(Sample.class, "rootCrit") .setProjection(Projections.distinct(projList)); //Projections.distinct(Property.forName("id"))); setCompositionCriteria(searchBean, crit); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Object[] row = (Object[]) results.get(i); String id = row[0].toString(); String name = row[1].toString(); logger.debug("id is: " + id); logger.debug("name is: " + name); String sampleId = id; //String sampleId = obj.toString(); sampleIds.add(sampleId); sampleIdNameMap.put(id, name); } } } if (!searchBean.getCharacterizationQueries().isEmpty()) { // characterization DetachedCriteria crit = DetachedCriteria.forClass(Sample.class, "rootCrit") .setProjection(Projections.distinct(projList)); //Projections.distinct(Property.forName("id"))); setCharacterizationCriteria(searchBean, crit); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Object[] row = (Object[]) results.get(i); String id = row[0].toString(); String name = row[1].toString(); logger.debug("id is: " + id); logger.debug("name is: " + name); String sampleId = id; //String sampleId = obj.toString(); sampleIds.add(sampleId); sampleIdNameMap.put(id, name); } } } Iterator<String> ite = sampleIdNameMap.keySet().iterator(); while (ite.hasNext()) { Long sampleId = Long.valueOf(ite.next()); if (!springSecurityAclService.currentUserHasReadPermission(sampleId, SecureClassesEnum.SAMPLE.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(sampleId, SecureClassesEnum.SAMPLE.getClazz())) { logger.debug("User doesn't have access to sample with id " + sampleId); ite.remove(); } } //filter out redundant ones and non-accessible ones // List<String>filteredSampleIds=new ArrayList<String>(); // for (String sampleId: sampleIds) { // if (!filteredSampleIds.contains(sampleId) // && StringUtils.containsIgnoreCase(getAccessibleData(), // sampleId)) { // filteredSampleIds.add(sampleId); // } else { // ignore no access exception // logger.debug("User doesn't have access to sample with id " // + sampleId); // } // } return sampleIdNameMap; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public List<String> findSampleIdsBy(String sampleName, String samplePointOfContact, String[] nanomaterialEntityClassNames, String[] otherNanomaterialEntityTypes, String[] functionalizingEntityClassNames, String[] otherFunctionalizingEntityTypes, String[] functionClassNames, String[] otherFunctionTypes, String[] characterizationClassNames, String[] otherCharacterizationTypes, String[] wordList) throws Exception { List<String> sampleIds = new ArrayList<String>(); //logger.error("Processing: " + sampleName); // can't query for the entire Sample object due to // limitations in pagination in SDK // added createdDate and sample name in the results so data can be // sorted by date and name DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .setProjection(Projections.projectionList().add(Projections.property("id")) .add(Projections.property("name")).add(Projections.property("createdDate"))); if (!StringUtils.isEmpty(sampleName)) { TextMatchMode nameMatchMode = new TextMatchMode(sampleName); crit.add(Restrictions.ilike("name", nameMatchMode.getUpdatedText(), nameMatchMode.getMatchMode())); }//from w ww .ja v a 2s. c o m if (!StringUtils.isEmpty(samplePointOfContact)) { TextMatchMode pocMatchMode = new TextMatchMode(samplePointOfContact); Disjunction disjunction = Restrictions.disjunction(); crit.createAlias("primaryPointOfContact", "pointOfContact"); crit.createAlias("pointOfContact.organization", "organization"); crit.createAlias("otherPointOfContactCollection", "otherPoc", CriteriaSpecification.LEFT_JOIN); crit.createAlias("otherPoc.organization", "otherOrg", CriteriaSpecification.LEFT_JOIN); String[] critStrs = { "pointOfContact.lastName", "pointOfContact.firstName", "pointOfContact.role", "organization.name", "otherPoc.lastName", "otherPoc.firstName", "otherOrg.name" }; for (String critStr : critStrs) { Criterion pocCrit = Restrictions.ilike(critStr, pocMatchMode.getUpdatedText(), pocMatchMode.getMatchMode()); disjunction.add(pocCrit); } crit.add(disjunction); } // join composition if (nanomaterialEntityClassNames != null && nanomaterialEntityClassNames.length > 0 || otherNanomaterialEntityTypes != null && otherNanomaterialEntityTypes.length > 0 || functionClassNames != null && functionClassNames.length > 0 || otherFunctionTypes != null && otherFunctionTypes.length > 0 || functionalizingEntityClassNames != null && functionalizingEntityClassNames.length > 0 || otherFunctionalizingEntityTypes != null && otherFunctionalizingEntityTypes.length > 0) { crit.createAlias("sampleComposition", "comp", CriteriaSpecification.LEFT_JOIN); } // join nanomaterial entity if (nanomaterialEntityClassNames != null && nanomaterialEntityClassNames.length > 0 || otherNanomaterialEntityTypes != null && otherNanomaterialEntityTypes.length > 0 || functionClassNames != null && functionClassNames.length > 0 || otherFunctionTypes != null && otherFunctionTypes.length > 0) { crit.createAlias("comp.nanomaterialEntityCollection", "nanoEntity", CriteriaSpecification.LEFT_JOIN); } // join functionalizing entity if (functionalizingEntityClassNames != null && functionalizingEntityClassNames.length > 0 || otherFunctionalizingEntityTypes != null && otherFunctionalizingEntityTypes.length > 0 || functionClassNames != null && functionClassNames.length > 0 || otherFunctionTypes != null && otherFunctionTypes.length > 0) { crit.createAlias("comp.functionalizingEntityCollection", "funcEntity", CriteriaSpecification.LEFT_JOIN); } // nanomaterial entity if (nanomaterialEntityClassNames != null && nanomaterialEntityClassNames.length > 0 || otherNanomaterialEntityTypes != null && otherNanomaterialEntityTypes.length > 0 || functionClassNames != null && functionClassNames.length > 0 || otherFunctionTypes != null && otherFunctionTypes.length > 0) { Disjunction disjunction = Restrictions.disjunction(); if (nanomaterialEntityClassNames != null && nanomaterialEntityClassNames.length > 0) { Criterion nanoEntityCrit = Restrictions.in("nanoEntity.class", nanomaterialEntityClassNames); disjunction.add(nanoEntityCrit); } if (otherNanomaterialEntityTypes != null && otherNanomaterialEntityTypes.length > 0) { Criterion otherNanoCrit1 = Restrictions.eq("nanoEntity.class", "OtherNanomaterialEntity"); Criterion otherNanoCrit2 = Restrictions.in("nanoEntity.type", otherNanomaterialEntityTypes); Criterion otherNanoCrit = Restrictions.and(otherNanoCrit1, otherNanoCrit2); disjunction.add(otherNanoCrit); } crit.add(disjunction); } // functionalizing entity // need to turn class names into integers in order for the .class // clause to work if (functionalizingEntityClassNames != null && functionalizingEntityClassNames.length > 0 || otherFunctionalizingEntityTypes != null && otherFunctionalizingEntityTypes.length > 0 || functionClassNames != null && functionClassNames.length > 0 || otherFunctionTypes != null && otherFunctionTypes.length > 0) { Disjunction disjunction = Restrictions.disjunction(); if (functionalizingEntityClassNames != null && functionalizingEntityClassNames.length > 0) { Integer[] functionalizingEntityClassNameIntegers = this .convertToFunctionalizingEntityClassOrderNumber(functionalizingEntityClassNames); Criterion funcEntityCrit = Restrictions.in("funcEntity.class", functionalizingEntityClassNameIntegers); disjunction.add(funcEntityCrit); } if (otherFunctionalizingEntityTypes != null && otherFunctionalizingEntityTypes.length > 0) { Integer classOrderNumber = Constants.FUNCTIONALIZING_ENTITY_SUBCLASS_ORDER_MAP .get("OtherFunctionalizingEntity"); Criterion otherFuncCrit1 = Restrictions.eq("funcEntity.class", classOrderNumber); Criterion otherFuncCrit2 = Restrictions.in("funcEntity.type", otherFunctionalizingEntityTypes); Criterion otherFuncCrit = Restrictions.and(otherFuncCrit1, otherFuncCrit2); disjunction.add(otherFuncCrit); } crit.add(disjunction); } // function if (functionClassNames != null && functionClassNames.length > 0 || otherFunctionTypes != null && otherFunctionTypes.length > 0) { Disjunction disjunction = Restrictions.disjunction(); crit.createAlias("nanoEntity.composingElementCollection", "compElement", CriteriaSpecification.LEFT_JOIN).createAlias("compElement.inherentFunctionCollection", "inFunc", CriteriaSpecification.LEFT_JOIN); crit.createAlias("funcEntity.functionCollection", "func", CriteriaSpecification.LEFT_JOIN); if (functionClassNames != null && functionClassNames.length > 0) { Criterion funcCrit1 = Restrictions.in("inFunc.class", functionClassNames); Criterion funcCrit2 = Restrictions.in("func.class", functionClassNames); disjunction.add(funcCrit1).add(funcCrit2); } if (otherFunctionTypes != null && otherFunctionTypes.length > 0) { Criterion otherFuncCrit1 = Restrictions.and(Restrictions.eq("inFunc.class", "OtherFunction"), Restrictions.in("inFunc.type", otherFunctionTypes)); Criterion otherFuncCrit2 = Restrictions.and(Restrictions.eq("func.class", "OtherFunction"), Restrictions.in("func.type", otherFunctionTypes)); disjunction.add(otherFuncCrit1).add(otherFuncCrit2); } crit.add(disjunction); } // join characterization if (characterizationClassNames != null && characterizationClassNames.length > 0 || otherCharacterizationTypes != null && otherCharacterizationTypes.length > 0 || wordList != null && wordList.length > 0) { crit.createAlias("characterizationCollection", "chara", CriteriaSpecification.LEFT_JOIN); } // characterization if (characterizationClassNames != null && characterizationClassNames.length > 0 || otherCharacterizationTypes != null && otherCharacterizationTypes.length > 0) { Disjunction disjunction = Restrictions.disjunction(); if (characterizationClassNames != null && characterizationClassNames.length > 0) { Criterion charCrit = Restrictions.in("chara.class", characterizationClassNames); disjunction.add(charCrit); } if (otherCharacterizationTypes != null && otherCharacterizationTypes.length > 0) { Criterion otherCharCrit1 = Restrictions.eq("chara.class", "OtherCharacterization"); Criterion otherCharCrit2 = Restrictions.in("chara.name", otherCharacterizationTypes); Criterion otherCharCrit = Restrictions.and(otherCharCrit1, otherCharCrit2); disjunction.add(otherCharCrit); } crit.add(disjunction); } // join keyword, finding, publication if (wordList != null && wordList.length > 0) { crit.createAlias("keywordCollection", "keyword1", CriteriaSpecification.LEFT_JOIN); crit.createAlias("chara.findingCollection", "finding", CriteriaSpecification.LEFT_JOIN) .createAlias("finding.fileCollection", "charFile", CriteriaSpecification.LEFT_JOIN) .createAlias("charFile.keywordCollection", "keyword2", CriteriaSpecification.LEFT_JOIN); // publication keywords crit.createAlias("publicationCollection", "pub1", CriteriaSpecification.LEFT_JOIN); crit.createAlias("pub1.keywordCollection", "keyword3", CriteriaSpecification.LEFT_JOIN); } // keyword if (wordList != null && wordList.length > 0) { Disjunction disjunction = Restrictions.disjunction(); for (String keyword : wordList) { // strip wildcards from either ends of keyword keyword = StringUtils.stripWildcards(keyword); Criterion keywordCrit1 = Restrictions.ilike("keyword1.name", keyword, MatchMode.ANYWHERE); Criterion keywordCrit2 = Restrictions.ilike("keyword2.name", keyword, MatchMode.ANYWHERE); Criterion keywordCrit3 = Restrictions.ilike("keyword3.name", keyword, MatchMode.ANYWHERE); disjunction.add(keywordCrit1); disjunction.add(keywordCrit2); disjunction.add(keywordCrit3); } for (String word : wordList) { Criterion summaryCrit1 = Restrictions.ilike("chara.designMethodsDescription", word, MatchMode.ANYWHERE); Criterion summaryCrit2 = Restrictions.ilike("charFile.description", word, MatchMode.ANYWHERE); Criterion summaryCrit = Restrictions.or(summaryCrit1, summaryCrit2); disjunction.add(summaryCrit); } crit.add(disjunction); } CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); List results = appService.query(crit); int resSize = results.size(); /* * We will look only though the maximum amount of allowed records to avoid Exceptions */ int maxCount = appService.getMaxRecordsCount(); Set<Sample> samples = new HashSet<Sample>(); for (int i = 0; (i < resSize) && (i < maxCount); i++) { try { /* * There is a bug when searching with keyword "tes", where the following line * whould trigger a ClassCastException. Reason unknow but suspected to be reaching * the last row of a dataset. */ // Object[] row = (Object[]) obj; Object[] row = (Object[]) results.get(i); Long sampleId = (Long) row[0]; if (springSecurityAclService.currentUserHasReadPermission(sampleId, SecureClassesEnum.SAMPLE.getClazz()) || springSecurityAclService.currentUserHasWritePermission(sampleId, SecureClassesEnum.SAMPLE.getClazz())) { Sample sample = new Sample(); sample.setId(sampleId); sample.setName((String) row[1]); sample.setCreatedDate((Date) row[2]); samples.add(sample); } else { logger.debug("User doesn't have access to sample of ID: " + sampleId); } } catch (ClassCastException e) { logger.error("Got ClassCastException: " + e.getMessage()); break; } } List<Sample> orderedSamples = new ArrayList<Sample>(samples); // Collections.sort(orderedSamples, // Collections.reverseOrder(new Comparators.SampleDateComparator())); Collections.sort(orderedSamples, new Comparators.SampleDateComparator()); for (Sample sample : orderedSamples) { sampleIds.add(sample.getId().toString()); } return sampleIds; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public List<String> findSampleIdsByOwner(String currentOwner) throws Exception { List<String> sampleIds = new ArrayList<String>(); // can't query for the entire Sample object due to // limitations in pagination in SDK // Sample sample = new Sample(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("id")); DetachedCriteria crit = DetachedCriteria.forClass(Sample.class); crit.setProjection(Projections.distinct(projectionList)); Criterion crit1 = Restrictions.eq("createdBy", currentOwner); // in case of copy createdBy is like lijowskim:COPY Criterion crit2 = Restrictions.like("createdBy", currentOwner + ":", MatchMode.START); crit.add(Expression.or(crit1, crit2)); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();//www.j a v a 2s. c o m List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { String id = results.get(i).toString(); if (springSecurityAclService.currentUserHasReadPermission(Long.valueOf(id), SecureClassesEnum.SAMPLE.getClazz()) || springSecurityAclService.currentUserHasWritePermission(Long.valueOf(id), SecureClassesEnum.SAMPLE.getClazz())) { sampleIds.add(id); } else { logger.debug("User doesn't have access to sample of ID: " + id); } } return sampleIds; }
From source file:government.data.ProvinceManager.java
@Override public Province getProvinceByName(String name, Session session) { String hql = "From Province"; ProjectionList proList = Projections.projectionList(); Criteria criteria = session.createCriteria(Province.class) .add(Restrictions.like("name", name, MatchMode.EXACT)); Province province = (Province) criteria.uniqueResult(); return province; }
From source file:gr.abiss.calipso.domain.ItemSearch.java
License:Open Source License
public List<DetachedCriteria> getGroupByCriteria() { List<DetachedCriteria> criteriaList = new LinkedList(); List<ColumnHeading> optionHeadings = getGroupByHeadings(); if (CollectionUtils.isNotEmpty(optionHeadings)) { for (ColumnHeading heading : optionHeadings) { DetachedCriteria criteria = this.getCriteria(); criteria.setProjection(/*from w w w . j av a 2 s. c om*/ Projections.projectionList().add(Projections.groupProperty(heading.getNameText())) .add(Projections.rowCount(), "rowCount")) .addOrder(Order.desc("rowCount")); criteriaList.add(criteria); } } return criteriaList; }
From source file:gr.abiss.calipso.hibernate.HibernateDao.java
License:Open Source License
@Override public Map<String, List> findItemGroupByTotals(ItemSearch itemSearch) { Map<String, List> results = new HashMap<String, List>(); List<ColumnHeading> optionHeadings = itemSearch.getGroupByHeadings(); if (CollectionUtils.isNotEmpty(optionHeadings)) { DetachedCriteria criteria = itemSearch.getCriteria(); for (ColumnHeading heading : optionHeadings) { criteria.setProjection(/*from w w w .ja va 2 s . c o m*/ Projections.projectionList().add(Projections.groupProperty(heading.getNameText())) .add(Projections.rowCount(), "rowCount")) .addOrder(Order.desc("rowCount")); List queryResults = getHibernateTemplate().findByCriteria(criteria); results.put(heading.getNameText(), queryResults); } } return results; }