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.   }  
  • 相关阅读:
    【C++】C++代码动态检查
    【加解密】使用CFSSL生成证书并使用gRPC验证证书
    分库分表下跨库join解决方案
    解决1235
    为什么v-for中的key值不推荐使用index
    弹性布局公共样式总结
    关于python的模块
    [转]Ubuntu18.04安装uwsgi错误:error: lto-wrapper failed collect2: error: ld returned 1 exit status
    python 坐标遍历 生成笛卡尔积矩阵
    Mongo BsonUndefined 转换问题(自定义Mongo类型转换器)
  • 原文地址:https://www.cnblogs.com/doudou618/p/4323534.html
Copyright © 2011-2022 走看看