• HibernateDaoSupport 源码


    Java代码  收藏代码
    1. package org.springframework.orm.hibernate3.support;  
    2.   
    3. import org.hibernate.HibernateException;  
    4. import org.hibernate.Session;  
    5. import org.hibernate.SessionFactory;  
    6. import org.springframework.dao.DataAccessException;  
    7. import org.springframework.dao.DataAccessResourceFailureException;  
    8. import org.springframework.dao.support.DaoSupport;  
    9. import org.springframework.orm.hibernate3.HibernateTemplate;  
    10. import org.springframework.orm.hibernate3.SessionFactoryUtils;  
    11.   
    12. public abstract class HibernateDaoSupport extends DaoSupport  
    13. {  
    14.   private HibernateTemplate hibernateTemplate;  
    15.   
    16.   // set注入sessionFactory  
    17.   public final void setSessionFactory(SessionFactory paramSessionFactory)  
    18.   {  
    19.     this.hibernateTemplate = createHibernateTemplate(paramSessionFactory);  
    20.   }  
    21.   //创建HibernateTemplate 俺们就是用这个对象  
    22.   protected HibernateTemplate createHibernateTemplate(SessionFactory paramSessionFactory)  
    23.   {  
    24.     return new HibernateTemplate(paramSessionFactory);  
    25.   }  
    26.   
    27.   public final SessionFactory getSessionFactory()  
    28.   {  
    29.     return ((this.hibernateTemplate != null) ? this.hibernateTemplate.getSessionFactory() : null);  
    30.   }  
    31.   
    32.   public final void setHibernateTemplate(HibernateTemplate paramHibernateTemplate)  
    33.   {  
    34.     this.hibernateTemplate = paramHibernateTemplate;  
    35.   }  
    36.   
    37.   public final HibernateTemplate getHibernateTemplate()  
    38.   {  
    39.     return this.hibernateTemplate;  
    40.   }  
    41.   
    42.   protected final void checkDaoConfig() {  
    43.     if (this.hibernateTemplate == null)  
    44.       throw new IllegalArgumentException("'sessionFactory' or 'hibernateTemplate' is required");  
    45.   }  
    46.  //创建session  
    47.   protected final Session getSession()  
    48.     throws DataAccessResourceFailureException, IllegalStateException  
    49.   {  
    50.     return getSession(this.hibernateTemplate.isAllowCreate());  
    51.   }  
    52.   
    53.   protected final Session getSession(boolean paramBoolean)  
    54.     throws DataAccessResourceFailureException, IllegalStateException  
    55.   {  
    56.     return ((!(paramBoolean)) ? SessionFactoryUtils.getSession(getSessionFactory(), false) : SessionFactoryUtils.getSession(getSessionFactory(), this.hibernateTemplate.getEntityInterceptor(), this.hibernateTemplate.getJdbcExceptionTranslator()));  
    57.   }  
    58.   
    59.   protected final DataAccessException convertHibernateAccessException(HibernateException paramHibernateException)  
    60.   {  
    61.     return this.hibernateTemplate.convertHibernateAccessException(paramHibernateException);  
    62.   }  
    63.   
    64.   protected final void releaseSession(Session paramSession)  
    65.   {  
    66.     SessionFactoryUtils.releaseSession(paramSession, getSessionFactory());  
    67.   }  
  • 相关阅读:
    这个帖子主要总结数据库备份方面的问题
    Visual C#.Net 网络程序开发Socket篇
    数据库设计说明书参考模板
    用Visual C#开发WinForm的应用程序
    在ASP.NET页中读取文本文件
    如何通过 SQL Server 链接服务器和分布式查询使用 Excel
    ER概念模型
    SQL Server 存储过程的分页方案比拼
    读出某一个目录的文件和文件夹
    Linux中的定时任务简单操作实例
  • 原文地址:https://www.cnblogs.com/doudou618/p/4323534.html
Copyright © 2020-2023  润新知