package com.entity;
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
* Student 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.entity.Student
* @author MyEclipse Persistence Tools
*/
public class StudentDAO extends HibernateDaoSupport {
private static final Logger log = LoggerFactory.getLogger(StudentDAO.class);
// property constants
public static final String USERNAME = "username";
public static final String AGE = "age";
protected void initDao() {
// do nothing
}
public void save(Student transientInstance) {
log.debug("saving Student instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Student persistentInstance) {
log.debug("deleting Student instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Student findById(java.lang.Integer id) {
log.debug("getting Student instance with id: " + id);
try {
Student instance = (Student) getHibernateTemplate().get(
"com.entity.Student", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Student instance) {
log.debug("finding Student 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 Student instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Student 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 findByAge(Object age) {
return findByProperty(AGE, age);
}
public List findAll() {
log.debug("finding all Student instances");
try {
String queryString = "from Student";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Student merge(Student detachedInstance) {
log.debug("merging Student instance");
try {
Student result = (Student) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Student instance) {
log.debug("attaching dirty Student instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Student instance) {
log.debug("attaching clean Student instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static StudentDAO getFromApplicationContext(ApplicationContext ctx) {
return (StudentDAO) ctx.getBean("StudentDAO");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
json.rar (35个子文件)
.project 2KB
.mystrutsdata 240B
.springBeans 462B
.mymetadata 285B
src
struts.xml 446B
applicationContext.xml 2KB
com
Biz
StudentBiz.java 405B
Action
StudentListAction.java 826B
entity
StudentDAO.java 4KB
Student.hbm.xml 805B
Student.java 784B
WebRoot
WEB-INF
spring-form.tld 69KB
spring.tld 17KB
classes
struts.xml 446B
applicationContext.xml 2KB
com
Biz
StudentBiz.class 749B
Action
StudentListAction.class 1KB
entity
Student.hbm.xml 805B
Student.class 1KB
StudentDAO.class 5KB
lib
commons-beanutils.jar 184KB
ezmorph-1.0.6.jar 84KB
mysql-connector-java-5.0.4-bin.jar 484KB
json-lib-2.4-jdk15.jar 155KB
xom-1.0d10.jar 104KB
web.xml 998B
index.jsp 2KB
js
jquery-1.7.2.js 247KB
META-INF
MANIFEST.MF 36B
.myeclipse
.myhibernatedata 562B
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.jdt.core.prefs 330B
org.eclipse.wst.jsdt.ui.superType.name 6B
.jsdtscope 500B
.classpath 2KB
共 35 条
- 1
潇湘欲雨
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页