1. package org.springframework.orm.hibernate3.support;
  2. import org.hibernate.HibernateException;
  3. import org.hibernate.Session;
  4. import org.hibernate.SessionFactory;
  5. import org.springframework.dao.DataAccessException;
  6. import org.springframework.dao.DataAccessResourceFailureException;
  7. import org.springframework.dao.support.DaoSupport;
  8. import org.springframework.orm.hibernate3.HibernateTemplate;
  9. import org.springframework.orm.hibernate3.SessionFactoryUtils;
  10. public abstract class HibernateDaoSupport extends DaoSupport
  11. {
  12. private HibernateTemplate hibernateTemplate;
  13. // set注入sessionFactory
  14. public final void setSessionFactory(SessionFactory paramSessionFactory)
  15. {
  16. this.hibernateTemplate = createHibernateTemplate(paramSessionFactory);
  17. }
  18. //创建HibernateTemplate 俺们就是用这个对象
  19. protected HibernateTemplate createHibernateTemplate(SessionFactory paramSessionFactory)
  20. {
  21. return new HibernateTemplate(paramSessionFactory);
  22. }
  23. public final SessionFactory getSessionFactory()
  24. {
  25. return ((this.hibernateTemplate != null) ? this.hibernateTemplate.getSessionFactory() : null);
  26. }
  27. public final void setHibernateTemplate(HibernateTemplate paramHibernateTemplate)
  28. {
  29. this.hibernateTemplate = paramHibernateTemplate;
  30. }
  31. public final HibernateTemplate getHibernateTemplate()
  32. {
  33. return this.hibernateTemplate;
  34. }
  35. protected final void checkDaoConfig() {
  36. if (this.hibernateTemplate == null)
  37. throw new IllegalArgumentException("'sessionFactory' or 'hibernateTemplate' is required");
  38. }
  39. //创建session
  40. protected final Session getSession()
  41. throws DataAccessResourceFailureException, IllegalStateException
  42. {
  43. return getSession(this.hibernateTemplate.isAllowCreate());
  44. }
  45. protected final Session getSession(boolean paramBoolean)
  46. throws DataAccessResourceFailureException, IllegalStateException
  47. {
  48. return ((!(paramBoolean)) ? SessionFactoryUtils.getSession(getSessionFactory(), false) : SessionFactoryUtils.getSession(getSessionFactory(), this.hibernateTemplate.getEntityInterceptor(), this.hibernateTemplate.getJdbcExceptionTranslator()));
  49. }
  50. protected final DataAccessException convertHibernateAccessException(HibernateException paramHibernateException)
  51. {
  52. return this.hibernateTemplate.convertHibernateAccessException(paramHibernateException);
  53. }
  54. protected final void releaseSession(Session paramSession)
  55. {
  56. SessionFactoryUtils.releaseSession(paramSession, getSessionFactory());
  57. }

HibernateDaoSupport 源码的更多相关文章

  1. SSH框架总结(环境搭建+框架分析+实例源码下载)

    一.SSH框架简介 SSH是struts+spring+hibernate集成的web应用程序开源框架. Struts:用来控制的,核心控制器是Controller. Spring:对Struts和H ...

  2. 【原】Android热更新开源项目Tinker源码解析系列之三:so热更新

    本系列将从以下三个方面对Tinker进行源码解析: Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Android热更新开源项目Tinker源码解析系列之二:资源文件热更新 A ...

  3. C# ini文件操作【源码下载】

    介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...

  4. 【原】FMDB源码阅读(三)

    [原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...

  5. 从源码看Azkaban作业流下发过程

    上一篇零散地罗列了看源码时记录的一些类的信息,这篇完整介绍一个作业流在Azkaban中的执行过程,希望可以帮助刚刚接手Azkaban相关工作的开发.测试. 一.Azkaban简介 Azkaban作为开 ...

  6. 【原】Android热更新开源项目Tinker源码解析系列之一:Dex热更新

    [原]Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Tinker是微信的第一个开源项目,主要用于安卓应用bug的热修复和功能的迭代. Tinker github地址:http ...

  7. 【原】Android热更新开源项目Tinker源码解析系列之二:资源文件热更新

    上一篇文章介绍了Dex文件的热更新流程,本文将会分析Tinker中对资源文件的热更新流程. 同Dex,资源文件的热更新同样包括三个部分:资源补丁生成,资源补丁合成及资源补丁加载. 本系列将从以下三个方 ...

  8. 多线程爬坑之路-Thread和Runable源码解析之基本方法的运用实例

    前面的文章:多线程爬坑之路-学习多线程需要来了解哪些东西?(concurrent并发包的数据结构和线程池,Locks锁,Atomic原子类) 多线程爬坑之路-Thread和Runable源码解析 前面 ...

  9. SDWebImage源码解读之SDWebImageDownloaderOperation

    第七篇 前言 本篇文章主要讲解下载操作的相关知识,SDWebImageDownloaderOperation的主要任务是把一张图片从服务器下载到内存中.下载数据并不难,如何对下载这一系列的任务进行设计 ...

随机推荐

  1. css清除默认样式和设置公共样式

    /*公共样式--开始*/ html, body, div, ul, li, h1, h2, h3, h4, h5, h6, p, dl, dt, dd, ol, form, input, textar ...

  2. 024-ActionResult解说

    ActionResult是一个抽象类,是Action运行后的回传类型,但是当Action回传ActionResult的时候,其实并不包含这个ActionResult的运行结果,而是包含运行这个Acti ...

  3. [maven] pom.xml 文件详解

    参考资料: http://blog.csdn.net/uohzoaix/article/details/7035307 http://www.cnblogs.com/qq78292959/p/3711 ...

  4. js 数组的判断

    <javascript语言精粹>中的 var is_array = function(value){ return value && //判断值是否为真,不接受null和其 ...

  5. MySQL索引实现

    摘自:http://blog.codinglabs.org/articles/theory-of-mysql-index.html 在MySQL中,索引属于存储引擎级别的概念,不同存储引擎对索引的实现 ...

  6. 421. Maximum XOR of Two Numbers in an Array——本质:利用trie数据结构查找

    Given a non-empty array of numbers, a0, a1, a2, - , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  7. Gramar

    一.And 并列关系(and) in addition / and / similarly / likewise / as well as / besides / furthermore / also ...

  8. linux-网卡故障

    Linux 网络问题解决思路 1.查看 /etc/sysconfig/network-script/ 查看eth0和eth1的配置是否正确 2.查看 /etc/modual.conf 的配置模块是否正 ...

  9. PostgreSQL数据库系统优点

    PostgreSQL 是世界上可以获得的最先进的开放源码的数据库系统, 它提供了多版本并行控制,支持几乎所有 SQL 构件(包括子查询,事务和用户定 义类型和函数), 并且可以获得非常广阔范围的(开发 ...

  10. [示例]NSDictionary编程题-字典的排序应用(iOS7班)

    代码: #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepo ...