List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:com.project.framework.dao.BaseDao.java
License:Apache License
/** * countCriteria./* w w w. j av a 2s. c o m*/ */ public int countResult(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<OrderEntry>) ReflectionUtils.getFieldValue(impl, "orderEntries"); ReflectionUtils.setFieldValue(impl, "orderEntries", new ArrayList<Object>()); } catch (Exception e) { logger.error("??:{}", e.getMessage()); } // Count int totalCount = Integer.parseInt(c.setProjection(Projections.rowCount()).uniqueResult().toString()); // ?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.getMessage()); } return totalCount; }
From source file:com.proper.uip.common.core.dao.HibernateDao.java
License:Apache License
/** * countCriteria.//from w w w. j a va2 s . 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.getMessage()); } // 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.getMessage()); } return totalCount; }
From source file:com.puertobahia.iceberg.dao.impl.ZonaDAOImpl.java
@Override public Zona getById(Long id) { Criteria crit = getSession().createCriteria(Zona.class); crit.add(Restrictions.idEq(id));//from w ww.j a va 2s. c o m crit.setFetchMode("usuario", FetchMode.JOIN); crit.setFetchMode("usuario.empleado", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.setFetchMode("consejos_comunitario", FetchMode.JOIN); crit.createAlias("consejos_comunitario", "consejo", JoinType.LEFT_OUTER_JOIN); crit.add(Restrictions.or(Restrictions.and(Restrictions.eq("consejo.estado", 0)), Restrictions.isNull("consejo.estado"))); return (Zona) crit.uniqueResult(); /*Criteria crit = getSession().createCriteria(Zona.class); crit.add(Restrictions.idEq(id)); crit.setFetchMode("usuario", FetchMode.JOIN); crit.setFetchMode("usuario.empleado", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Zona zona = (Zona) crit.uniqueResult(); Criteria crit2 = getSession().createCriteria(ConsejoComunitario.class); zona.setConsejos_comunitario(crit2.add(Restrictions.and(Restrictions.idEq(zona.getId()),Restrictions.eq("estado", 0))).list()); return zona;*/ }
From source file:com.qfix.vms.dao.impl.AccidentsDaoImpl.java
@Override public List<Accidents> findAllAccidents() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Accidents> accidents = (List<Accidents>) criteria.list(); return accidents; }
From source file:com.qfix.vms.dao.impl.AnnualLicenseDaoImpl.java
@Override public List<AnnualLicense> findAllAnnualLicenses() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<AnnualLicense> annualLicenses = (List<AnnualLicense>) criteria.list(); return annualLicenses; }
From source file:com.qfix.vms.dao.impl.DriverDaoImpl.java
@SuppressWarnings("unchecked") @Override// w ww . jav a 2s .c om public List<Driver> findAllDrivers() { Criteria criteria = createEntityCriteria().addOrder(Order.asc("name")); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Driver> drivers = (List<Driver>) criteria.list(); return drivers; }
From source file:com.qfix.vms.dao.impl.PaymentsDaoImpl.java
@Override public List<Payments> findAllPayments() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Payments> payments = (List<Payments>) criteria.list(); return payments; }
From source file:com.qfix.vms.dao.impl.RepairDaoImpl.java
@Override public List<Repair> findAllRepairs() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Repair> repairs = (List<Repair>) criteria.list(); return repairs; }
From source file:com.qfix.vms.dao.impl.SurvicingDaoImpl.java
@Override public List<Survicing> findAllSurvicings() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Survicing> survicings = (List<Survicing>) criteria.list(); return survicings; }
From source file:com.qfix.vms.dao.impl.ToolsDaoImpl.java
@Override public List<Tools> findAllTools() { Criteria criteria = createEntityCriteria().addOrder(Order.asc("ID")); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Tools> tools = (List<Tools>) criteria.list(); return tools; }