package com.baosight.rbac.dao.impl;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.baosight.rbac.model.PagerModel;
import com.baosight.rbac.utils.SystemContext;
import com.baosight.rbac.utils.SystemException;
public class AbstractManager extends HibernateDaoSupport {
public PagerModel searchPaginated(String hql){
return searchPaginated(hql, null);
}
public PagerModel searchPaginated(String hql,Object param){
return searchPaginated(hql, new Object[]{param});
}
public PagerModel searchPaginated(String hql,Object[] params){
return searchPaginated(hql, params,SystemContext.getOffset(), SystemContext.getPagesize());
}
public PagerModel searchPaginated(String hql,int offset,int pagesize){
return searchPaginated(hql,null, offset, pagesize);
}
public PagerModel searchPaginated(String hql,Object param,int offset,int pagesize){
return searchPaginated(hql, new Object[]{param}, offset, pagesize);
}
@SuppressWarnings("unchecked")
public PagerModel searchPaginated(String hql,Object[] params,int offset,int pagesize){
//获取记录总数
String countHql = getCountQuery(hql);
Query query = getSession().createQuery(countHql);
if(params != null && params.length > 0){
for(int i=0; i<params.length; i++){
query.setParameter(i, params[i]);
}
}
int total = ((Long)query.uniqueResult()).intValue();
//获取结果�?
query = getSession().createQuery(hql);
if(params != null && params.length > 0){
for(int i=0; i<params.length; i++){
query.setParameter(i, params[i]);
}
}
query.setFirstResult(offset);
query.setMaxResults(pagesize);
List datas = query.list();
//返回PagerModel
PagerModel pm = new PagerModel();
pm.setDatas(datas);
pm.setTotal(total);
return pm;
}
/**
* 根据HQL语句,获得查询�?记录数的HQL语句
* 如:
* select ... from Organization o where o.parent is null
* 经过转换,可以得到:
* select count(*) from Organziation o where o.parent is null
* @param hql
* @return
*/
private String getCountQuery(String hql){
int index = hql.indexOf("from");
if(index != -1){
return "select count(*) " + hql.substring(index);
}
throw new SystemException("无效的HQL查询语句�?+hql+");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Rights_management.rar (91个子文件)
Rights_management
script.sql 1KB
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.resources.prefs 136B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 330B
.project 1KB
WebRoot
css
dtree.css 795B
img
line.gif 66B
nolines_minus.gif 861B
globe.gif 1KB
imgfolder.gif 622B
folderopen.gif 376B
folder.gif 372B
trash.gif 1KB
minus.gif 86B
musicfolder.gif 633B
minusbottom.gif 85B
join.gif 69B
plusbottom.gif 88B
plus.gif 89B
question.gif 1KB
cd.gif 239B
page.gif 582B
base.gif 1KB
empty.gif 62B
joinbottom.gif 66B
nolines_plus.gif 870B
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 2KB
classes
log4j.properties 2KB
com
baosight
rbac
dao
ItemDao.class 231B
impl
ItemDaoImpl.class 820B
AbstractManager.class 3KB
filter
CharacterEncodingFilter.class 984B
model
Item.hbm.xml 604B
PagerModel.class 752B
Item.class 2KB
service
ItemService.class 243B
impl
ItemServiceImpl.class 782B
actions
ListMenus.class 1KB
utils
SystemException.class 2KB
SystemContext.class 1KB
struts.xml 470B
applicationContext-beans.xml 933B
applicationContext-actions.xml 775B
applicationContext-common.xml 2KB
lib
commons-collections-3.1.jar 546KB
dom4j-1.6.1.jar 307KB
spring.jar 2.81MB
mysql-connector-java-5.1.7-bin.jar 693KB
standard.jar 384KB
xwork-2.0.7.jar 449KB
struts2-spring-plugin-2.0.14.jar 9KB
ognl-2.6.11.jar 164KB
jstl.jar 20KB
commons-logging.jar 59KB
aspectjweaver.jar 1.47MB
aspectjrt.jar 112KB
slf4j-api-1.5.2.jar 17KB
javassist-3.4.GA.jar 460KB
slf4j-log4j12-1.5.2.jar 9KB
log4j-1.2.15.jar 383KB
freemarker-2.3.8.jar 784KB
struts2-core-2.0.14.jar 2.22MB
jta-1.1.jar 13KB
antlr-2.7.6.jar 433KB
c3p0-0.9.1.jar 594KB
hibernate3.jar 2.64MB
js
dtree.js 12KB
tree.jsp 889B
index.jsp 81B
.mymetadata 324B
.classpath 2KB
.myeclipse
core_src
log4j.properties 2KB
com
baosight
rbac
dao
ItemDao.java 167B
impl
AbstractManager.java 2KB
ItemDaoImpl.java 424B
filter
CharacterEncodingFilter.java 602B
model
Item.hbm.xml 604B
PagerModel.java 459B
Item.java 1KB
service
ItemService.java 175B
impl
ItemServiceImpl.java 437B
actions
ListMenus.java 604B
utils
SystemContext.java 891B
SystemException.java 945B
struts.xml 470B
applicationContext-beans.xml 933B
applicationContext-actions.xml 775B
applicationContext-common.xml 2KB
共 91 条
- 1
ahut0316
- 粉丝: 3
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页