package com.foxconn.dao;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.foxconn.bean.Tcustomer;
public class TcustomerDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(TcustomerDAO.class);
// property constants
public static final String CUSTOMERNAME = "customername";
public static final String PWD = "pwd";
public static final String LOGINNAME = "loginname";
public static final String BIRTHDAY = "birthday";
protected void initDao() {
// do nothing
}
public void save(Tcustomer transientInstance) {
log.debug("saving Tcustomer instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Tcustomer persistentInstance) {
log.debug("deleting Tcustomer instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Tcustomer findById(java.lang.Integer id) {
log.debug("getting Tcustomer instance with id: " + id);
try {
Tcustomer instance = (Tcustomer) getHibernateTemplate().get(
"com.foxconn.bean.Tcustomer", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Tcustomer instance) {
log.debug("finding Tcustomer instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Tcustomer instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Tcustomer as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByCustomername(Object customername) {
return findByProperty(CUSTOMERNAME, customername);
}
public List findByPwd(Object pwd) {
return findByProperty(PWD, pwd);
}
public List findByLoginname(Object loginname) {
return findByProperty(LOGINNAME, loginname);
}
public List findByBirthday(Object birthday) {
return findByProperty(BIRTHDAY, birthday);
}
public List findAll() {
log.debug("finding all Tcustomer instances");
try {
String queryString = "from Tcustomer";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Tcustomer merge(Tcustomer detachedInstance) {
log.debug("merging Tcustomer instance");
try {
Tcustomer result = (Tcustomer) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Tcustomer instance) {
log.debug("attaching dirty Tcustomer instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Tcustomer instance) {
log.debug("attaching clean Tcustomer instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static TcustomerDAO getFromApplicationContext(ApplicationContext ctx) {
return (TcustomerDAO) ctx.getBean("TcustomerDAO");
}
@SuppressWarnings("unchecked")
public int getUserTotalCount(String customerName){
String hql= "select count(*) from Tcustomer where 1=1";
if ( customerName !=null){
hql += "and customerName like :customerName";
}
Session session = this.getHibernateTemplate().getSessionFactory().openSession();
Query q = session.createQuery(hql);
if ( customerName !=null){
q.setString("customerName", "%"+customerName+"%");
}
List l = q.list();
Integer i = (Integer)l.get(0);
return i;
}
public int getTotalPage(int pageSize ,String customerName){
int totalCount = this.getUserTotalCount(customerName);
int totalPageCount = (totalCount+pageSize-1)/pageSize;
return totalPageCount;
}
@SuppressWarnings("unchecked")
public List findPageAll(int currentPage,int pageSize,Tcustomer instance){
log.debug("分页查找");
try {
if (currentPage == 0){
currentPage =1;}
Criteria criteria = this.getSession().createCriteria(Tcustomer.class);
Example example = Example.create(instance);
if (instance.getCustomername()!= null){
criteria.add(Restrictions.ilike("customerName", instance.getCustomername(),MatchMode.ANYWHERE));
}
criteria.setFirstResult((currentPage-1)*pageSize);
criteria.setMaxResults(pageSize);
return criteria.list();
}catch(RuntimeException re){
log.error("find all failed",re);
throw re;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
一个ssh分页的源代码
共44个文件
class:10个
java:9个
tld:7个
4星 · 超过85%的资源 需积分: 3 203 下载量 37 浏览量
2008-09-07
20:12:31
上传
评论
收藏 39KB RAR 举报
温馨提示
一个ssh分页的源代码,源文件较大,把lib下的jar去掉了
资源推荐
资源详情
资源评论
收起资源包目录
basicSSH.rar (44个子文件)
basicSSH
.project 2KB
.mymetadata 297B
WebRoot
listMyUsers.jsp 3KB
WEB-INF
struts-tiles.tld 8KB
.struts-config.mex 1KB
web.xml 1KB
struts-config.xml 1KB
struts-bean.tld 9KB
spring-form.tld 51KB
struts-nested.tld 70KB
applicationContext.xml 2KB
struts-html.tld 72KB
spring.tld 13KB
struts-logic.tld 14KB
validator-rules.xml 13KB
lib
classes
other
Change.class 775B
com
foxcon
util
MyUserPage.class 2KB
Page.class 2KB
PageUtil.class 2KB
MyUserPage$1.class 1KB
foxconn
bean
Tcustomer.hbm.xml 1KB
Tcustomer.class 2KB
dao
TcustomerDAO.class 8KB
struts
action
SpringAction.class 726B
ListMyUsersAction.class 2KB
form
ListMyUsersForm.class 824B
ApplicationResources.properties 87B
index.jsp 834B
META-INF
MANIFEST.MF 39B
.myeclipse
src
other
Change.java 289B
com
foxcon
util
PageUtil.java 2KB
MyUserPage.java 1KB
Page.java 2KB
foxconn
bean
Tcustomer.java 1KB
Tcustomer.hbm.xml 1KB
dao
TcustomerDAO.java 6KB
struts
action
ListMyUsersAction.java 2KB
SpringAction.java 303B
form
ListMyUsersForm.java 969B
ApplicationResources.properties 87B
.mystrutsdata 258B
.springBeans 332B
.classpath 6KB
.myhibernatedata 522B
共 44 条
- 1
资源评论
- outsiderqhl2011-12-19这是Struts1的吗,我把jar包导进去会报错啊
jiunizhuai
- 粉丝: 9
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功