首页
Web开发
Windows程序
编程语言
数据库
移动开发
系统相关
微信
其他好文
会员
首页
>
Web开发
> 详细
HibernateDaoSupport 源码
时间:
2015-03-09 15:48:32
阅读:
137
评论:
0
收藏:
0
[点我收藏+]
标签:
Java代码
package org.springframework.orm.hibernate3.support;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.dao.support.DaoSupport;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
public
abstract
class HibernateDaoSupport
extends DaoSupport
{
private HibernateTemplate hibernateTemplate;
// set注入sessionFactory
public
final
void setSessionFactory(SessionFactory paramSessionFactory)
{
this.hibernateTemplate = createHibernateTemplate(paramSessionFactory);
}
//创建HibernateTemplate 俺们就是用这个对象
protected HibernateTemplate createHibernateTemplate(SessionFactory paramSessionFactory)
{
return
new HibernateTemplate(paramSessionFactory);
}
public
final SessionFactory getSessionFactory()
{
return ((
this.hibernateTemplate !=
null) ?
this.hibernateTemplate.getSessionFactory() :
null);
}
public
final
void setHibernateTemplate(HibernateTemplate paramHibernateTemplate)
{
this.hibernateTemplate = paramHibernateTemplate;
}
public
final HibernateTemplate getHibernateTemplate()
{
return
this.hibernateTemplate;
}
protected
final
void checkDaoConfig() {
if (
this.hibernateTemplate ==
null)
throw
new IllegalArgumentException(
"‘sessionFactory‘ or ‘hibernateTemplate‘ is required");
}
//创建session
protected
final Session getSession()
throws DataAccessResourceFailureException, IllegalStateException
{
return getSession(
this.hibernateTemplate.isAllowCreate());
}
protected
final Session getSession(
boolean paramBoolean)
throws DataAccessResourceFailureException, IllegalStateException
{
return ((!(paramBoolean)) ? SessionFactoryUtils.getSession(getSessionFactory(),
false) : SessionFactoryUtils.getSession(getSessionFactory(),
this.hibernateTemplate.getEntityInterceptor(),
this.hibernateTemplate.getJdbcExceptionTranslator()));
}
protected
final DataAccessException convertHibernateAccessException(HibernateException paramHibernateException)
{
return
this.hibernateTemplate.convertHibernateAccessException(paramHibernateException);
}
protected
final
void releaseSession(Session paramSession)
{
SessionFactoryUtils.releaseSession(paramSession, getSessionFactory());
}
HibernateDaoSupport 源码
标签:
原文地址:http://www.cnblogs.com/doudou618/p/4323534.html
踩
(
0
)
赞
(
0
)
举报
评论
一句话评论(
0
)
登录后才能评论!
分享档案
更多>
2021年07月29日 (22)
2021年07月28日 (40)
2021年07月27日 (32)
2021年07月26日 (79)
2021年07月23日 (29)
2021年07月22日 (30)
2021年07月21日 (42)
2021年07月20日 (16)
2021年07月19日 (90)
2021年07月16日 (35)
周排行
更多
36.VUE — 认识 Webpack 和 安装
2021-07-28
【PHP】上传图片翻转问题
2021-07-28
php对数字进行万。亿的转化
2021-07-28
五个 .NET 性能小贴士
2021-07-28
Three.js中显示坐标轴、平面、球体、四方体
2021-07-28
.net 5+ 知新:【1】 .Net 5 基本概念和开发环境搭建
2021-07-27
1.html,css
2021-07-27
基于Docker搭建 Php-fpm + Nginx 环境
2021-07-27
nginx + http + svn
2021-07-27
kubernets kube-proxy的代理 iptables和ipvs
2021-07-26
友情链接
兰亭集智
国之画
百度统计
站长统计
阿里云
chrome插件
新版天听网
关于我们
-
联系我们
-
留言反馈
© 2014
mamicode.com
版权所有 联系我们:gaon5@hotmail.com
迷上了代码!