package com.mvc.dao.impl.base;
import javax.annotation.Resource;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.dao.support.DaoSupport;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
public class BaseHibernateDao extends DaoSupport{
private SessionFactory sessionFactory;
private HibernateTemplate hibernateTemplate;
@Autowired
private JdbcTemplate jdbcTemplate;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
@Resource(name="sessionFactory")
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
this.hibernateTemplate=createHibernateTemplate(sessionFactory);
}
public Session getSession() {
if (this.sessionFactory == null) {
throw new HibernateException("Session Create Fail,SessionFactory is null!");
}
return this.sessionFactory.getCurrentSession();
}
protected HibernateTemplate createHibernateTemplate(
SessionFactory sessionFactory) {
return new HibernateTemplate(sessionFactory);
}
@Override
protected void checkDaoConfig() throws IllegalArgumentException {
if (this.hibernateTemplate == null) {
throw new IllegalArgumentException("'sessionFactory' or 'hibernateTemplate' is required");
}
}
protected final Session getSession(boolean allowCreate)
throws DataAccessResourceFailureException, IllegalStateException {
return (!allowCreate ? SessionFactoryUtils.getSession(
getSessionFactory(), false) : SessionFactoryUtils.getSession(
getSessionFactory(),
this.hibernateTemplate.getEntityInterceptor(), this.hibernateTemplate.getJdbcExceptionTranslator()));
}
protected final DataAccessException convertHibernateAccessException(
HibernateException ex) {
return this.hibernateTemplate.convertHibernateAccessException(ex);
}
protected final void releaseSession(Session session) {
SessionFactoryUtils.releaseSession(session, getSessionFactory());
if(null!=session)session=null;
}
public final void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
public final HibernateTemplate getHibernateTemplate() {
return this.hibernateTemplate;
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
springmvc.rar (77个子文件)
springmvc
.project 1KB
WebContent
WEB-INF
view
hello.jsp 624B
welcome.jsp 288B
spring-servlet.xml 2KB
lib
org.springframework.beans-3.1.0.RELEASE.jar 575KB
org.springframework.core-3.1.0.RELEASE.jar 432KB
org.springframework.asm-3.1.0.RELEASE.jar 52KB
jboss-transaction-api_1.1_spec-1.0.1.Final.jar 25KB
dom4j-1.6.1.jar 307KB
org.springframework.web.servlet-3.1.0.RELEASE.jar 559KB
org.springframework.transaction-3.1.0.RELEASE.jar 240KB
org.springframework.test-3.1.0.RELEASE.jar 224KB
jstl-1.2.jar 405KB
cglib-nodep-2.1_3.jar 317KB
org.springframework.instrument-3.1.0.RELEASE.jar 7KB
org.springframework.jdbc-3.1.0.RELEASE.jar 392KB
javassist-3.15.0-GA.jar 633KB
org.springframework.jms-3.1.0.RELEASE.jar 194KB
commons-logging-1.1.1.jar 59KB
hibernate-core-4.2.5.Final.jar 4.41MB
org.springframework.expression-3.1.0.RELEASE.jar 172KB
mysql-connector-5.1.8.jar 707KB
org.springframework.oxm-3.1.0.RELEASE.jar 69KB
c3p0-0.9.1.2.jar 596KB
hibernate-jpa-2.0-api-1.0.1.Final.jar 100KB
antlr-2.7.7.jar 435KB
org.springframework.instrument.tomcat-3.1.0.RELEASE.jar 11KB
aspectjweaver-1.6.8.jar 1.55MB
aopalliance-1.0.jar 4KB
jboss-logging-3.1.0.GA.jar 59KB
org.springframework.roo.annotations-1.1.3.RELEASE.jar 16KB
org.springframework.aspects-3.1.0.RELEASE.jar 49KB
hibernate-commons-annotations-4.0.2.Final.jar 80KB
org.springframework.web-3.1.0.RELEASE.jar 528KB
org.springframework.context-3.1.0.RELEASE.jar 810KB
org.springframework.orm-3.1.0.RELEASE.jar 369KB
org.springframework.aop-3.1.0.RELEASE.jar 324KB
org.springframework.context.support-3.1.0.RELEASE.jar 104KB
jdbc.properties 152B
web.xml 2KB
index.jsp 280B
META-INF
MANIFEST.MF 39B
src
applicationContext_hibernate.xml 6KB
com
mvc
service
impl
UserServiceImpl.java 731B
UserService.java 130B
model
User.java 485B
hbm
Users.hbm.xml 948B
controller
UserTestJdbc.java 831B
TestController.java 968B
UserController.java 835B
dao
UserDao.java 138B
impl
UserDaoImpl.java 735B
base
BaseHibernateDao.java 3KB
jdbc.properties 152B
applicationContext_jdbc.xml 6KB
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 345B
org.eclipse.wst.ws.service.policy.prefs 118B
org.eclipse.jdt.core.prefs 395B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.resources.prefs 107B
org.eclipse.wst.common.component 481B
.jsdtscope 503B
build
classes
applicationContext_hibernate.xml 6KB
com
mvc
service
UserService.class 185B
impl
UserServiceImpl.class 1KB
model
User.class 914B
hbm
Users.hbm.xml 948B
controller
UserController.class 1KB
UserTestJdbc.class 1KB
TestController.class 2KB
dao
impl
UserDaoImpl.class 701B
base
BaseHibernateDao.class 4KB
UserDao.class 179B
jdbc.properties 152B
applicationContext_jdbc.xml 6KB
.classpath 919B
共 77 条
- 1
nlf416511
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页