Java Code Examples for org.hibernate.criterion.DetachedCriteria#getExecutableCriteria()

The following examples show how to use org.hibernate.criterion.DetachedCriteria#getExecutableCriteria() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericBaseCommonDao.java    From jeewx with Apache License 2.0 5 votes vote down vote up
public <T> List<T> pageList(DetachedCriteria dc, int firstResult,
		int maxResult) {
	Criteria criteria = dc.getExecutableCriteria(getSession());
	criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
	criteria.setFirstResult(firstResult);
	criteria.setMaxResults(maxResult);
	return criteria.list();
}
 
Example 2
Source File: BaseHibernateDao.java    From framework with Apache License 2.0 5 votes vote down vote up
/**
 * Description: <br>
 * 
 * @author 王伟<br>
 * @taskId <br>
 * @param detachedCriteria
 * @param pi
 * @param pageSize
 * @param <T> T
 * @return T
 * @throws DaoException <br>
 */
@Override
public <T> PagerList<T> getPageList(final DetachedCriteria detachedCriteria, final int pi, final int pageSize)
    throws DaoException {
    int pageIndex = pi;
    if (pi == 0) {
        pageIndex = 1;
    }

    Criteria criteria = detachedCriteria.getExecutableCriteria(getSession());

    // 查询分页总数
    CriteriaImpl impl = (CriteriaImpl) criteria;
    Projection projection = impl.getProjection();
    Long allCounts = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();

    criteria.setProjection(projection);
    criteria.setFirstResult((pageIndex - 1) * pageSize);
    criteria.setMaxResults(pageSize);

    PagerList<T> resultList = new PagerList<T>();
    resultList.setPageIndex(pageIndex);
    resultList.setPageSize(pageSize);
    if (allCounts == null) {
        allCounts = 0L;
    }
    resultList.setTotalCount(allCounts);

    if (allCounts > 0) {
        resultList.addAll(criteria.list());
    }
    return resultList;
}
 
Example 3
Source File: HibernateDao.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings ("unchecked")
public List<T> listCriteria (DetachedCriteria detached, int skip, int top)
{
   SessionFactory factory = getSessionFactory ();
   org.hibernate.classic.Session session = factory.getCurrentSession ();

   Criteria criteria = detached.getExecutableCriteria (session);

   if (skip > 0)
      criteria.setFirstResult (skip);
   if (top > 0)
      criteria.setMaxResults (top);
   return criteria.list ();
}
 
Example 4
Source File: HibernateDao.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
public int count (DetachedCriteria detached)
{
   Session session = getSessionFactory ().getCurrentSession ();
   Criteria criteria = detached.getExecutableCriteria (session);
   Object result = criteria.uniqueResult ();
   return ((Number) result).intValue ();
}
 
Example 5
Source File: BaseServiceImpl.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
/**
 * 计算总页数(入参为detachedCriteria)
 *
 * @param dCriteria
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public int countTotalPage(DetachedCriteria dCriteria, int pageSize) {
    Criteria criteria = dCriteria.getExecutableCriteria(getCurrentSession());
    int totalRecord = ((Long) criteria
            .setProjection(Projections.rowCount()).uniqueResult())
            .intValue();
    criteria.setProjection(null);
    int totalPage = (int) Math.ceil(((double) totalRecord / pageSize));
    return totalPage;
}
 
Example 6
Source File: BaseServiceImpl.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public int countNum(DetachedCriteria dCriteria) {
    Criteria criteria = dCriteria
            .getExecutableCriteria(getCurrentSession());
    int num = ((Long) criteria
            .setProjection(Projections.rowCount()).uniqueResult())
            .intValue();
    return num;
}
 
Example 7
Source File: BaseServiceImpl.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public List<?> getByPage(DetachedCriteria dCriteria, int pageSize) {

    int curPage = PageHelper.getCurPage();
    Criteria criteria = dCriteria.getExecutableCriteria(getCurrentSession());
    criteria.setFirstResult((curPage - 1) * pageSize);
    criteria.setMaxResults(pageSize);
    List<?> list = criteria.list();
    return list;
}
 
Example 8
Source File: BaseServiceImpl.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public <T> List<T> queryAllOfCondition(Class<T> clazz, DetachedCriteria dCriteria) {
    Criteria criteria = dCriteria.getExecutableCriteria(getCurrentSession());
    List<T> list = criteria.list();
    return list;
}
 
Example 9
Source File: BaseServiceImpl.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public <T> List<T> queryMaxNumOfCondition(Class<T> clazz, DetachedCriteria dCriteria, int num) {
    Criteria criteria = dCriteria.getExecutableCriteria(getCurrentSession());
    List<T> list = criteria.setMaxResults(num).list();
    return list;
}
 
Example 10
Source File: GenericBaseCommonDao.java    From jeecg with Apache License 2.0 5 votes vote down vote up
public <T> List<T> pageList(DetachedCriteria dc, int firstResult,
		int maxResult) {
	Criteria criteria = dc.getExecutableCriteria(getSession());
	criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
	criteria.setFirstResult(firstResult);
	criteria.setMaxResults(maxResult);
	return criteria.list();
}