use of com.netsteadfast.greenstep.base.model.QueryResult in project bamboobsc by billchen198318.
the class HessianServiceProxyAspect method setReCalculateSizePageOfForPageFindGridResult.
/**
* 給 GridPage 查詢返回後處理
* 如果 hessian 遠端呼叫有啟用時, 要重新調用 PageOf.setCountSize 與 PageOf.toCalculateSize
* 因為帶入遠端 Service 的 PageOf 並沒有回傳, 遠端只有回傳 QueryResult
*
* @param queryResult
* @param pageOf
*/
private void setReCalculateSizePageOfForPageFindGridResult(Object resultObj, Object[] params) {
if (null == resultObj || !(resultObj instanceof QueryResult)) {
return;
}
if (params == null || params.length < 1) {
return;
}
PageOf pageOf = null;
for (int i = 0; i < params.length && pageOf == null; i++) {
if (params[i] instanceof PageOf) {
pageOf = (PageOf) params[i];
}
}
if (null == pageOf) {
return;
}
QueryResult<?> result = (QueryResult<?>) resultObj;
pageOf.setCountSize(String.valueOf(result.getRowCount()));
pageOf.toCalculateSize();
}
use of com.netsteadfast.greenstep.base.model.QueryResult in project bamboobsc by billchen198318.
the class BaseDAO method findPageQueryResult.
/**
* 頁面查詢grid資料用
*
* map 放入 key為 persisent obj 欄位名稱
*
*/
@SuppressWarnings("unchecked")
public <RO extends QueryResult<List<VO>>, VO extends java.io.Serializable> QueryResult<List<VO>> findPageQueryResult(String findHQL, String countHQL, Map<String, Object> params, int offset, int limit) throws Exception {
QueryResult<List<VO>> result = new QueryResult<List<VO>>();
List<VO> list = null;
long count = 0L;
Session hbmSession = this.getCurrentSession();
try {
Query query = hbmSession.createQuery(countHQL);
if (params != null) {
for (Map.Entry<String, Object> entry : params.entrySet()) {
if (entry.getKey().equals(Constants._RESERVED_PARAM_NAME_QUERY_ORDER_BY) || entry.getKey().equals(Constants._RESERVED_PARAM_NAME_QUERY_SORT_TYPE)) {
continue;
}
this.setQueryParams(query, entry.getKey(), entry.getValue());
}
}
count = ((Long) query.uniqueResult()).longValue();
int newOffset = offset;
if (count > 0) {
if (offset >= count) {
// 改掉原本頁面上一次查詢的欄位值 , 2014-10-08 offset>count
newOffset = (int) (count - Long.valueOf(limit));
if (newOffset < 0) {
newOffset = 0;
}
}
query = hbmSession.createQuery(findHQL);
if (params != null) {
for (Map.Entry<String, Object> entry : params.entrySet()) {
if (entry.getKey().equals(Constants._RESERVED_PARAM_NAME_QUERY_ORDER_BY) || entry.getKey().equals(Constants._RESERVED_PARAM_NAME_QUERY_SORT_TYPE)) {
continue;
}
this.setQueryParams(query, entry.getKey(), entry.getValue());
}
}
//offset
query.setFirstResult(newOffset);
query.setMaxResults(limit);
list = (List<VO>) query.list();
}
result.setRowCount(count);
// 2017-06-30 bug fix, result.setOffset(offset);
result.setOffset(newOffset);
result.setLimit(limit);
result.setFindHQL(findHQL);
result.setCountHQL(countHQL);
if (list != null && list.size() > 0) {
result.setValue(list);
} else {
result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA)));
}
} catch (Exception e) {
e.printStackTrace();
result.setSystemMessage(new SystemMessage(e.getMessage()));
}
return result;
}
Aggregations