예제 #1
0
 public Pager<T> find(String hql, Object[] args, Map<String, Object> alias) {
   hql = initSort(hql);
   String cq = getCountHql(hql, true);
   Query cquery = getSession().createQuery(cq);
   Query query = getSession().createQuery(hql);
   // 设置别名参数
   setAliasParameter(query, alias);
   setAliasParameter(cquery, alias);
   // 设置参数
   setParameter(query, args);
   setParameter(cquery, args);
   Pager<T> pages = new Pager<T>();
   setPagers(query, pages);
   List<T> datas = query.list();
   pages.setRows(datas);
   long total = (Long) cquery.uniqueResult();
   pages.setTotal(total);
   return pages;
 }
예제 #2
0
 public <N extends Object> Pager<N> findBySql(
     String sql, Object[] args, Map<String, Object> alias, Class<?> clz, boolean hasEntity) {
   sql = initSort(sql);
   String cq = getCountHql(sql, false);
   SQLQuery sq = getSession().createSQLQuery(sql);
   SQLQuery cquery = getSession().createSQLQuery(cq);
   setAliasParameter(sq, alias);
   setAliasParameter(cquery, alias);
   setParameter(sq, args);
   setParameter(cquery, args);
   Pager<N> pages = new Pager<N>();
   setPagers(sq, pages);
   if (hasEntity) {
     sq.addEntity(clz);
   } else {
     sq.setResultTransformer(Transformers.aliasToBean(clz));
   }
   List<N> datas = sq.list();
   pages.setRows(datas);
   long total = ((BigInteger) cquery.uniqueResult()).longValue();
   pages.setTotal(total);
   return pages;
 }