@Override public <T> List<T> find( Class<T> clazz, Query query, int firstResult, int maxResults, HibernateParameter... parameters) { Query q = HibernateTool.setParameters(query, parameters); return (List<T>) HibernateTool.setPaging(q, firstResult, maxResults).list(); }
@Override public <T> List<T> findAll(Class<T> clazz, int firstResult, int maxResults, Order... orders) { Criteria criteria = getSession().createCriteria(clazz); if (orders == null || orders.length == 0) { return (List<T>) HibernateTool.setPaging(criteria, firstResult, maxResults).list(); } else { criteria = HibernateTool.addOrders(criteria, orders); criteria = HibernateTool.setPaging(criteria, firstResult, maxResults); return (List<T>) criteria.list(); } }
@Override public <P> Page<P> reportPage( Class<P> projectClass, ProjectionList projectionList, Criteria criteria, Pageable pageable) { Criteria report = buildProjectionCriteria(projectClass, criteria, projectionList, false); long totalCount = count(report); List<P> items = HibernateTool.setPaging(report, pageable).list(); return new PageImpl<P>(items, pageable, totalCount); }
@Override public long count(Query query, HibernateParameter... parameters) { return (Long) HibernateTool.setParameters(query, parameters) .setResultTransformer(CriteriaSpecification.PROJECTION) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) .uniqueResult(); }
@Override public <T> List<T> findAll(Class<T> clazz, Order... orders) { if (orders == null || orders.length == 0) { return (List<T>) getSession().createCriteria(clazz).list(); } else { Criteria criteria = getSession().createCriteria(clazz); return (List<T>) HibernateTool.addOrders(criteria, orders).list(); } }
@Override public <P> List<P> reportList( Class<P> projectClass, ProjectionList projectionList, Criteria criteria, int firstResult, int maxResults) { Criteria report = buildProjectionCriteria(projectClass, criteria, projectionList, false); return (List<P>) HibernateTool.setPaging(report, firstResult, maxResults).list(); }
@Override public <T> Page<T> getPage(Class<T> clazz, Criteria criteria, Pageable pageable) { Criteria countCriteria = HibernateTool.copyCriteria(criteria); long totalItemCount = count(countCriteria); List<T> items = find( clazz, criteria, pageable.getPageNumber() * pageable.getPageSize(), pageable.getPageSize(), CriteriaTool.toOrders(pageable.getSort()).toArray(new Order[0])); return new PageImpl<T>(items, pageable, totalItemCount); }
@Override public int executeUpdate(Query query, HibernateParameter... parameters) { return HibernateTool.setParameters(query, parameters).executeUpdate(); }
@Override public <T> T findUnique(Class<T> clazz, Query query, HibernateParameter... parameters) { return (T) HibernateTool.setParameters(query, parameters).uniqueResult(); }
@Override public <T> List<T> find(Class<T> clazz, Query query, HibernateParameter... parameters) { return (List<T>) HibernateTool.setParameters(query, parameters).list(); }
@Override public <T> List<T> find( Class<T> clazz, Criteria criteria, int firstResult, int maxResults, Order... orders) { Criteria cri = HibernateTool.addOrders(criteria, orders); return (List<T>) HibernateTool.setPaging(cri, firstResult, maxResults).list(); }
@Override public <T> List<T> find(Class<T> clazz, Criteria criteria, Order... orders) { return (List<T>) HibernateTool.addOrders(criteria, orders).list(); }
@Override public ScrollableResults scroll( Query query, ScrollMode scrollMode, HibernateParameter... parameters) { return HibernateTool.setParameters(query, parameters).scroll(scrollMode); }