List of usage examples for org.hibernate.criterion Projections groupProperty
public static PropertyProjection groupProperty(String propertyName)
From source file:org.infoscoop.dao.KeywordLogDAO.java
License:Open Source License
/** * Get the map to add up keyword-ranking. * // w w w . j av a2s .c o m * @param startDate * @param endDate * @param keywordLogType * @return */ public Map getCountMap(final String startDate, final String endDate, final Integer keywordLogType) { Map countMap = (Map) super.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Map countMap = new SequencedHashMap(); Criteria cri = session.createCriteria(Keyword.class); SimpleExpression se = Expression.eq("Type", keywordLogType); LogicalExpression le = Expression.and(Expression.ge("Date", startDate), Expression.le("Date", endDate)); LogicalExpression le2 = Expression.and(se, le); cri.add(le2); Projection projection = Projections.projectionList().add(Projections.property("Keyword")) .add(Projections.count("Keyword").as("KwdCount")).add(Projections.groupProperty("Keyword")); cri.setProjection(projection); cri.addOrder(Order.desc("KwdCount")); try { Object[] resultObjs; for (Iterator ite = cri.list().iterator(); ite.hasNext();) { resultObjs = (Object[]) ite.next(); String keyword = (String) resultObjs[0]; Integer count = (Integer) resultObjs[1]; countMap.put(keyword, count); } } catch (Exception e) { logger.error("parsing error", e); throw new RuntimeException(); } if (log.isInfoEnabled()) log.info("getCountMap successfully. : startDate=" + startDate + ", endDate=" + endDate + ", keywordLogType=" + keywordLogType); return countMap; } }); return countMap; }
From source file:org.jasig.ssp.dao.CaseloadDao.java
License:Apache License
private PagingWrapper<CoachCaseloadRecordCountForProgramStatus> caseloadCountsByStatusWithDateRestrictions( Criterion dateRestrictions, List<UUID> studentTypeIds, List<UUID> serviceReasonIds, List<UUID> specialServiceGroupIds, String homeDepartment, SortingAndPaging sAndP) { final Criteria query = createCriteria(); query.createAlias("programStatuses", "ps").createAlias("coach", "c"); if (dateRestrictions != null) { query.add(dateRestrictions);/*from w ww . j a va 2 s . co m*/ } if (studentTypeIds != null && !studentTypeIds.isEmpty()) { query.add(Restrictions.in("studentType.id", studentTypeIds)); } if (serviceReasonIds != null && !serviceReasonIds.isEmpty()) { query.createAlias("serviceReasons", "serviceReasons"); query.createAlias("serviceReasons.serviceReason", "serviceReason"); query.add(Restrictions.in("serviceReason.id", serviceReasonIds)); query.add(Restrictions.eq("serviceReasons.objectStatus", ObjectStatus.ACTIVE)); } if (specialServiceGroupIds != null && !specialServiceGroupIds.isEmpty()) { query.createAlias("specialServiceGroups", "personSpecialServiceGroups").add( Restrictions.in("personSpecialServiceGroups.specialServiceGroup.id", specialServiceGroupIds)); query.add(Restrictions.eq("personSpecialServiceGroups.objectStatus", ObjectStatus.ACTIVE)); } if (homeDepartment == null || homeDepartment.length() <= 0) query.createAlias("coach.staffDetails", "sd", JoinType.LEFT_OUTER_JOIN); else { query.createAlias("coach.staffDetails", "sd"); query.add(Restrictions.eq("sd.departmentName", homeDepartment)); } ProjectionList projectionList = Projections.projectionList() .add(Projections.groupProperty("c.id").as("coachId")); // TODO find a way to turn these into more generic and centralized // feature checks on the Dialect so we at least aren't scattering // Dialect-specific code all over the place Dialect dialect = ((SessionFactoryImplementor) sessionFactory).getDialect(); if (dialect instanceof SQLServerDialect) { // sql server requires all these to part of the grouping projectionList.add(Projections.groupProperty("c.lastName").as("coachLastName")) .add(Projections.groupProperty("c.firstName").as("coachFirstName")) .add(Projections.groupProperty("c.middleName").as("coachMiddleName")) .add(Projections.groupProperty("c.schoolId").as("coachSchoolId")) .add(Projections.groupProperty("c.username").as("coachUsername")); } else { // other dbs (postgres) don't need these in the grouping projectionList.add(Projections.property("c.lastName").as("coachLastName")) .add(Projections.property("c.firstName").as("coachFirstName")) .add(Projections.property("c.middleName").as("coachMiddleName")) .add(Projections.property("c.schoolId").as("coachSchoolId")) .add(Projections.property("c.username").as("coachUsername")); } projectionList.add(Projections.groupProperty("sd.departmentName").as("coachDepartmentName")) .add(Projections.groupProperty("ps.programStatus.id").as("programStatusId")) .add(Projections.count("ps.programStatus.id").as("count")); query.setProjection(projectionList); if (sAndP == null || !(sAndP.isSorted())) { // there are assumptions in CaseloadServiceImpl about this // default ordering... make sure it stays synced up query.addOrder(Order.asc("c.lastName")).addOrder(Order.asc("c.firstName")) .addOrder(Order.asc("c.middleName")); // can't sort on program status name without another join, but // sorting on id is non-deterministic across dbs (sqlserver sorts // UUIDs one way, Postgres another, so you can't write a single // integration test for both), so more dialect specific magic here. if (dialect instanceof SQLServerDialect) { query.addOrder(OrderAsString.asc("ps.programStatus.id")); } else { query.addOrder(Order.asc("ps.programStatus.id")); } } if (sAndP != null) { sAndP.addAll(query); } query.setResultTransformer( new AliasToBeanResultTransformer(CoachCaseloadRecordCountForProgramStatus.class)); // item count Long totalRows = 0L; if ((sAndP != null) && sAndP.isPaged()) { query.setProjection(new MultipleCountProjection("c.id;ps.programStatus.id").setDistinct()); totalRows = (Long) query.uniqueResult(); if (totalRows == 0) { Collection<CoachCaseloadRecordCountForProgramStatus> empty = Lists.newArrayListWithCapacity(0); return new PagingWrapper<CoachCaseloadRecordCountForProgramStatus>(0, empty); } // clear the row count projection query.setProjection(null); } return sAndP == null ? new PagingWrapper<CoachCaseloadRecordCountForProgramStatus>(query.list()) : new PagingWrapper<CoachCaseloadRecordCountForProgramStatus>(totalRows, query.list()); }
From source file:org.jasig.ssp.dao.EarlyAlertDao.java
License:Apache License
private Map<UUID, Number> getCountOfAlertsForPeopleId(@NotNull final Collection<UUID> personIds, CriteriaCallback criteriaCallback) { // validate//from w w w . j a v a2s . c o m if (personIds == null) { throw new IllegalArgumentException("Must include a collection of personIds (students)."); } // setup return value final Map<UUID, Number> countForPeopleId = Maps.newHashMap(); // only run the query to fill the return Map if values were given if (!personIds.isEmpty()) { BatchProcessor<UUID, Object[]> processor = new BatchProcessor<UUID, Object[]>(personIds); do { Criteria query = createCriteria(); final ProjectionList projections = Projections.projectionList(); projections.add(Projections.groupProperty("person.id").as("personId")); projections.add(Projections.count("id")); query.setProjection(projections); query.add(Restrictions.eq("objectStatus", ObjectStatus.ACTIVE)); if (criteriaCallback != null) { query = criteriaCallback.criteria(query); } processor.process(query, "person.id"); } while (processor.moreToProcess()); // run query @SuppressWarnings("unchecked") final List<Object[]> results = processor.getSortedAndPagedResultsAsList(); // put query results into return value for (final Object[] result : results) { countForPeopleId.put((UUID) result[0], (Number) result[1]); } // ensure all people IDs that were request exist in return Map for (final UUID id : personIds) { if (!countForPeopleId.containsKey(id)) { countForPeopleId.put(id, 0); } } } return countForPeopleId; }
From source file:org.jasig.ssp.dao.EarlyAlertDao.java
License:Apache License
@SuppressWarnings("unchecked") public PagingWrapper<EarlyAlertStudentReportTO> getStudentsEarlyAlertCountSetForCriteria( EarlyAlertStudentSearchTO criteriaTO, SortingAndPaging sAndP) { final Criteria query = createCriteria(); setPersonCriteria(query.createAlias("person", "person"), criteriaTO.getAddressLabelSearchTO()); if (criteriaTO.getTermCode() != null) { query.add(Restrictions.eq("courseTermCode", criteriaTO.getTermCode())); }/*from w w w . j av a 2 s . c om*/ if (criteriaTO.getStartDate() != null) { query.add(Restrictions.ge("createdDate", criteriaTO.getStartDate())); } if (criteriaTO.getEndDate() != null) { query.add(Restrictions.le("createdDate", criteriaTO.getEndDate())); } query.setProjection(null); List<UUID> ids = query.setProjection(Projections.distinct(Projections.property("id"))).list(); if (ids.size() <= 0) { return null; } BatchProcessor<UUID, EarlyAlertStudentReportTO> processor = new BatchProcessor<UUID, EarlyAlertStudentReportTO>( ids, sAndP); do { final Criteria criteria = createCriteria(); ProjectionList projections = Projections.projectionList() .add(Projections.countDistinct("id").as("earlyalert_total")) .add(Projections.countDistinct("closedBy").as("earlyalert_closed")); addBasicStudentProperties(projections, criteria); projections.add(Projections.groupProperty("id").as("earlyalert_earlyAlertId")); criteria.setProjection(projections); criteria.setResultTransformer( new NamespacedAliasToBeanResultTransformer(EarlyAlertStudentReportTO.class, "earlyalert_")); processor.process(criteria, "id"); } while (processor.moreToProcess()); return processor.getSortedAndPagedResults(); }
From source file:org.jasig.ssp.dao.EarlyAlertDao.java
License:Apache License
private ProjectionList addBasicStudentProperties(ProjectionList projections, Criteria criteria) { criteria.createAlias("person", "person"); criteria.createAlias("person.programStatuses", "personProgramStatuses", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("person.coach", "c"); criteria.createAlias("person.staffDetails", "personStaffDetails", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("person.specialServiceGroups", "personSpecialServiceGroups", JoinType.LEFT_OUTER_JOIN); projections.add(Projections.groupProperty("person.firstName").as("earlyalert_firstName")); projections.add(Projections.groupProperty("person.middleName").as("earlyalert_middleName")); projections.add(Projections.groupProperty("person.lastName").as("earlyalert_lastName")); projections.add(Projections.groupProperty("person.schoolId").as("earlyalert_schoolId")); projections/* w w w.j a va2 s . co m*/ .add(Projections.groupProperty("person.primaryEmailAddress").as("earlyalert_primaryEmailAddress")); projections.add( Projections.groupProperty("person.secondaryEmailAddress").as("earlyalert_secondaryEmailAddress")); projections.add(Projections.groupProperty("person.cellPhone").as("earlyalert_cellPhone")); projections.add(Projections.groupProperty("person.homePhone").as("earlyalert_homePhone")); projections.add(Projections.groupProperty("person.addressLine1").as("earlyalert_addressLine1")); projections.add(Projections.groupProperty("person.addressLine2").as("earlyalert_addressLine2")); projections.add(Projections.groupProperty("person.city").as("earlyalert_city")); projections.add(Projections.groupProperty("person.state").as("earlyalert_state")); projections.add(Projections.groupProperty("person.zipCode").as("earlyalert_zipCode")); projections.add(Projections.groupProperty("person.id").as("earlyalert_id")); criteria.createAlias("personSpecialServiceGroups.specialServiceGroup", "specialServiceGroup", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("personProgramStatuses.programStatus", "programStatus", JoinType.LEFT_OUTER_JOIN); projections.add(Projections.groupProperty("personSpecialServiceGroups.objectStatus") .as("earlyalert_specialServiceGroupAssocObjectStatus")); projections.add( Projections.groupProperty("specialServiceGroup.name").as("earlyalert_specialServiceGroupName")); projections.add(Projections.groupProperty("specialServiceGroup.id").as("earlyalert_specialServiceGroupId")); projections.add(Projections.groupProperty("programStatus.name").as("earlyalert_programStatusName")); projections.add(Projections.groupProperty("personProgramStatuses.id").as("earlyalert_programStatusId")); projections.add(Projections.groupProperty("personProgramStatuses.expirationDate") .as("earlyalert_programStatusExpirationDate")); // Join to Student Type criteria.createAlias("person.studentType", "studentType", JoinType.LEFT_OUTER_JOIN); // add StudentTypeName Column projections.add(Projections.groupProperty("studentType.name").as("earlyalert_studentTypeName")); projections.add(Projections.groupProperty("studentType.code").as("earlyalert_studentTypeCode")); Dialect dialect = ((SessionFactoryImplementor) sessionFactory).getDialect(); if (dialect instanceof SQLServerDialect) { // sql server requires all these to part of the grouping // projections.add(Projections.groupProperty("c.id").as("coachId")); projections.add(Projections.groupProperty("c.lastName").as("earlyalert_coachLastName")) .add(Projections.groupProperty("c.firstName").as("earlyalert_coachFirstName")) .add(Projections.groupProperty("c.middleName").as("earlyalert_coachMiddleName")) .add(Projections.groupProperty("c.schoolId").as("earlyalert_coachSchoolId")) .add(Projections.groupProperty("c.username").as("earlyalert_coachUsername")); } else { // other dbs (postgres) don't need these in the grouping // projections.add(Projections.property("c.id").as("coachId")); projections.add(Projections.groupProperty("c.lastName").as("earlyalert_coachLastName")) .add(Projections.groupProperty("c.firstName").as("earlyalert_coachFirstName")) .add(Projections.groupProperty("c.middleName").as("earlyalert_coachMiddleName")) .add(Projections.groupProperty("c.schoolId").as("earlyalert_coachSchoolId")) .add(Projections.groupProperty("c.username").as("earlyalert_coachUsername")); } return projections; }
From source file:org.jasig.ssp.dao.EarlyAlertDao.java
License:Apache License
@SuppressWarnings("unchecked") public PagingWrapper<EntityStudentCountByCoachTO> getStudentEarlyAlertCountByCoaches( EntityCountByCoachSearchForm form) { List<Person> coaches = form.getCoaches(); List<AuditPerson> auditCoaches = new ArrayList<AuditPerson>(); for (Person person : coaches) { auditCoaches.add(new AuditPerson(person.getId())); }// w w w .j a va 2 s.co m BatchProcessor<AuditPerson, EntityStudentCountByCoachTO> processor = new BatchProcessor<AuditPerson, EntityStudentCountByCoachTO>( auditCoaches, form.getSAndP()); do { final Criteria query = createCriteria(); setBasicCriteria(query, form); query.setProjection(Projections.projectionList() .add(Projections.countDistinct("person").as("earlyalert_studentCount")) .add(Projections.countDistinct("id").as("earlyalert_entityCount")) .add(Projections.groupProperty("createdBy").as("earlyalert_coach"))); query.setResultTransformer( new NamespacedAliasToBeanResultTransformer(EntityStudentCountByCoachTO.class, "earlyalert_")); processor.process(query, "createdBy"); } while (processor.moreToProcess()); return processor.getSortedAndPagedResults(); }
From source file:org.jasig.ssp.dao.EarlyAlertDao.java
License:Apache License
public List<Triple<String, Long, Long>> getEarlyAlertReasonTypeCountByCriteria(Campus campus, String termCode, Date createdDateFrom, Date createdDateTo, ObjectStatus objectStatus) { final Criteria criteria = createCriteria(); if (termCode != null) { criteria.add(Restrictions.eq("courseTermCode", termCode)); }// w w w . jav a2 s.co m if (createdDateFrom != null) { criteria.add(Restrictions.ge("createdDate", createdDateFrom)); } if (createdDateTo != null) { criteria.add(Restrictions.le("createdDate", createdDateTo)); } if (campus != null) { criteria.add(Restrictions.eq("campus", campus)); } if (objectStatus != null) { criteria.add(Restrictions.eq("objectStatus", objectStatus)); } criteria.createAlias("earlyAlertReasonIds", "eareasons"); ProjectionList projections = Projections.projectionList().add(Projections.property("eareasons.name")) .add(Projections.countDistinct("person")).add(Projections.count("id")); projections.add(Projections.groupProperty("eareasons.name")); criteria.setProjection(projections); criteria.addOrder(Order.asc("eareasons.name")); final List<Triple<String, Long, Long>> reasonCounts = new ArrayList<>(); for (final Object result : criteria.list()) { Object[] resultReasonCounts = (Object[]) result; reasonCounts.add(new Triple((String) resultReasonCounts[0], (Long) resultReasonCounts[1], (Long) resultReasonCounts[2])); } return reasonCounts; }
From source file:org.jasig.ssp.dao.EarlyAlertResponseDao.java
License:Apache License
@SuppressWarnings({ "unchecked" }) public Collection<EarlyAlertStudentOutreachReportTO> getEarlyAlertOutreachCountByOutcome(String alertTermCode, Date alertCreateDateFrom, Date alertCreateDateTo, Date responseCreateDateFrom, Date responseCreateDateTo, List<UUID> outcomes, String homeDepartment, Person coach) { final Criteria query = createCriteria(); query.createAlias("earlyAlert", "earlyAlert"); if (alertTermCode != null) { query.add(Restrictions.eq("earlyAlert.courseTermCode", alertTermCode)); }/*from www. j a v a 2 s. com*/ if (alertCreateDateFrom != null) { query.add(Restrictions.ge("earlyAlert.createdDate", alertCreateDateFrom)); } if (alertCreateDateTo != null) { query.add(Restrictions.le("earlyAlert.createdDate", alertCreateDateTo)); } if (responseCreateDateFrom != null) { query.add(Restrictions.ge("createdDate", responseCreateDateFrom)); } if (responseCreateDateTo != null) { query.add(Restrictions.le("createdDate", responseCreateDateTo)); } if (outcomes != null && outcomes.size() > 0) { query.add(Restrictions.in("earlyAlertOutcome.id", outcomes)); } query.createAlias("earlyAlert.person", "student"); Criteria coachCriteria = query.createAlias("student.coach", "coach"); if (coach != null) { coachCriteria.add(Restrictions.eq("coach.id", coach.getId())); } if (homeDepartment != null && homeDepartment.length() > 0) { query.createAlias("coach.staffDetails", "personStaffDetails"); query.add(Restrictions.eq("personStaffDetails.departmentName", homeDepartment)); } else { query.createAlias("coach.staffDetails", "personStaffDetails", JoinType.LEFT_OUTER_JOIN); } ProjectionList projections = Projections.projectionList() .add(Projections.groupProperty("earlyAlert.id").as("ea_outcome_earlyAlertId")); projections.add(Projections.groupProperty("coach.firstName").as("ea_outcome_coachFirstName")); projections.add(Projections.groupProperty("coach.middleName").as("ea_outcome_coachMiddleName")); projections.add(Projections.groupProperty("coach.lastName").as("ea_outcome_coachLastName")); projections.add(Projections.groupProperty("coach.id").as("ea_outcome_coachId")); projections.add(Projections.groupProperty("coach.schoolId").as("ea_outcome_coachSchoolId")); projections.add(Projections.groupProperty("personStaffDetails.departmentName") .as("ea_outcome_coachDepartmentName")); query.createAlias("earlyAlertOutreachIds", "earlyAlertOutreachIds"); projections.add( Projections.groupProperty("earlyAlertOutreachIds.name").as("ea_outcome_earlyAlertOutreachName")); query.setProjection(projections).setResultTransformer( new NamespacedAliasToBeanResultTransformer(EarlyAlertStudentOutreachReportTO.class, "ea_outcome_")); // item count List<EarlyAlertStudentOutreachReportTO> values = query.list(); if (values.size() == 0) { return null; } Iterator<EarlyAlertStudentOutreachReportTO> valueIterator = values.iterator(); ArrayList<EarlyAlertStudentOutreachReportTO> responses = new ArrayList<EarlyAlertStudentOutreachReportTO>(); while (valueIterator.hasNext()) { EarlyAlertStudentOutreachReportTO value = valueIterator.next(); Integer index = responses.indexOf(value); if (index != null && index >= 0) { responses.get(index).processDuplicate(value); } else { responses.add(value); } } return responses; }
From source file:org.jasig.ssp.dao.EarlyAlertResponseDao.java
License:Apache License
@SuppressWarnings({ "unchecked", "unused" }) public List<EarlyAlertStudentResponseOutcomeReportTO> getEarlyAlertResponseOutcomeTypeForStudentsByCriteria( String outcomeType, EarlyAlertStudentSearchTO searchForm, SortingAndPaging sAndP) { final Criteria criteria = getCriteriaForOutcomeType(searchForm, sAndP); ProjectionList projections = getPersonProjection(); criteria.createAlias(outcomeType, outcomeType); projections.add(Projections.groupProperty(outcomeType + ".name").as("ea_outcome_outcomeName")); criteria.setProjection(projections).setResultTransformer(new NamespacedAliasToBeanResultTransformer( EarlyAlertStudentResponseOutcomeReportTO.class, "ea_outcome_")); return (List) criteria.list(); }
From source file:org.jasig.ssp.dao.EarlyAlertResponseDao.java
License:Apache License
private ProjectionList getPersonProjection() { ProjectionList projections = Projections.projectionList(); projections.add(Projections.groupProperty("person.firstName").as("ea_outcome_firstName")); projections.add(Projections.groupProperty("person.middleName").as("ea_outcome_middleName")); projections.add(Projections.groupProperty("person.lastName").as("ea_outcome_lastName")); projections//w w w. j av a 2 s . c o m .add(Projections.groupProperty("person.primaryEmailAddress").as("ea_outcome_primaryEmailAddress")); projections.add(Projections.groupProperty("person.schoolId").as("ea_outcome_schoolId")); projections.add(Projections.groupProperty("coach.firstName").as("ea_outcome_coachFirstName")); projections.add(Projections.groupProperty("coach.middleName").as("ea_outcome_coachMiddleName")); projections.add(Projections.groupProperty("coach.lastName").as("ea_outcome_coachLastName")); return projections; }