package com.javen.dao;
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;
import com.javen.entity.User;
/**
* 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 com.javen.entity.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 NAME = "name";
public static final String PASSWORD = "password";
public static final String SEX = "sex";
public static final String NUM = "num";
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(
"com.javen.entity.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 findByName(Object name) {
return findByProperty(NAME, name);
}
public List findByPassword(Object password) {
return findByProperty(PASSWORD, password);
}
public List findBySex(Object sex) {
return findByProperty(SEX, sex);
}
public List findByNum(Object num) {
return findByProperty(NUM, num);
}
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");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SSH封装接口返回Json数据. (102个子文件)
UserDAO.class 5KB
UserAction.class 3KB
testDAO.class 2KB
UserHanderImpl.class 2KB
User.class 2KB
BaseAction.class 1KB
JSONUtils.class 1KB
Tools.class 712B
UserHander.class 250B
.classpath 6KB
org.eclipse.wst.common.component 537B
org.eclipse.wst.jsdt.ui.superType.container 49B
hibernate3.jar 2.31MB
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar 1.57MB
jbosscache-core-3.1.0.GA.jar 1.1MB
mysql-connector-java-5[1].1.7-bin.jar 693KB
jboss-cache-1.4.1.GA.jar 690KB
org.springframework.context-3.0.5.RELEASE.jar 653KB
com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar 603KB
c3p0-0.9.1.jar 594KB
javassist-3.9.0.GA.jar 583KB
commons-collections-3.1.jar 546KB
org.springframework.beans-3.0.5.RELEASE.jar 542KB
proxool-0.8.3.jar 465KB
antlr-2.7.6.jar 433KB
org.springframework.web.servlet-3.0.5.RELEASE.jar 409KB
com.springsource.org.apache.log4j-1.2.15.jar 387KB
org.springframework.web-3.0.5.RELEASE.jar 386KB
org.springframework.jdbc-3.0.5.RELEASE.jar 377KB
org.springframework.core-3.0.5.RELEASE.jar 373KB
log4j-1.2.14.jar 359KB
org.springframework.orm-3.0.5.RELEASE.jar 326KB
com.springsource.net.sf.cglib-2.2.0.jar 319KB
org.springframework.aop-3.0.5.RELEASE.jar 314KB
dom4j-1.6.1.jar 307KB
com.springsource.org.apache.commons.httpclient-3.1.0.jar 301KB
hibernate-annotations.jar 273KB
cglib-2.2.jar 272KB
com.springsource.org.codehaus.jackson.mapper-1.0.0.jar 264KB
com.springsource.org.apache.commons.lang-2.4.0.jar 258KB
org.springframework.transaction-3.0.5.RELEASE.jar 226KB
ehcache-1.2.3.jar 203KB
org.springframework.web.portlet-3.0.5.RELEASE.jar 171KB
org.springframework.expression-3.0.5.RELEASE.jar 166KB
gson-1.6.jar 161KB
jotm.jar 121KB
commons-dbcp.jar 119KB
hibernate-entitymanager.jar 116KB
oscache-2.1.jar 112KB
com.springsource.org.apache.commons.pool-1.5.3.jar 95KB
xapool.jar 90KB
persistence.jar 69KB
hibernate-commons-annotations.jar 65KB
hibernate-validator.jar 61KB
com.springsource.org.apache.commons.logging-1.1.1.jar 60KB
org.springframework.oxm-3.0.5.RELEASE.jar 60KB
com.springsource.org.apache.commons.fileupload-1.2.0.jar 53KB
org.springframework.asm-3.0.5.RELEASE.jar 52KB
ejb3-persistence.jar 49KB
org.springframework.aspects-3.0.5.RELEASE.jar 35KB
org.springframework.web.struts-3.0.5.RELEASE.jar 31KB
swarmcache-1.0RC2.jar 30KB
slf4j-api-1.5.8.jar 23KB
jta-1.1.jar 13KB
slf4j-log4j12-1.5.8.jar 9KB
org.springframework.instrument.tomcat-3.0.5.RELEASE.jar 6KB
com.springsource.org.aopalliance-1.0.0.jar 5KB
org.springframework.instrument-3.0.5.RELEASE.jar 2KB
UserDAO.java 4KB
UserAction.java 2KB
testDAO.java 1KB
BaseAction.java 1KB
UserHanderImpl.java 1KB
User.java 1KB
JSONUtils.java 643B
Tools.java 405B
UserHander.java 272B
.jsdtscope 500B
index.jsp 834B
Error.jsp 823B
MANIFEST.MF 36B
.myhibernatedata 643B
.mymetadata 297B
.mystrutsdata 240B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.jdt.ui.prefs 5KB
org.eclipse.jdt.core.prefs 364B
com.genuitec.eclipse.ws.prefs 78B
.project 2KB
log4j.properties 296B
log4j.properties 296B
.springBeans 462B
spring-form.tld 69KB
spring.tld 17KB
struts.xml 2KB
struts.xml 2KB
applicationContext.xml 2KB
applicationContext.xml 2KB
web.xml 2KB
User.hbm.xml 1KB
共 102 条
- 1
- 2
资源评论
- 琴韵2016-03-22不错,值得学习一下
jialiguo
- 粉丝: 19
- 资源: 75
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功