List of usage examples for org.hibernate.criterion Projections groupProperty
public static PropertyProjection groupProperty(String propertyName)
From source file:org.jasig.ssp.dao.TaskDao.java
License:Apache License
@SuppressWarnings("unchecked") public PagingWrapper<EntityStudentCountByCoachTO> getStudentTaskCountForCoaches( EntityCountByCoachSearchForm form) { List<AuditPerson> auditCoaches = new ArrayList<AuditPerson>(); for (Person person : form.getCoaches()) { auditCoaches.add(new AuditPerson(person.getId())); }//from w w w . j a va2 s .c om BatchProcessor<AuditPerson, EntityStudentCountByCoachTO> processor = new BatchProcessor<AuditPerson, EntityStudentCountByCoachTO>( auditCoaches, form.getSAndP()); do { final Criteria query = createCriteria(); setCriteria(query, form); query.setProjection( Projections.projectionList().add(Projections.countDistinct("person").as("task_studentCount")) .add(Projections.countDistinct("id").as("task_entityCount")) .add(Projections.groupProperty("createdBy").as("task_coach"))) .setResultTransformer( new NamespacedAliasToBeanResultTransformer(EntityStudentCountByCoachTO.class, "task_")); processor.process(query, "createdBy"); } while (processor.moreToProcess()); return processor.getSortedAndPagedResults(); }
From source file:org.jboss.example.portlet.jasper.db.PhoneCallHibernateServiceImpl.java
License:Open Source License
public List<Object[]> getChartDataForPhoneNumber(String phoneNumber) { Session s = getHibernateSession();//from www .j a v a 2 s . c o m Transaction t = s.beginTransaction(); /* select des_phone_number, count(*) from pcall_recs where phone_number = ':phoneNumber' group by des_phone_number */ try { Criteria c = s.createCriteria(PhoneCallBean.class) .setProjection(Projections.projectionList().add(Projections.groupProperty("desPhoneNumber")) .add(Projections.count("callerName"), "callsCount")) .add(Restrictions.eq("phoneNumber", phoneNumber)); /* Result of Hibernate Query with aggregate function is List<Object[]> */ @SuppressWarnings("unchecked") List<Object[]> l = c.list(); t.commit(); return l; } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } return null; }
From source file:org.jpos.qi.EntityContainer.java
License:Open Source License
public int size() { if (size == null) { try {/*from w w w. j ava 2 s. co m*/ size = (Long) DB.exec((db) -> { Criteria crit = getBaseCriteria(db); if (searchRestrictions != null && searchRestrictions.size() > 0) { for (Criterion c : searchRestrictions) { crit.add(c); } } if (restrictions != null && restrictions.size() > 0) { for (Criterion c : restrictions) { crit.add(c); } } crit = crit.setProjection(Projections.projectionList().add(Projections.rowCount()) .add(Projections.groupProperty("id"))); return (long) crit.list().size(); }); } catch (Exception e) { QI.getQI().getLog().error(e); return 0; } } return (int) size.longValue(); }
From source file:org.me.employerServices.JobMarketReporting.java
/** * Web service operation//from w w w. j a va 2 s. c o m */ @WebMethod(operationName = "getMostDesiredCreds") public List<String> getMostDesiredCreds(@WebParam(name = "occupation") String occupation) { Session s = null; Transaction tx = null; try { s = factory.openSession(); tx = s.beginTransaction(); // get jobs List<KnowledgeSkill> skills = (List<KnowledgeSkill>) s .createCriteria(KnowledgeSkill.class).setProjection(Projections.projectionList() .add(Projections.rowCount(), "skillCount").add(Projections.groupProperty("id"))) .addOrder(Order.desc("skillCount")); // get count of skills from jobs // return top k skills //TODO write your implementation code here: } catch (Exception ex) { } finally { } return null; }
From source file:org.mzd.shap.domain.dao.FeatureDaoSpringHibernate.java
License:Open Source License
/** * Build a list of Features for each FeatureType where only independent features * are reported. Here, independent features of a given type are those from different * detectors which do not possess any overlap in genomic coordinates. Conflicts * are resolved by consideration of the assigned rank of each detector for * a given FeatureType./*from ww w . j a v a 2 s . co m*/ */ @SuppressWarnings("unchecked") public List<Feature> findResolvedSet(final Sequence sequence, final FeatureType restrictedToType) { Object result = getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { List<Feature> features = new ArrayList<Feature>(); /* Get the list of FeatureTypes contained in this sequence, * subsequent processing will be done per type. */ Criteria crit = session.createCriteria(getPersistentClass()) .add(Restrictions.eq("sequence", sequence)) .setProjection(Projections.projectionList().add(Projections.groupProperty("type"))); if (restrictedToType != null) { crit.add(Restrictions.eq("type", restrictedToType)); } List<FeatureType> featTypes = (List<FeatureType>) crit.list(); for (FeatureType ft : featTypes) { /* For the given FeatureType, get the list of detectors * that have been used on this sequence and order them * by assigned rank. Higher rank == higher precedence. * In cases where ranks are equal, it is resolved by * alphabetic reference to their unique names. */ List<Object[]> detectors = (List<Object[]>) session.createCriteria(getPersistentClass()) .createAlias("detector", "det").setFetchMode("detector", FetchMode.JOIN) .add(Restrictions.eq("sequence", sequence)).add(Restrictions.eq("type", ft)) .addOrder(Order.desc("det.rank")).addOrder(Order.asc("det.name")) .setProjection(Projections.projectionList().add(Projections.groupProperty("detector")) .add(Projections.groupProperty("det.name")) .add(Projections.groupProperty("det.rank"))) .list(); List<Feature> independentFeaturesOfType = new ArrayList<Feature>(); for (Object[] row : detectors) { /* Get the features determined by the given detector. We * add the FeatureType here since there might be a case * where a detector can generate multiple FeatureTypes. * * This possibility becomes more likely when there are * many finely grained types. */ Detector detector = (Detector) row[0]; List<Feature> featuresOfDetector = (List<Feature>) session .createCriteria(getPersistentClass()).add(Restrictions.eq("sequence", sequence)) .add(Restrictions.eq("detector", detector)).add(Restrictions.eq("type", ft)).list(); for (Feature df : featuresOfDetector) { boolean independent = true; for (Feature ndf : independentFeaturesOfType) { if (!df.getDetector().equals(ndf.getDetector()) && !df.getLocation().independent(ndf.getLocation())) { independent = false; break; } } if (independent) { independentFeaturesOfType.add(df); } } } features.addAll(independentFeaturesOfType); } return Feature.sortAscendingStart(features); } }); return (List<Feature>) result; }
From source file:org.mzd.shap.domain.dao.FeatureDaoSpringHibernate.java
License:Open Source License
public List<FeatureBreakdownDTO> findTypeBreakdown(final Integer sequenceId) { return getHibernateTemplate().execute(new HibernateCallback<List<FeatureBreakdownDTO>>() { @SuppressWarnings("unchecked") public List<FeatureBreakdownDTO> doInHibernate(Session session) throws HibernateException, SQLException { return session.createCriteria(getPersistentClass()).createAlias("sequence", "seq") .add(Restrictions.eq("seq.id", sequenceId)) .setProjection(Projections.projectionList().add(Projections.groupProperty("type"), "type") .add(Projections.rowCount(), "count")) .addOrder(Order.asc("type")) .setResultTransformer(Transformers.aliasToBean(FeatureBreakdownDTO.class)).list(); }//from w w w. j ava 2 s . c om }); }
From source file:org.n52.sos.ds.hibernate.dao.OfferingDAO.java
License:Open Source License
/** * Get offering time extrema/*from ww w . j a v a2s . co m*/ * * @param identifiers * Optional collection of offering identifiers to fetch. If null, all offerings are returned. * @param session * Hibernate session Hibernate session * @return Map of offering time extrema, keyed by offering identifier * @throws CodedException */ @SuppressWarnings("unchecked") public Map<String, OfferingTimeExtrema> getOfferingTimeExtrema(final Collection<String> identifiers, final Session session) throws OwsExceptionReport { List<Object[]> results = null; if (HibernateHelper.isNamedQuerySupported(SQL_QUERY_OFFERING_TIME_EXTREMA, session)) { Query namedQuery = session.getNamedQuery(SQL_QUERY_OFFERING_TIME_EXTREMA); if (CollectionHelper.isNotEmpty(identifiers)) { namedQuery.setParameterList("identifiers", identifiers); } LOGGER.debug("QUERY getOfferingTimeExtrema() with NamedQuery: {}", SQL_QUERY_OFFERING_TIME_EXTREMA); results = namedQuery.list(); } else { Criteria criteria = DaoFactory.getInstance().getObservationDAO() .getDefaultObservationInfoCriteria(session).createAlias(AbstractObservation.OFFERINGS, "off") .setProjection(Projections.projectionList() .add(Projections.groupProperty("off." + Offering.IDENTIFIER)) .add(Projections.min(AbstractObservation.PHENOMENON_TIME_START)) .add(Projections.max(AbstractObservation.PHENOMENON_TIME_START)) .add(Projections.max(AbstractObservation.PHENOMENON_TIME_END)) .add(Projections.min(AbstractObservation.RESULT_TIME)) .add(Projections.max(AbstractObservation.RESULT_TIME))); if (CollectionHelper.isNotEmpty(identifiers)) { criteria.add(Restrictions.in(Offering.IDENTIFIER, identifiers)); } LOGGER.debug("QUERY getOfferingTimeExtrema(): {}", HibernateHelper.getSqlString(criteria)); results = criteria.list(); } Map<String, OfferingTimeExtrema> map = Maps.newHashMap(); for (Object[] result : results) { String offering = (String) result[0]; OfferingTimeExtrema ote = new OfferingTimeExtrema(); ote.setMinPhenomenonTime(DateTimeHelper.makeDateTime(result[1])); DateTime maxPhenStart = DateTimeHelper.makeDateTime(result[2]); DateTime maxPhenEnd = DateTimeHelper.makeDateTime(result[3]); ote.setMaxPhenomenonTime(DateTimeHelper.max(maxPhenStart, maxPhenEnd)); ote.setMinResultTime(DateTimeHelper.makeDateTime(result[4])); ote.setMaxResultTime(DateTimeHelper.makeDateTime(result[5])); map.put(offering, ote); } return map; }
From source file:org.n52.sos.ds.hibernate.dao.OfferingDAO.java
License:Open Source License
/** * Get temporal bounding box for each offering * * @param session/*from w ww. j a va2 s.c o m*/ * Hibernate session * @return a Map containing the temporal bounding box for each offering * @throws CodedException */ public Map<String, TimePeriod> getTemporalBoundingBoxesForOfferings(final Session session) throws OwsExceptionReport { if (session != null) { Criteria criteria = DaoFactory.getInstance().getObservationDAO() .getDefaultObservationInfoCriteria(session); criteria.createAlias(AbstractObservation.OFFERINGS, "off"); criteria.setProjection( Projections.projectionList().add(Projections.min(AbstractObservation.PHENOMENON_TIME_START)) .add(Projections.max(AbstractObservation.PHENOMENON_TIME_START)) .add(Projections.max(AbstractObservation.PHENOMENON_TIME_END)) .add(Projections.groupProperty("off." + Offering.IDENTIFIER))); LOGGER.debug("QUERY getTemporalBoundingBoxesForOfferings(): {}", HibernateHelper.getSqlString(criteria)); final List<?> temporalBoundingBoxes = criteria.list(); if (!temporalBoundingBoxes.isEmpty()) { final HashMap<String, TimePeriod> temporalBBoxMap = new HashMap<String, TimePeriod>( temporalBoundingBoxes.size()); for (final Object recordObj : temporalBoundingBoxes) { if (recordObj instanceof Object[]) { final Object[] record = (Object[]) recordObj; final TimePeriod value = createTimePeriod((Timestamp) record[0], (Timestamp) record[1], (Timestamp) record[2]); temporalBBoxMap.put((String) record[3], value); } } LOGGER.debug(temporalBoundingBoxes.toString()); return temporalBBoxMap; } } return new HashMap<String, TimePeriod>(0); }
From source file:org.n52.sos.ds.hibernate.dao.ProcedureDAO.java
License:Open Source License
/** * Query procedure time extrema for the provided procedure identifier * * @param session/*w w w .j a v a2s . c om*/ * @param procedureIdentifier * @return ProcedureTimeExtrema * @throws CodedException */ public TimeExtrema getProcedureTimeExtrema(final Session session, String procedureIdentifier) throws OwsExceptionReport { Object[] result; if (isProcedureTimeExtremaNamedQuerySupported(session)) { return getProcedureTimeExtremaFromNamedQuery(session, procedureIdentifier); } AbstractObservationDAO observationDAO = DaoFactory.getInstance().getObservationDAO(); Criteria criteria = observationDAO.getDefaultObservationInfoCriteria(session); if (observationDAO instanceof AbstractSeriesObservationDAO) { criteria.createAlias(SeriesObservationInfo.SERIES, "s"); criteria.createAlias("s." + Series.PROCEDURE, "p"); } else { criteria.createAlias(ObservationInfo.PROCEDURE, "p"); } criteria.add(Restrictions.eq("p." + Procedure.IDENTIFIER, procedureIdentifier)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("p." + Procedure.IDENTIFIER)); projectionList.add(Projections.min(AbstractObservation.PHENOMENON_TIME_START)); projectionList.add(Projections.max(AbstractObservation.PHENOMENON_TIME_START)); projectionList.add(Projections.max(AbstractObservation.PHENOMENON_TIME_END)); criteria.setProjection(projectionList); LOGGER.debug("QUERY getProcedureTimeExtrema(procedureIdentifier): {}", HibernateHelper.getSqlString(criteria)); result = (Object[]) criteria.uniqueResult(); return parseProcedureTimeExtremaResult(result); }
From source file:org.n52.sos.ds.hibernate.GetDataAvailabilityDAO.java
License:Open Source License
/** * Query data availability information depending on supported functionality * /*ww w . j a v a 2 s. com*/ * @param req * GetDataAvailability request * @param session * Hibernate session * @return Data availability information * @throws OwsExceptionReport * If an error occurs */ private List<?> queryDataAvailabilityValues(GetDataAvailabilityRequest req, Session session) throws OwsExceptionReport { // check is named queries are supported if (checkForNamedQueries(req, session)) { return executeNamedQuery(req, session); } // check if series mapping is supporte else if (EntitiyHelper.getInstance().isSeriesSupported()) { return querySeriesDataAvailabilities(req, session); } else { Criteria c = getDefaultObservationInfoCriteria(session); if (req.isSetFeaturesOfInterest()) { c.createCriteria(ObservationInfo.FEATURE_OF_INTEREST) .add(Restrictions.in(FeatureOfInterest.IDENTIFIER, req.getFeaturesOfInterest())); } if (req.isSetProcedures()) { c.createCriteria(ObservationInfo.PROCEDURE) .add(Restrictions.in(Procedure.IDENTIFIER, req.getProcedures())); } if (req.isSetObservedProperties()) { c.createCriteria(ObservationInfo.OBSERVABLE_PROPERTY) .add(Restrictions.in(ObservableProperty.IDENTIFIER, req.getObservedProperties())); } if (req.isSetOfferings()) { c.createCriteria(ObservationInfo.OFFERINGS) .add(Restrictions.in(Offering.IDENTIFIER, req.getOfferings())); } ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty(ObservationInfo.PROCEDURE)) .add(Projections.groupProperty(ObservationInfo.OBSERVABLE_PROPERTY)) .add(Projections.groupProperty(ObservationInfo.FEATURE_OF_INTEREST)) .add(Projections.min(ObservationInfo.PHENOMENON_TIME_START)) .add(Projections.max(ObservationInfo.PHENOMENON_TIME_END)); if (isShowCount(req)) { projectionList.add(Projections.rowCount()); } c.setProjection(projectionList); c.setResultTransformer(new DataAvailabilityTransformer(session)); LOGGER.debug("QUERY getDataAvailability(request): {}", HibernateHelper.getSqlString(c)); List<?> list = c.list(); if (isIncludeResultTime(req)) { for (Object o : list) { DataAvailability dataAvailability = (DataAvailability) o; dataAvailability.setResultTimes(getResultTimesFromObservation(dataAvailability, req, session)); } } return list; } }