package org.loveli.dao;
import java.util.Date;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.loveli.pojo.Employee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A data access object (DAO) providing persistence and search support for
* Employee 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 org.loveli.pojo.Employee
* @author MyEclipse Persistence Tools
*/
public class EmployeeDAO extends BaseHibernateDAO {
private static final Logger log = LoggerFactory
.getLogger(EmployeeDAO.class);
// property constants
public static final String EMP_NAME = "empName";
public static final String SEX = "sex";
public static final String AGE = "age";
public static final String ADDRESS = "address";
public void save(Employee transientInstance) {
log.debug("saving Employee instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Employee persistentInstance) {
log.debug("deleting Employee instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Employee findById(java.lang.Integer id) {
log.debug("getting Employee instance with id: " + id);
try {
Employee instance = (Employee) getSession().get(
"org.loveli.pojo.Employee", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Employee instance) {
log.debug("finding Employee instance by example");
try {
List results = getSession().createCriteria(
"org.loveli.pojo.Employee").add(Example.create(instance))
.list();
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 Employee instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Employee as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByEmpName(Object empName) {
return findByProperty(EMP_NAME, empName);
}
public List findBySex(Object sex) {
return findByProperty(SEX, sex);
}
public List findByAge(Object age) {
return findByProperty(AGE, age);
}
public List findByAddress(Object address) {
return findByProperty(ADDRESS, address);
}
public List findAll() {
log.debug("finding all Employee instances");
try {
String queryString = "from Employee";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Employee merge(Employee detachedInstance) {
log.debug("merging Employee instance");
try {
Employee result = (Employee) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Employee instance) {
log.debug("attaching dirty Employee instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Employee instance) {
log.debug("attaching clean Employee instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
struts2+Hibernate+jquery+Ajax+Json+mysql案例 (103个子文件)
.buildpath 188B
EmployeeDAO.class 6KB
DepartmentDAO.class 5KB
EmployeeAction.class 4KB
Employee.class 3KB
HibernateUtil.class 2KB
ServiceHander.class 2KB
Department.class 2KB
EmpServiceImpl.class 2KB
HibernateInterceptor.class 1KB
TransactionProxyFactory.class 996B
DeptServiceImpl.class 670B
BaseHibernateDAO.class 489B
EmpService.class 455B
DeptService.class 235B
IBaseHibernateDAO.class 179B
.classpath 3KB
main.css 2KB
loading.gif 6KB
hibernate3.jar 2.31MB
xwork-core-2.1.6.jar 1.49MB
freemarker-2.3.15.jar 859KB
struts2-core-2.1.8.1.jar 738KB
mysql-connector-java-5.1.6-bin.jar 687KB
javassist-3.9.0.GA.jar 583KB
commons-collections-3.2.jar 558KB
struts2-embeddedjsp-plugin-2.1.8.1.jar 528KB
antlr-2.7.6.jar 433KB
log4j-1.2.14.jar 359KB
dom4j-1.6.1.jar 307KB
hibernate-annotations.jar 273KB
cglib-2.2.jar 272KB
commons-lang-2.3.jar 240KB
ognl-2.7.3.jar 234KB
ehcache-1.2.3.jar 203KB
commons-beanutils-1.7.0.jar 184KB
gson-2.1.jar 176KB
commons-digester-2.0.jar 145KB
commons-validator-1.3.1.jar 136KB
json-lib-2.1.jar 122KB
hibernate-entitymanager.jar 116KB
commons-chain-1.2.jar 90KB
commons-io-1.3.2.jar 86KB
hibernate-commons-annotations.jar 65KB
oro-2.0.8.jar 64KB
hibernate-validator.jar 61KB
struts2-convention-plugin-2.1.8.1.jar 60KB
commons-fileupload-1.2.1.jar 56KB
struts2-json-plugin-2.1.8.1.jar 50KB
ejb3-persistence.jar 49KB
commons-logging-api-1.1.jar 44KB
commons-logging-1.0.4.jar 37KB
classworlds-1.1.jar 37KB
sslext-1.2-0.jar 26KB
slf4j-api-1.5.8.jar 23KB
jta-1.1.jar 13KB
slf4j-log4j12-1.5.8.jar 9KB
aopalliance-1.0.jar 4KB
EmployeeDAO.java 4KB
DepartmentDAO.java 4KB
HibernateUtil.java 3KB
EmployeeAction.java 3KB
Employee.java 2KB
Department.java 1KB
EmpServiceImpl.java 1KB
ServiceHander.java 1KB
HibernateInterceptor.java 851B
EmpService.java 583B
DeptServiceImpl.java 516B
TransactionProxyFactory.java 498B
BaseHibernateDAO.java 340B
DeptService.java 243B
IBaseHibernateDAO.java 225B
jquery-1.4.4.js 179KB
jquery.form.js 20KB
main.js 7KB
index.jsp 6KB
MANIFEST.MF 36B
.myhibernatedata 576B
.mymetadata 306B
.mystrutsdata 240B
.myumldata 66B
users.png 6KB
tooltip.png 4KB
update.png 3KB
update_hover.png 3KB
add.png 3KB
add_hover.png 3KB
delete.png 3KB
delete_hover.png 3KB
div_hide.png 697B
org.eclipse.core.resources.prefs 88B
.project 2KB
test.sql 3KB
Employee.hbm.xml 2KB
Employee.hbm.xml 2KB
Department.hbm.xml 1KB
Department.hbm.xml 1KB
hibernate.cfg.xml 1KB
hibernate.cfg.xml 1KB
共 103 条
- 1
- 2
叶威1
- 粉丝: 264
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页