List of usage examples for org.hibernate.criterion CriteriaSpecification ROOT_ENTITY
ResultTransformer ROOT_ENTITY
To view the source code for org.hibernate.criterion CriteriaSpecification ROOT_ENTITY.
Click Source Link
From source file:com.lighting.platform.base.dao.HibernateDao.java
License:Apache License
/** * countCriteria.//from w ww . j a v a 2s. c om */ protected long countCriteriaResult(final Criteria c) { org.hibernate.internal.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.npower.dm.hibernate.management.PaginatedResultImpl4Criteria.java
License:Open Source License
protected void load() { // http://www.blogjava.net/iamtin/archive/2006/06/06/50702.aspx // ProjectionOrderBy,Count CriteriaImpl impl = (CriteriaImpl) this.criteria; Projection projection = impl.getProjection(); List<OrderEntry> orderEntries; try {/* www . java 2s. c o m*/ orderEntries = (List<OrderEntry>) BeanHelper.getPrivateProperty(impl, "orderEntries"); BeanHelper.setPrivateProperty(impl, "orderEntries", new ArrayList<OrderEntry>()); } catch (Exception e) { throw new InternalError(" Runtime Exception impossibility throw "); } // Execute and get query for counting. Projection project4Count = Projections.rowCount(); this.fullListSize = (Integer) criteria.setProjection(project4Count).uniqueResult(); // ProjectionOrderBy criteria.setProjection(projection); if (projection == null) { criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); // DISTINCT_ROOT_ENTITY, // DISTINCT_ROOT_ENTITY , , . //criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); } try { BeanHelper.setPrivateProperty(impl, "orderEntries", orderEntries); } catch (Exception e) { throw new InternalError("Runtime Exception impossibility throw "); } int firstResult = this.getObjectsPerPage() * (this.getPageNumber() - 1); criteria.setFirstResult(firstResult); criteria.setMaxResults(this.getObjectsPerPage()); this.results = criteria.list(); // Load Records // criteria.setProjection(null); // int firstResult = this.getObjectsPerPage() * (this.getPageNumber() - 1); // criteria.setFirstResult(firstResult); // criteria.setMaxResults(this.getObjectsPerPage()); // this.results = criteria.list(); // Countting records // criteria.setProjection(Projections.rowCount()); // // criteria.setFirstResult(0); // criteria.setMaxResults(Integer.MAX_VALUE); // this.fullListSize = ((Integer)criteria.list().get(0)).intValue(); }
From source file:com.project.framework.dao.BaseDao.java
License:Apache License
/** * countCriteria./* ww w . j av a 2 s .c om*/ */ 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 . java2 s .c om */ @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.rosy.bill.dao.hibernate.HibernateDao.java
License:Apache License
/** * countCriteria./* w w w . j av a 2s.com*/ */ @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<OrderEntry>) ReflectionUtils.getFieldValue(impl, "orderEntries"); ReflectionUtils.setFieldValue(impl, "orderEntries", new ArrayList<T>()); } 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.sailing.hrm.persistent.base.HibernateDao.java
License:Apache License
/** * countCriteria./*from w ww. ja 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); } // 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.scopix.periscope.periscopefoundation.persistence.paging.PagedDetachedCriteria.java
License:Open Source License
/** * This method does the query and returns a Page object which has the paged * result./*w w w .j av a 2s . co m*/ * @param hibernateTemplate HibernateTemplate asociado * @return Page para un hibernateTemplate dado */ public Page listPage(HibernateTemplate hibernateTemplate) { List resultadoPaginado; Integer total = 0; if (this.pageData != null) { this.setProjection(Projections.rowCount()); List<Integer> resultadoProyeccion = hibernateTemplate.findByCriteria(this, 0, Integer.MAX_VALUE); if (resultadoProyeccion != null) { for (Integer integer : resultadoProyeccion) { total += integer; } } this.setProjection(null); this.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); this.addOrder(this.order); resultadoPaginado = hibernateTemplate.findByCriteria(this, this.pageData.getFirstResult() - 1, this.pageData.getMaxResults()); } else { resultadoPaginado = hibernateTemplate.findByCriteria(this); total = resultadoPaginado.size(); } Page page = new Page(); page.setElements(resultadoPaginado); page.setTotalElements(total); return page; }
From source file:com.thinkmore.framework.orm.hibernate.HibernateDao.java
License:Apache License
/** * countCriteria.//from w ww . j av a 2s. c o m */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected int 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) ReflectionUtil.getFieldValue(impl, "orderEntries"); ReflectionUtil.setFieldValue(impl, "orderEntries", new ArrayList()); } catch (Exception e) { logger.error("??:{}", e.getMessage()); } // Count int totalCount = (Integer) c.setProjection(Projections.rowCount()).uniqueResult(); // ?Projection,ResultTransformerOrderBy?? c.setProjection(projection); if (projection == null) { c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); } if (transformer != null) { c.setResultTransformer(transformer); } try { ReflectionUtil.setFieldValue(impl, "orderEntries", orderEntries); } catch (Exception e) { logger.error("??:{}", e.getMessage()); } return totalCount; }
From source file:com.wonders.bud.freshmommy.service.content.dao.impl.ContentDaoImpl.java
License:Open Source License
@Override public Page<ContentPO> findByPageCustom(Page<ContentPO> page, String orQuery) { Criteria c = createCriteria();/*ww w .j av a 2 s .c o m*/ if (page.getParam() != null) { c = page.getParam().andCriteria(c); } if (orQuery != null) { Criterion cTitle = Restrictions.like("title", "%" + orQuery + "%"); Criterion cShortTitle = Restrictions.like("shortTitle", "%" + orQuery + "%"); LogicalExpression orExp1 = Restrictions.or(cTitle, cShortTitle); Criterion cTxt = Restrictions.like("txt", "%" + orQuery + "%"); LogicalExpression orExp = Restrictions.or(orExp1, cTxt); c.add(orExp); } c.setProjection(null); // ?? int totalCount = ((Long) c.setProjection(Projections.rowCount()).uniqueResult()).intValue(); c.setProjection(null); c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); // page if (page.getStart() > -1) { c.setFirstResult(page.getStart()); } if (page.getPagesize() > -1) { c.setMaxResults(page.getPagesize()); } List<ContentPO> result = c.list(); getSession().clear(); page.setResult(result); page.setTotal(totalCount); return page; }
From source file:com.xbwl.common.orm.hibernate.HibernateDao.java
License:Apache License
/** * countCriteria./*from w w w .j av a2 s.co m*/ */ @SuppressWarnings("unchecked") protected int countCriteriaResult(final Criteria c) { CriteriaImpl impl = (CriteriaImpl) c; // ProjectionResultTransformerOrderBy,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 int totalCount = (Integer) c.setProjection(Projections.rowCount()).uniqueResult(); // 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; }