List of usage examples for org.hibernate.criterion Projections groupProperty
public static PropertyProjection groupProperty(String propertyName)
From source file:net.thackbarth.sparrow.DatabaseCleaner.java
License:Apache License
void removeDoubleFiles(Session session) { ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty(PROPERTY_FILE_PATH).as(PROPERTY_FILE_PATH)) .add(Projections.count(PROPERTY_FILE_PATH).as(PROPERTY_AMOUNT)); Criteria doubleCriteria = session.createCriteria(MusicTrack.class).setProjection(projectionList) .setMaxResults(configuration.getBatchSize()).addOrder(Order.desc(PROPERTY_AMOUNT)); boolean uniqueFileFound = false; do {//from w w w.j a v a 2 s .c om progress.info("Delete double files from database."); List doubleList = doubleCriteria.list(); if (doubleList.isEmpty()) { uniqueFileFound = true; } else { for (Object obj : doubleList) { uniqueFileFound = checkDoubleFiles(session, (Object[]) obj) || uniqueFileFound; } } session.flush(); } while (!uniqueFileFound); }
From source file:org.apache.usergrid.apm.service.charts.service.LogChartUtil.java
License:Apache License
public static ProjectionList getProjectionList(LogChartCriteria cq) { ProjectionList projList = Projections.projectionList(); //Adding GroupBy. We will allow only one groupby so that chart looks cleaner. if (cq.isGroupedByApp()) { projList.add(Projections.groupProperty("this.appId"), "appId"); } else if (cq.isGroupedByNetworkType()) { projList.add(Projections.groupProperty("this.networkType"), "networkType"); }//from www . j a v a 2s . co m else if (cq.isGroupedByNetworkCarrier()) { projList.add(Projections.groupProperty("this.networkCarrier"), "networkCarrier"); } switch (cq.getSamplePeriod()) { //see http://stackoverflow.com/questions/84644/hibernate-query-by-example-and-projections on why "this." is needed //in following lines case MINUTE: projList.add(Projections.groupProperty("this.endMinute"), "endMinute"); break; case HOUR: projList.add(Projections.groupProperty("this.endHour"), "endHour"); break; case DAY_WEEK: projList.add(Projections.groupProperty("this.endDay"), "endDay"); break; case DAY_MONTH: projList.add(Projections.groupProperty("this.endDay"), "endDay"); break; case MONTH: projList.add(Projections.groupProperty("this.endMonth"), "endMonth"); break; } //may run into this bug because of alias http://stackoverflow.com/questions/84644/hibernate-query-by-example-and-projections //And I did run into it. ouch. Fix was to add this.filedName !! return projList; }
From source file:org.apache.usergrid.apm.service.charts.service.NetworkMetricsChartUtil.java
License:Apache License
public static ProjectionList getProjectionList(MetricsChartCriteria cq) { ProjectionList projList = Projections.projectionList(); //Adding GroupBy. We will allow only one groupby so that chart looks cleaner. if (cq.isGroupedByApp()) { projList.add(Projections.groupProperty("this.appId"), "appId"); } else/*w ww. ja va 2 s . c om*/ projList.add(Projections.property("this.appId"), "appId"); //projList.add(Projections.groupProperty("appId"),"appId"); if (cq.isGroupedByNetworkType()) { projList.add(Projections.groupProperty("this.networkType"), "networkType"); } else if (cq.isGroupedByNetworkCarrier()) { projList.add(Projections.groupProperty("this.networkCarrier"), "networkCarrier"); } else if (cq.isGroupedByAppVersion()) { projList.add(Projections.groupProperty("this.applicationVersion"), "applicationVersion"); } else if (cq.isGroupedByAppConfigType()) { projList.add(Projections.groupProperty("this.appConfigType"), "appConfigType"); } else if (cq.isGroupedByDeviceModel()) { projList.add(Projections.groupProperty("this.deviceModel"), "deviceModel"); } else if (cq.isGroupedbyDevicePlatform()) { projList.add(Projections.groupProperty("this.devicePlatform"), "devicePlatform"); } switch (cq.getSamplePeriod()) { //see http://stackoverflow.com/questions/84644/hibernate-query-by-example-and-projections on why "this." is needed //in following lines case MINUTE: projList.add(Projections.groupProperty("this.endMinute"), "endMinute"); break; case HOUR: projList.add(Projections.groupProperty("this.endHour"), "endHour"); break; case DAY_WEEK: projList.add(Projections.groupProperty("this.endDay"), "endDay"); break; case DAY_MONTH: projList.add(Projections.groupProperty("this.endDay"), "endDay"); break; case MONTH: projList.add(Projections.groupProperty("this.endMonth"), "endMonth"); break; } //Adding Projections projList.add(Projections.sum("numSamples"), "numSamples"); projList.add(Projections.sum("numErrors"), "numErrors"); projList.add(Projections.sum("sumLatency"), "sumLatency"); projList.add(Projections.max("maxLatency"), "maxLatency"); projList.add(Projections.min("minLatency"), "minLatency"); //may run into this bug because of alias http://stackoverflow.com/questions/84644/hibernate-query-by-example-and-projections //And I did run into it. ouch. Fix was to add this.filedName !! return projList; }
From source file:org.apache.usergrid.apm.service.charts.service.SessionMetricsChartUtil.java
License:Apache License
public static ProjectionList getProjectionList(SessionChartCriteria cq) { ProjectionList projList = Projections.projectionList(); //Adding GroupBy. We will allow only one groupby so that chart looks cleaner. if (cq.isGroupedByApp()) { projList.add(Projections.groupProperty("this.appId"), "appId"); } else if (cq.isGroupedByNetworkType()) { projList.add(Projections.groupProperty("this.networkType"), "networkType"); }/*from ww w.jav a 2 s. c o m*/ else if (cq.isGroupedByNetworkCarrier()) { projList.add(Projections.groupProperty("this.networkCarrier"), "networkCarrier"); } switch (cq.getSamplePeriod()) { //see http://stackoverflow.com/questions/84644/hibernate-query-by-example-and-projections on why "this." is needed //in following lines case MINUTE: projList.add(Projections.groupProperty("this.endMinute"), "endMinute"); break; case HOUR: projList.add(Projections.groupProperty("this.endHour"), "endHour"); break; case DAY_WEEK: projList.add(Projections.groupProperty("this.endDay"), "endDay"); break; case DAY_MONTH: projList.add(Projections.groupProperty("this.endDay"), "endDay"); break; case MONTH: projList.add(Projections.groupProperty("this.endMonth"), "endMonth"); break; } //may run into this bug because of alias http://stackoverflow.com/questions/84644/hibernate-query-by-example-and-projections //And I did run into it. ouch. Fix was to add this.filedName !! return projList; }
From source file:org.candlepin.gutterball.curator.ComplianceSnapshotCurator.java
License:Open Source License
/** * Retrieves an iterator over the compliance snapshots on the target date. * * @param targetDate// ww w . java 2 s .co m * The date for which to retrieve compliance snapshots. If null, the current date will be used * instead. * * @param consumerUuids * A list of consumer UUIDs to use to filter the results. If provided, only compliances for * consumers in the list will be retrieved. * * @param ownerFilters * A list of owners to use to filter the results. If provided, only compliances for consumers * belonging to the specified owners (orgs) will be retrieved. * * @param statusFilters * A list of statuses to use to filter the results. If provided, only compliances with a status * matching the list will be retrieved. * * @param productNameFilters * A list of product names to use to filter compliances. If provided, only compliances for * consumers having installed the specified products will be retrieved. * * @param subscriptionSkuFilters * A list of subscription skus to use to filter compliances. If provided, only compliances for * the specified subscription skus will be retrieved. * * @param subscriptionNameFilters * A list of subscription names to use to filter compliances. If provided, only compliances for * the specified subscription names will be retrieved. * * @param attributeFilters * A map of entitlement attributes to use to filter compliances. If provided, only compliances * for entitlements having the specified values for the given attributes will be retrieved. * * @param pageRequest * A PageRequest instance containing paging information from the request. If null, no paging * will be performed. * * @return * A Page instance containing an iterator over the compliance snapshots for the target date and * the paging information for the query. */ @SuppressWarnings("checkstyle:indentation") public Page<Iterator<Compliance>> getSnapshotIterator(Date targetDate, List<String> consumerUuids, List<String> ownerFilters, List<String> statusFilters, List<String> productNameFilters, List<String> subscriptionSkuFilters, List<String> subscriptionNameFilters, Map<String, String> attributeFilters, PageRequest pageRequest) { Page<Iterator<Compliance>> page = new Page<Iterator<Compliance>>(); page.setPageRequest(pageRequest); DetachedCriteria subquery = DetachedCriteria.forClass(Compliance.class); subquery.createAlias("consumer", "c"); subquery.createAlias("c.consumerState", "state"); // https://hibernate.atlassian.net/browse/HHH-2776 if (consumerUuids != null && !consumerUuids.isEmpty()) { subquery.add(Restrictions.in("c.uuid", consumerUuids)); } Date toCheck = targetDate == null ? new Date() : targetDate; subquery.add( Restrictions.or(Restrictions.isNull("state.deleted"), Restrictions.gt("state.deleted", toCheck))); subquery.add(Restrictions.le("state.created", toCheck)); if (ownerFilters != null && !ownerFilters.isEmpty()) { subquery.createAlias("c.owner", "o"); subquery.add(Restrictions.in("o.key", ownerFilters)); } subquery.add(Restrictions.le("date", toCheck)); subquery.setProjection( Projections.projectionList().add(Projections.max("date")).add(Projections.groupProperty("c.uuid"))); Session session = this.currentSession(); Criteria query = session.createCriteria(Compliance.class, "comp").createAlias("comp.consumer", "cs") .add(Subqueries.propertiesIn(new String[] { "comp.date", "cs.uuid" }, subquery)) .setCacheMode(CacheMode.IGNORE).setReadOnly(true); if ((statusFilters != null && !statusFilters.isEmpty()) || (attributeFilters != null && attributeFilters.containsKey("management_enabled")) || (productNameFilters != null && !productNameFilters.isEmpty())) { query.createAlias("comp.status", "stat"); if (statusFilters != null && !statusFilters.isEmpty()) { query.add(Restrictions.in("stat.status", statusFilters)); } if (attributeFilters != null && attributeFilters.containsKey("management_enabled")) { boolean managementEnabledFilter = PropertyConverter .toBoolean(attributeFilters.get("management_enabled")); query.add(Restrictions.eq("stat.managementEnabled", managementEnabledFilter)); } if (productNameFilters != null && !productNameFilters.isEmpty()) { query.createAlias("stat.compliantProducts", "cprod", JoinType.LEFT_OUTER_JOIN) .createAlias("stat.partiallyCompliantProducts", "pcprod", JoinType.LEFT_OUTER_JOIN) .createAlias("stat.nonCompliantProducts", "ncprod", JoinType.LEFT_OUTER_JOIN); DetachedCriteria prodQuery = DetachedCriteria.forClass(Compliance.class, "comp2"); prodQuery.createAlias("comp2.consumer", "cons2"); prodQuery.createAlias("cons2.installedProducts", "installed"); prodQuery.add(Restrictions.and(Restrictions.in("installed.productName", productNameFilters), Restrictions.eqProperty("comp2.id", "comp.id"))); prodQuery.setProjection(Projections.property("installed.productId")); query.add(Restrictions.or(Property.forName("cprod.productId").in(prodQuery), Property.forName("pcprod.productId").in(prodQuery), Property.forName("ncprod.productId").in(prodQuery))); } } // Add subscription filters, if necessary if ((subscriptionSkuFilters != null && !subscriptionSkuFilters.isEmpty()) || (subscriptionNameFilters != null && !subscriptionNameFilters.isEmpty())) { // Impl note: We have to be very careful with alias names, as Hibernate has a tendancy // to errorneously truncate "long" ones. Actual property/field names are safe, though. query.createAlias("comp.entitlements", "entsnap"); if (subscriptionSkuFilters != null && !subscriptionSkuFilters.isEmpty()) { query.add(Restrictions.in("entsnap.productId", subscriptionSkuFilters)); } if (subscriptionNameFilters != null && !subscriptionNameFilters.isEmpty()) { query.add(Restrictions.in("entsnap.productName", subscriptionNameFilters)); } } if (pageRequest != null && pageRequest.isPaging()) { page.setMaxRecords(this.getRowCount(query)); query.setFirstResult((pageRequest.getPage() - 1) * pageRequest.getPerPage()); query.setMaxResults(pageRequest.getPerPage()); if (pageRequest.getSortBy() != null) { query.addOrder( pageRequest.getOrder() == PageRequest.Order.ASCENDING ? Order.asc(pageRequest.getSortBy()) : Order.desc(pageRequest.getSortBy())); } } page.setPageData(new AutoEvictingColumnarResultsIterator<Compliance>(session, query.scroll(ScrollMode.FORWARD_ONLY), 0)); return page; }
From source file:org.egov.adtax.repository.AdvertisementRepositoryImpl.java
License:Open Source License
@Override public List<Object[]> fetchAdvertisementBySearchType(final Advertisement hoarding, final String searchType) { final Criteria criteria = entityManager.unwrap(Session.class) .createCriteria(AdvertisementPermitDetail.class, "permit") .createAlias("permit.advertisement", "advertisement").createAlias("advertisement.ward", "ward") .createAlias("advertisement.locality", "locality").createAlias("advertisement.category", "category") .createAlias("advertisement.subCategory", "subCategory") .createAlias("advertisement.revenueInspector", "revenueInspector") .createAlias("permit.agency", "agency"); if ("agency".equalsIgnoreCase(searchType)) criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("agency"), "agency") .add(Projections.rowCount(), "count")) .setResultTransformer(Transformers.aliasToBean(AgencyWiseResult.class)); if (null != hoarding.getAdvertisementNumber() && !hoarding.getAdvertisementNumber().isEmpty()) criteria.add(Restrictions.eq("hoarding.advertisementNumber", hoarding.getAdvertisementNumber())); if (null != hoarding.getLocality()) criteria.add(Restrictions.eq("locality.id", hoarding.getLocality().getId())); if (null != hoarding.getWard()) criteria.add(Restrictions.eq("ward.id", hoarding.getWard().getId())); if (null != hoarding.getCategory()) criteria.add(Restrictions.eq("category.id", hoarding.getCategory().getId())); if (null != hoarding.getSubCategory()) criteria.add(Restrictions.eq("subCategory.id", hoarding.getSubCategory().getId())); /* if (null != hoarding.getAgency() && null!=hoarding.getAgency().getId()) criteria.add(Restrictions.eq("agency.id", hoarding.getAgency().getId())); */ if (null != hoarding.getStatus()) criteria.add(Restrictions.eq("hoarding.status", hoarding.getStatus())); if (null != hoarding.getRevenueInspector()) criteria.add(Restrictions.eq("revenueInspector.id", hoarding.getRevenueInspector().getId())); return criteria.list(); }
From source file:org.egov.infra.workflow.matrix.service.WorkFlowMatrixService.java
License:Open Source License
private void addProjectionsforCriteria(final Criteria workFlowCrit) { workFlowCrit.setProjection(//from w ww. j a v a 2s . c o m Projections.projectionList().add(Projections.groupProperty("objectType").as("objectTypeAlias")) .add(Projections.groupProperty("department").as("departmentAlias")) .add(Projections.groupProperty("additionalRule").as("additionalRuleAlias")) .add(Projections.groupProperty("fromQty").as("fromQtyAlias")) .add(Projections.groupProperty("toQty").as("toQtyAlias")) .add(Projections.groupProperty("fromDate").as("fromDateAlias")) .add(Projections.groupProperty("toDate").as("toDateAlias"))); }
From source file:org.egov.pgr.service.ComplaintTypeService.java
License:Open Source License
/** * List top 5 complaint types filed in last one month * * @return complaint Type list/*from www. ja v a 2 s. c o m*/ */ @ReadOnly public List<ComplaintType> getFrequentlyFiledComplaints() { DateTime previousDate = new DateTime(); DateTime currentDate = new DateTime(); previousDate = previousDate.minusMonths(1); Criteria criteria = entityManager.unwrap(Session.class).createCriteria(Complaint.class, "complaint"); criteria.createAlias(COMPLAINT_COMPLAINT_TYPE, "compType"); criteria.setProjection(Projections.projectionList().add(Projections.property(COMPLAINT_COMPLAINT_TYPE)) .add(Projections.count(COMPLAINT_COMPLAINT_TYPE).as("count")) .add(Projections.groupProperty(COMPLAINT_COMPLAINT_TYPE))); criteria.add(Restrictions.between("complaint.createdDate", previousDate.toDate(), currentDate.toDate())); criteria.add(Restrictions.eq("compType.isActive", Boolean.TRUE)); criteria.setMaxResults(5).addOrder(Order.desc("count")); List<Object> resultList = criteria.list(); List<ComplaintType> complaintTypeList = new ArrayList<>(); for (Object row : resultList) { Object[] columns = (Object[]) row; complaintTypeList.add((ComplaintType) columns[0]); } return complaintTypeList; }
From source file:org.egov.ptis.actions.reports.BoundaryWisePropUsgeDelegate.java
License:Open Source License
public List getZoneList() { LOGGER.debug("Entered into getZoneList method"); List zoneList = null;/*from ww w . java 2 s . c o m*/ Criterion criterion = null; Projection projection = Projections.projectionList().add(Projections.property("zone.id")) .add(Projections.property("propTypeMstrID.id")).add(Projections.sum("aggrArrDmd")) .add(Projections.sum("aggrCurrDmd")).add(Projections.count("basicPropertyID")) .add(Projections.groupProperty("zone.id")).add(Projections.groupProperty("propTypeMstrID")); Order order = Order.asc("zone.id"); /* * Integer vacTypeId = getPropertyIdbyCode("OPEN_PLOT"); criterion = * Restrictions.ne("propTypeMstrID", vacTypeId); */ zoneList = propertyDAO.getPropMaterlizeViewList(projection, criterion, order); LOGGER.debug("Zone list : " + (zoneList != null ? zoneList : ZERO)); LOGGER.debug("Exit from getZoneList method"); return zoneList; }
From source file:org.egov.ptis.actions.reports.BoundaryWisePropUsgeDelegate.java
License:Open Source License
public List getTotPropUsage(Integer bndryNo) { LOGGER.debug("Entered into getTotPropUsage method"); LOGGER.debug("Boundary Number : " + bndryNo); List wardList = null;/*from w w w . j a va 2s . c om*/ Criterion criterion = null; Criterion vacantCrit = null; Conjunction conjun = Restrictions.conjunction(); Projection projection = Projections.projectionList().add(Projections.property("propTypeMstrID.id")) .add(Projections.count("basicPropertyID")).add(Projections.sum("aggrArrDmd")) .add(Projections.sum("aggrCurrDmd")).add(Projections.groupProperty("propTypeMstrID")); if (bndryNo != null) { criterion = Restrictions.like("zone.id", bndryNo); conjun.add(criterion); } /* * Integer vacTypeId = getPropertyIdbyCode("OPEN_PLOT"); vacantCrit = * Restrictions.ne("propTypeMstrID", vacTypeId); conjun.add(vacantCrit); */ wardList = propertyDAO.getPropMaterlizeViewList(projection, conjun, null); LOGGER.debug("Ward list : " + (wardList != null ? wardList : ZERO)); LOGGER.debug("Exit from getTotPropUsage method"); return wardList; }