zoukankan      html  css  js  c++  java
  • 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.   }  
  • 相关阅读:
    Python range() 函数用法
    substr
    disable enable 所有其他表关联的外键
    sql with multiply where
    小米开源文件管理器MiCodeFileExplorer-源码研究(7)-Favorite收藏管理和SQLite数据库CRUD
    Centos安装FastDFS+Nginx(一天时间搞定)
    Centos安装FastDFS+Nginx(一天时间搞定)
    小米开源文件管理器MiCodeFileExplorer-源码研究(6)-媒体文件MediaFile和文件类型MimeUtils
    小米开源文件管理器MiCodeFileExplorer-源码研究(6)-媒体文件MediaFile和文件类型MimeUtils
    小米开源文件管理器MiCodeFileExplorer-源码研究(5)-AsyncTask异步任务
  • 原文地址:https://www.cnblogs.com/doudou618/p/4323534.html
Copyright © 2011-2022 走看看