package orm;
import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* A data access object (DAO) providing persistence and search support for User
* entities. Transaction control of the save(), update() and delete() operations
* can directly support Spring container-managed transactions or they can be
* augmented to handle user-managed Spring transactions. Each of these methods
* provides additional information for how to configure it for the desired type
* of transaction control.
*
* @see orm.User
* @author MyEclipse Persistence Tools
*/
public class UserDAO extends HibernateDaoSupport {
private static final Logger log = LoggerFactory.getLogger(UserDAO.class);
// property constants
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
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("orm.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 findAll() {
getHibernateTemplate().setCacheQueries(true);
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");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
sh_EhCache.7z (84个子文件)
sh_EhCache
.springBeans 462B
.myhibernatedata 569B
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.common.component 468B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 395B
src
test
test.java 1KB
orm
User.hbm.xml 998B
User.java 1KB
UserDAO.java 4KB
ehcache.xml 651B
applicationContext.xml 3KB
.project 2KB
WebRoot
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 404B
classes
test
test.class 1KB
orm
User.hbm.xml 998B
User.class 1KB
UserDAO.class 5KB
ehcache.xml 651B
applicationContext.xml 3KB
lib
log4j-1.2.14.jar 359KB
commons-collections-3.1.jar 546KB
hibernate-annotations.jar 273KB
com.springsource.org.apache.commons.logging-1.1.1.jar 60KB
org.springframework.web.struts-3.0.5.RELEASE.jar 31KB
dom4j-1.6.1.jar 307KB
org.springframework.transaction-3.0.5.RELEASE.jar 226KB
org.springframework.context-3.0.5.RELEASE.jar 653KB
org.springframework.instrument.tomcat-3.0.5.RELEASE.jar 6KB
ejb3-persistence.jar 49KB
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar 1.57MB
com.springsource.org.apache.commons.pool-1.5.3.jar 95KB
org.springframework.oxm-3.0.5.RELEASE.jar 60KB
ehcache-core-2.5.5.jar 1.19MB
org.springframework.beans-3.0.5.RELEASE.jar 542KB
slf4j-jdk14-1.6.1.jar 9KB
cglib-2.2.jar 272KB
org.springframework.expression-3.0.5.RELEASE.jar 166KB
com.springsource.org.codehaus.jackson.mapper-1.0.0.jar 264KB
persistence.jar 69KB
com.springsource.org.apache.log4j-1.2.15.jar 387KB
xapool.jar 90KB
slf4j-api-1.6.1.jar 25KB
org.springframework.asm-3.0.5.RELEASE.jar 52KB
com.springsource.org.aopalliance-1.0.0.jar 5KB
mysql-connector-java-5.1.6-bin.jar 687KB
org.springframework.web.servlet-3.0.5.RELEASE.jar 409KB
com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar 603KB
org.springframework.web-3.0.5.RELEASE.jar 386KB
org.springframework.jdbc-3.0.5.RELEASE.jar 377KB
ehcache-terracotta-2.5.5.jar 876KB
terracotta-toolkit-1.5-runtime-4.4.0.jar 12.16MB
javassist-3.9.0.GA.jar 583KB
hibernate-commons-annotations.jar 65KB
jotm.jar 121KB
org.springframework.core-3.0.5.RELEASE.jar 373KB
org.springframework.web.portlet-3.0.5.RELEASE.jar 171KB
slf4j-api-1.5.8.jar 23KB
ehcache-1.2.3.jar 203KB
commons-dbcp.jar 119KB
spring-context-support-3.2.0.RC2.jar 124KB
org.springframework.aop-3.0.5.RELEASE.jar 314KB
com.springsource.org.apache.commons.httpclient-3.1.0.jar 301KB
com.springsource.net.sf.cglib-2.2.0.jar 319KB
org.springframework.instrument-3.0.5.RELEASE.jar 2KB
com.springsource.org.apache.commons.lang-2.4.0.jar 258KB
slf4j-log4j12-1.5.8.jar 9KB
jta-1.1.jar 13KB
org.springframework.orm-3.0.5.RELEASE.jar 326KB
hibernate-validator.jar 61KB
com.springsource.org.apache.commons.fileupload-1.2.0.jar 53KB
hibernate-entitymanager.jar 116KB
antlr-2.7.6.jar 433KB
spring-context-3.2.0.RC2.jar 833KB
org.springframework.aspects-3.0.5.RELEASE.jar 35KB
hibernate3.jar 2.31MB
spring.tld 17KB
spring-form.tld 69KB
index.jsp 834B
.mymetadata 303B
.classpath 6KB
.myeclipse
共 84 条
- 1
昵称_csdn
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页