zoukankan      html  css  js  c++  java
  • mybatis之SqlSessionFactory源码分析

    SqlSessionFactoryBuilder 类中代码
    public
    class SqlSessionFactoryBuilder { public SqlSessionFactory build(Reader reader) { return build(reader, null, null); } public SqlSessionFactory build(Reader reader, String environment) { return build(reader, environment, null); } public SqlSessionFactory build(Reader reader, Properties properties) { return build(reader, null, properties); } public SqlSessionFactory build(Reader reader, String environment, Properties properties) { try { XMLConfigBuilder parser = new XMLConfigBuilder(reader, environment, properties); return build(parser.parse()); } catch (Exception e) { throw ExceptionFactory.wrapException("Error building SqlSession.", e); } finally { ErrorContext.instance().reset(); try { reader.close(); } catch (IOException e) { // Intentionally ignore. Prefer previous error. } } } public SqlSessionFactory build(InputStream inputStream) { return build(inputStream, null, null); } public SqlSessionFactory build(InputStream inputStream, String environment) { return build(inputStream, environment, null); } public SqlSessionFactory build(InputStream inputStream, Properties properties) { return build(inputStream, null, properties); } public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) { try { XMLConfigBuilder parser = new XMLConfigBuilder(inputStream, environment, properties); return build(parser.parse()); } catch (Exception e) { throw ExceptionFactory.wrapException("Error building SqlSession.", e); } finally { ErrorContext.instance().reset(); try { inputStream.close(); } catch (IOException e) { // Intentionally ignore. Prefer previous error. } } } public SqlSessionFactory build(Configuration config) { return new DefaultSqlSessionFactory(config);//DefaultSqlSessionFactory实现了SqlSessionFactory接口 } }
    可以看到SqlSessionFactoryBuilder 中有9个build方法,其中有4个字符流、4个字节流,还有一个是(Configuration config)作为形参
    都是将mybatis-config.xml配置文件解析成Configuration对象,最终导向build(Configuration configuration)进行SqlSessionFactory的构造。
    然后可以看XMLConfigBuilder的parse()的方法是从configuration根节点开始解析,根节点下可以配置10个子节点
    分别为:properties、typeAliases、plugins、objectFactory、objectWrapperFactory、settings、environments、databaseIdProvider、typeHandlers、mappers。
  • 相关阅读:
    Laravel 请求:判断是否是 Ajax 请求
    Laravel中常用的几种向视图传递变量的方法
    curl实现http与https请求的方法
    PHP header 的几种用法
    mysql数据库“不能插入中文”解决办法
    支付宝证书签名 PHP SDK
    tp5.0在控制器中和在模板中调用配置文件中的常量
    TP5.1 调用common里面自定义的常量
    Call to a member function assign() on null
    Docker部署code-server
  • 原文地址:https://www.cnblogs.com/wangxiaochao/p/9306813.html
Copyright © 2011-2022 走看看