package dao;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* Data access object (DAO) for domain model class User.
*
* @see dao.User
* @author MyEclipse Persistence Tools
*/
public class UserDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(UserDAO.class);
// property constants
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String AGE = "age";
protected void initDao() {
// do nothing
}
public void save(User transientInstance) {
log.debug("saving User instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(User persistentInstance) {
log.debug("deleting User instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public User findById(java.lang.Integer id) {
log.debug("getting User instance with id: " + id);
try {
User instance = (User) getHibernateTemplate().get("dao.User", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(User instance) {
log.debug("finding User 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 User instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from User 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 findByUsername(Object username) {
return findByProperty(USERNAME, username);
}
public List findByPassword(Object password) {
return findByProperty(PASSWORD, password);
}
public List findByAge(Object age) {
return findByProperty(AGE, age);
}
public List findAll() {
log.debug("finding all User instances");
try {
String queryString = "from User";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public User merge(User detachedInstance) {
log.debug("merging User instance");
try {
User result = (User) getHibernateTemplate().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(User instance) {
log.debug("attaching dirty User instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(User instance) {
log.debug("attaching clean User instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static UserDAO getFromApplicationContext(ApplicationContext ctx) {
return (UserDAO) ctx.getBean("UserDAO");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Spring + Struts + Hibernate 的完整 MyEclipse 项目源码
共44个文件
xml:9个
jar:9个
tld:7个
4星 · 超过85%的资源 需积分: 10 120 下载量 183 浏览量
2008-10-08
18:25:41
上传
评论 4
收藏 1.56MB ZIP 举报
温馨提示
Spring + Struts + Hibernate 的完整 MyEclipse 项目源码
资源推荐
资源详情
资源评论
收起资源包目录
Spring+++Struts+++Hibernate+的完整+MyEclipse+项目源码.zip (44个子文件)
ssh
.mystrutsdata 262B
.springBeans 320B
.myhibernatedata 474B
createTable.sql 350B
src
dao
User.hbm.xml 927B
User.java 1KB
UserDAO.java 4KB
log4j.properties 547B
com
yourcompany
struts
ApplicationResources.properties 86B
action
RegisterAction.java 1KB
hibernate.cfg.xml 829B
applicationContext.xml 2KB
.project 2KB
WebRoot
META-INF
MANIFEST.MF 39B
WEB-INF
struts-nested.tld 70KB
validator-rules.xml 13KB
struts-bean.tld 9KB
struts-html.tld 72KB
struts-logic.tld 14KB
struts-tiles.tld 8KB
web.xml 1KB
.struts-config.mex 489B
classes
dao
User.hbm.xml 927B
User.class 2KB
UserDAO.class 5KB
com
yourcompany
struts
ApplicationResources.properties 86B
action
RegisterAction.class 2KB
hibernate.cfg.xml 829B
applicationContext.xml 2KB
struts-config.xml 788B
lib
commons-beanutils.jar 160KB
jakarta-oro.jar 62KB
commons-validator.jar 74KB
commons-fileupload.jar 19KB
commons-logging.jar 33KB
mysql-connector-java-3.1.6-bin.jar 382KB
struts.jar 474KB
antlr.jar 344KB
commons-digester.jar 147KB
spring.tld 13KB
spring-form.tld 51KB
index.jsp 831B
.mymetadata 282B
.classpath 2KB
.myeclipse
共 44 条
- 1
资源评论
- sunfish_iris2017-07-24下载下来, 学习学习
doc123
- 粉丝: 22
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功