List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:com.rta.vsd.data.service.impl.ViolationDataServiceImpl.java
/** * /*w w w. jav a 2s . c o m*/ * Gets a list of all the violations WithoutPlateConsficationInspections based on the plate details provided * * @author Eldon Barrows * @param dsContext * @param retrieveArabicData * @param vehiclePlateDetails * @param paginationValues * @return List<VsdViolation> * @throws VSDDataAccessException */ public List<VsdViolation> getViolationsWithoutPlateConsficationInspectionsByPlateDetails( final DataServiceContext dsContext, boolean retrieveArabicData, VehiclePlate vehiclePlateDetails, PaginationParam paginationValues) throws VSDDataAccessException { logger.info("getViolationsWithoutPlateConsficationInspectionsByPlateDetails -- START"); List<VsdViolation> violations = null; try { Session session = (Session) dsContext.getInternalContext(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("violaton.violationId"), "violationId"); projectionList.add(Projections.property("violaton.reportedDate"), "reportedDate"); Criteria crit = session.createCriteria(VsdViolation.class, "violaton") .add(Restrictions.eq("violaton.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vsdInspections", "inspections", Criteria.LEFT_JOIN, Restrictions.eq("inspections.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vsdVehicleInfo", "vehicleInfo", Criteria.LEFT_JOIN, Restrictions.eq("vehicleInfo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vehicleInfo.vehiclePlateCategory", vehiclePlateDetails.getPlateCategory()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateCode", vehiclePlateDetails.getPlateCode()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateSource", vehiclePlateDetails.getPlateSource()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateNumber", vehiclePlateDetails.getPlateNumber()) .ignoreCase()) .add(Restrictions.eq("inspections.isPlateConfiscated", Constant.FALSE)) .addOrder(Order.desc("violaton.reportedDate")) .setProjection(Projections.distinct(projectionList)); crit.setResultTransformer(new AliasToBeanResultTransformer(VsdViolation.class)); if (paginationValues.getFirstResult() != null && paginationValues.getFirstResult().longValue() != -1) { crit.setFirstResult(paginationValues.getFirstResult().intValue()); } if (paginationValues.getFetchedSize() != null && paginationValues.getFetchedSize().longValue() != -1) { crit.setMaxResults(paginationValues.getFetchedSize().intValue()); } List list = crit.list(); logger.debug("list.size() : " + list.size()); Set resultSet = new HashSet(list); logger.debug("resultSet.size() : " + resultSet.size()); if (resultSet.size() == 0) return new ArrayList(); Iterator iterator = resultSet.iterator(); ArrayList innerQueryList = new ArrayList<Long>(); while (iterator.hasNext()) { VsdViolation violation = (VsdViolation) iterator.next(); innerQueryList.add(violation.getViolationId()); } Criteria main = session.createCriteria(VsdViolation.class, "violaton") .add(Property.forName("violaton.violationId").in(innerQueryList)) .add(Restrictions.eq("violaton.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vsdInspections", "inspections", Criteria.LEFT_JOIN, Restrictions.eq("inspections.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vsdVehicleInfo", "vehicleInfo", Criteria.LEFT_JOIN, Restrictions.eq("vehicleInfo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vehicleInfo.vehiclePlateCategory", vehiclePlateDetails.getPlateCategory())) .add(Restrictions.eq("vehicleInfo.vehiclePlateCode", vehiclePlateDetails.getPlateCode())) .add(Restrictions.eq("vehicleInfo.vehiclePlateSource", vehiclePlateDetails.getPlateSource())) .add(Restrictions.eq("vehicleInfo.vehiclePlateNumber", vehiclePlateDetails.getPlateNumber())) .add(Restrictions.eq("inspections.isPlateConfiscated", Constant.FALSE)) .addOrder(Order.desc("violaton.reportedDate")); violations = main.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); logger.info("getViolationsWithoutPlateConsficationInspectionsByPlateDetails -- END"); return violations; } catch (Exception ex) { logger.error("An error occured in getViolationsWithoutPlateConsficationInspectionsByPlateDetails()"); throw new VSDDataAccessException(ex.getMessage(), ex); } }
From source file:com.sailing.hrm.persistent.base.HibernateDao.java
License:Apache License
/** * countCriteria.//from w ww . j a va 2s . c o m */ @SuppressWarnings("unchecked") protected long countCriteriaResult(final Criteria c) { CriteriaImpl impl = (CriteriaImpl) c; // Projection?ResultTransformer?OrderBy??,??Count? Projection projection = impl.getProjection(); ResultTransformer transformer = impl.getResultTransformer(); List<CriteriaImpl.OrderEntry> orderEntries = null; try { orderEntries = (List) ReflectionUtils.getFieldValue(impl, "orderEntries"); ReflectionUtils.setFieldValue(impl, "orderEntries", new ArrayList()); } catch (Exception e) { logger.error("??:{}", e); } // Count Long totalCountObject = (Long) c.setProjection(Projections.rowCount()).uniqueResult(); long totalCount = (totalCountObject != null) ? totalCountObject : 0; // ?Projection,ResultTransformerOrderBy?? c.setProjection(projection); if (projection == null) { c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); } if (transformer != null) { c.setResultTransformer(transformer); } try { ReflectionUtils.setFieldValue(impl, "orderEntries", orderEntries); } catch (Exception e) { logger.error("??:{}", e); } return totalCount; }
From source file:com.sccl.attech.common.persistence.BaseDao.java
License:Open Source License
/** * // w w w.j av a2 s . c o m * @param page * @param detachedCriteria * @param resultTransformer * @return */ @SuppressWarnings("unchecked") public Page<T> find(Page<T> page, DetachedCriteria detachedCriteria, ResultTransformer resultTransformer) { // get count if (!page.isDisabled() && !page.isNotCount()) { page.setCount(count(detachedCriteria)); if (page.getCount() < 1) { return page; } } Criteria criteria = detachedCriteria.getExecutableCriteria(getSession()); criteria.setResultTransformer(resultTransformer); // set page if (!page.isDisabled()) { criteria.setFirstResult(page.getFirstResult()); criteria.setMaxResults(page.getMaxResults()); } // order by if (StringUtils.isNotBlank(page.getOrderBy())) { for (String order : StringUtils.split(page.getOrderBy(), ",")) { String[] o = StringUtils.split(order, " "); //???? String orderStr = o[0]; if (orderStr.split("-")[0].equals("desc")) { criteria.addOrder(Order.desc(orderStr.split("-")[1])); } else { criteria.addOrder(Order.asc(orderStr.split("-")[1])); } } } page.setList(criteria.list()); return page; }
From source file:com.scit.spring.dao.GenericDAOImpl.java
@Override public Pagina selPagina(int pag, String colOrder, Estructuras.Orden orden) { Criteria c = getCurrentSession().createCriteria(clazz); c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (!colOrder.equals("") && orden != null) { switch (orden) { case asc: c.addOrder(Order.asc(colOrder)); break; case desc: c.addOrder(Order.desc(colOrder)); break; }/*from w w w . ja v a 2 s. c o m*/ } return calcular(c, pag); }
From source file:com.scopix.periscope.businesswarehouse.transfer.dao.TransferHibernateDAO.java
License:Open Source License
public List<IndicatorProductAndAreaType> getIndicatorProductAndAreaTypes(Integer indicatorId) { List<IndicatorProductAndAreaType> ipaats = null; Session session = null;/*from ww w. j a va 2 s. c o m*/ try { if (indicatorId != null) { session = this.getSession(); Criteria criteria = session.createCriteria(IndicatorProductAndAreaType.class); criteria.add(Restrictions.eq("indicator.id", indicatorId)); ipaats = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); } } finally { this.releaseSession(session); } return ipaats; }
From source file:com.scopix.periscope.businesswarehouse.transfer.dao.TransferHibernateDAO.java
License:Open Source License
public List<EvidenceProvider> getEvidenceProviderListByIds(List<Integer> evidenceProviderIdListBW) { log.info("[evidenceProviderIdListBW: " + StringUtils.join(evidenceProviderIdListBW, ",") + "]"); List<EvidenceProvider> list = null; Session session = this.getSession(); if (evidenceProviderIdListBW != null && evidenceProviderIdListBW.size() > 0) { Criteria criteria = session.createCriteria(EvidenceProvider.class); criteria.add(Restrictions.in("id", evidenceProviderIdListBW)); list = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); }/* ww w .j a va 2 s .c o m*/ return list; }
From source file:com.scopix.periscope.evaluationmanagement.dao.EvaluationHibernateDAOImpl.java
License:Open Source License
@Override public Metric getMetricForAProcessId(Integer processId, Integer situationTemplateId, Integer metricTemplateId, Integer evidenceProviderId) { log.debug("start"); Metric metric = null;//from w w w .ja va 2 s. c o m Session session = this.getSession(); try { Criteria criteria = session.createCriteria(Metric.class); criteria.createCriteria("metricTemplate").add(Restrictions.eq("id", metricTemplateId)); Criteria situationCrit = criteria.createCriteria("situation"); situationCrit.add(Restrictions.eq("processId", processId)); situationCrit.createCriteria("situationTemplate").add(Restrictions.eq("id", situationTemplateId)); // createCriteria("extractionPlanCustomizing") Criteria epmCriteria = criteria.createCriteria("extractionPlanMetric"); epmCriteria.createCriteria("evidenceProviders").add(Restrictions.eq("id", evidenceProviderId)); List<Metric> metrics = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); if (metrics != null && !metrics.isEmpty()) { metric = metrics.get(0); } } catch (HibernateException e) { log.error(e, e); } finally { this.releaseSession(session); } log.debug("end"); return metric; }
From source file:com.scopix.periscope.evaluationmanagement.dao.ObservedMetricHibernateDAO.java
License:Open Source License
public List<ObservedMetric> getObservedMetricList(ObservedMetric observedMetric) { log.info("start"); registerLogs(observedMetric);/* w ww .java 2s .co m*/ Session session = this.getSession(); List<ObservedMetric> observedMetrics = null; try { Criteria criteria = session.createCriteria(ObservedMetric.class); criteria.addOrder(Order.asc("id")); if (observedMetric != null) { log.debug("observedMetric es diferente de null"); if (observedMetric.getEvaluationState() != null) { log.debug("evaluationState criteria: [" + observedMetric.getEvaluationState() + "]"); criteria.add(Restrictions.eq("evaluationState", observedMetric.getEvaluationState())); } if (observedMetric.getMetric() != null && observedMetric.getMetric().getId() != null) { log.debug("metricId criteria: [" + observedMetric.getMetric().getId() + "]"); criteria.add(Restrictions.eq("metric.id", observedMetric.getMetric().getId())); } if (observedMetric.getObservedMetricDate() != null) { log.debug("observedMetricDate criteria: [" + observedMetric.getObservedMetricDate() + "]"); criteria.add(Restrictions.eq("observedMetricDate", observedMetric.getObservedMetricDate())); } if (observedMetric.getObservedSituation() != null && observedMetric.getObservedSituation().getId() != null) { log.debug("observedSituationId criteria: [" + observedMetric.getObservedSituation().getId() + "]"); criteria.add( Restrictions.eq("observedSituation.id", observedMetric.getObservedSituation().getId())); } } log.debug("antes de listar observedMetrics"); observedMetrics = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); } catch (HibernateException e) { log.error(e, e); } finally { this.releaseSession(session); } log.info("end"); return observedMetrics; }
From source file:com.scopix.periscope.evaluationmanagement.dao.ObservedSituationHibernateDAOImpl.java
License:Open Source License
@Override public List<ObservedSituation> getObservedSituationList(ObservedSituation observedSituation) { Session session = this.getSession(); List<ObservedSituation> observedSituations = null; try {/*www . ja va 2 s . c o m*/ Criteria criteria = session.createCriteria(ObservedSituation.class); criteria.addOrder(Order.asc("id")); if (observedSituation != null) { if (observedSituation.getEvaluationState() != null) { criteria.add(Restrictions.eq("evaluationState", observedSituation.getEvaluationState())); } if (observedSituation.getSituation() != null && observedSituation.getSituation().getId() != null) { criteria.add(Restrictions.eq("situation.id", observedSituation.getSituation().getId())); } if (observedSituation.getObservedSituationDate() != null) { criteria.add( Restrictions.eq("observedSituationDate", observedSituation.getObservedSituationDate())); } } observedSituations = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); } catch (HibernateException e) { log.error(e, e); } finally { this.releaseSession(session); } return observedSituations; }
From source file:com.scopix.periscope.evaluationmanagement.dao.ObservedSituationHibernateDAOImpl.java
License:Open Source License
@Override public List<Formula> getFormulaList(Formula filter) { Session session = this.getSession(); List<Formula> formulas = null; try {//from w ww.j av a 2s .c o m Criteria criteria = session.createCriteria(Formula.class); criteria.addOrder(Order.asc("description")); if (filter != null) { if (filter.getDescription() != null && filter.getDescription().length() > 0) { criteria.add(Restrictions.ilike("description", filter.getDescription(), MatchMode.ANYWHERE)); } if (filter.getSituationTemplates() != null && !filter.getSituationTemplates().isEmpty()) { List<Integer> stIds = new ArrayList<Integer>(); for (SituationTemplate st : filter.getSituationTemplates()) { stIds.add(st.getId()); } criteria.createCriteria("situationTemplates").add(Restrictions.in("id", stIds)); } if (filter.getStores() != null && !filter.getStores().isEmpty()) { List<Integer> sIds = new ArrayList<Integer>(); for (Store s : filter.getStores()) { sIds.add(s.getId()); } criteria.createCriteria("stores").add(Restrictions.in("id", sIds)); } if (filter.getType() != null) { criteria.add(Restrictions.eq("type", filter.getType())); } if (filter.getCompliantType() != null) { criteria.add(Restrictions.eq("compliantType", filter.getCompliantType())); } } formulas = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); } catch (HibernateException e) { log.error(e, e); } finally { this.releaseSession(session); } return formulas; }