コード例 #1
0
 private Query createQueryParam(String _jpql, List<SqlQueryItem> _paramList, Pageable _pageable) {
   Query query = manager.createQuery(_jpql);
   if (_pageable != null) {
     int maxResult = _pageable.getPageSize();
     query.setFirstResult(_pageable.getPageNumber() * _pageable.getPageSize());
     query.setMaxResults(maxResult);
   }
   if (_paramList != null) {
     for (SqlQueryItem param : _paramList) {
       Object value = param.getValue();
       if (param.getAction() == SqlActionType.LIKE) {
         String val = param.getValue().toString().trim();
         if (!val.startsWith("%")) {
           val = "%" + val;
         }
         if (!val.endsWith("%")) {
           val = val + "%";
         }
         value = val;
       }
       query.setParameter(param.getPropertyName().replace(".", ""), value);
     }
   }
   return query;
 }
コード例 #2
0
 protected String getFilter(List<SqlQueryItem> _paramList) {
   if (_paramList == null || _paramList.size() == 0) {
     return "";
   }
   String result = "where ";
   for (SqlQueryItem item : _paramList) {
     result =
         result
             + String.format(
                 "t.%s %s :%s and ",
                 new Object[] {
                   item.getPropertyName(),
                   item.getAction().getAction(),
                   item.getPropertyName().replace(".", "")
                 });
   }
   result = result.substring(0, result.length() - 5);
   return result;
 }