SqlSession最常用的类
2013-05-11 00:00
267 查看
http://chengjisihan.iteye.com/blog/752168(SqlSession,SqlSessionFactory,SqlSessionFactoryBuilder,Environment,Configuration,Mapper)
http://chengjisihan.iteye.com/blog/755104(Interceptor,TypeHandler,ObjectFactory,TypeAlias,SelectBuilder)
http://chengjisihan.iteye.com/blog/760259(Dynamic SQL)
SqlSession中的几个方法在Dao中经常要用到。。
SqlSessionFactory是用来构造SqlSession的
从这个方法中可以看到构建顺序
Configuration --> Environment --> TransactionFactory --> Transaction -> Executor --> DefaultSqlSession
http://chengjisihan.iteye.com/blog/755104(Interceptor,TypeHandler,ObjectFactory,TypeAlias,SelectBuilder)
http://chengjisihan.iteye.com/blog/760259(Dynamic SQL)
SqlSession中的几个方法在Dao中经常要用到。。
SqlSessionFactory是用来构造SqlSession的
public interface SqlSessionFactory { SqlSession openSession(); SqlSession openSession(boolean autoCommit); SqlSession openSession(Connection connection); SqlSession openSession(TransactionIsolationLevel level); SqlSession openSession(ExecutorType execType); SqlSession openSession(ExecutorType execType, boolean autoCommit); SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level); SqlSession openSession(ExecutorType execType, Connection connection); Configuration getConfiguration(); }默认实现是DefaultSqlSessionFactory,还有一个是SqlSessonManager(身份不明)
public class DefaultSqlSessionFactory implements SqlSessionFactory { private final Configuration configuration; public DefaultSqlSessionFactory(Configuration configuration) { this.configuration = configuration; } //此处省去很多openSession(...) public Configuration getConfiguration() { return configuration; } //这个才是核心 private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) { Transaction tx = null; try { final Environment environment = configuration.getEnvironment(); final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit); final Executor executor = configuration.newExecutor(tx, execType, autoCommit); return new DefaultSqlSession(configuration, executor); } catch (Exception e) { closeTransaction(tx); // may have fetched a connection so lets call close() throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
从这个方法中可以看到构建顺序
Configuration --> Environment --> TransactionFactory --> Transaction -> Executor --> DefaultSqlSession
相关文章推荐
- mybatis与hibernate常用的持久化类,及sqlsession和sqlsessionTemplate区别
- mybatis之入门到开发(三)之常用对象SqlSessionFactory和SqlSession,动态sql,输入映射和输出映射
- NAnt常用Target:clean
- ASP常用数据库连接方法和技巧
- sql常用简易语句
- 一些常用的Js调用cs类
- JDom 常用api 及 一般的使用
- Socket网络编程学习笔记(1):常用方法介绍
- js 常用数组操作
- 锐捷网络交换机常用操作命令
- 40种网页常用小技巧(javascript)--备不时之需
- linux常用命令大全(转)
- Android 常用 mimeType 表
- Linux 常用命令
- Linux常用命令(二)(课程)
- Android常用语句
- JavaScript常用全局属性与方法记录积累
- java 开发常用IDE
- const 限定符常用总结
- Vim常用配置函数介绍