コード例 #1
0
 @SuppressWarnings("unchecked")
 public Page<T> findPage(String qlString, List<Object> parameter, Pageable pageable) {
   if (pageable == null) pageable = new Pageable();
   StringBuilder stringBuilder = new StringBuilder(qlString);
   addFilter(stringBuilder, pageable, parameter);
   addOrders(stringBuilder, pageable, parameter);
   qlString = stringBuilder.toString();
   if (qlString.indexOf("order by") == -1) {
     if (OrderEntity.class.isAssignableFrom(this.entityClass)) {
       qlString += "order by order ASC";
     } else {
       qlString += "order by createDate DESC";
     }
   }
   long count = count(stringBuilder, null, parameter);
   int i = (int) Math.ceil((double) count / pageable.getPageSize());
   if (i < pageable.getPageNumber()) {
     pageable.setPageNumber(i);
   }
   System.out.println("query=" + qlString);
   for (Object object : parameter) {
     System.out.println("object=" + object);
   }
   Query query = createQuery(qlString, parameter.toArray());
   query.setFirstResult((pageable.getPageNumber() - 1) * pageable.getPageSize());
   query.setMaxResults(pageable.getPageSize());
   List<Object> list = query.list();
   if (list.size() > 0) {
     return new Page<T>(query.list(), count, pageable);
   }
   List<T> listTemp = new ArrayList<T>();
   return new Page<T>(listTemp, count, pageable);
 }
コード例 #2
0
 @SuppressWarnings("unchecked")
 public List<T> findList(
     String qlString,
     List<Object> parameter,
     Integer first,
     Integer count,
     List<Filter> filters,
     List<Order> orders) {
   StringBuilder stringBuilder = new StringBuilder(qlString);
   addFilter(stringBuilder, filters, parameter);
   addOrders(stringBuilder, orders, parameter);
   qlString = stringBuilder.toString();
   if (qlString.indexOf("order by") == -1) {
     if (OrderEntity.class.isAssignableFrom(this.entityClass)) {
       qlString += "order by order ASC";
     } else {
       qlString += "order by createDate DESC";
     }
   }
   System.out.println("productQuery = " + qlString);
   System.out.println(parameter.size());
   for (Object object : parameter) {
     System.out.println("object=" + object);
   }
   Query query = createQuery(qlString, parameter.toArray());
   if (first != null) {
     query.setFirstResult(first);
   }
   if (count != null) {
     query.setMaxResults(count);
   }
   return query.list();
 }