完整的时序图可以打开我的云笔记进行查看,对浏览器查看比例进行缩放为250%即可
使用org.apache.ibatis.io.Resources.getResourceAsReader(String)定位mybatis配置文件的位置,获得文件的输入流。
Created with Raphaël 2.1.0ReaderReaderResourcesResourcesInputStreamReaderInputStreamReaderInputStreamInputStreamClassLoaderWrapperClassLoaderWrapperClassLoaderClassLoadergetResourceAsReader()getResourceAsReader()''getResourceAsStream()getResourceAsStream()getResourceAsStream()''getResourceAsReadernew InputStreamReader()构建SqlSessionFactory的时序图,使用SqlSessionFactoryBuilder创建SqlSessionFactory对象
Created with Raphaël 2.1.0SqlSessionFactoryBuilderSqlSessionFactoryBuilderXMLConfigBuilderXMLConfigBuilderXPathParserXPathParserDocumentBuilderDocumentBuilderDOMParserDOMParserDocumentDocumentConfigurationConfigurationSqlSessionFactorySqlSessionFactorybuild(reader)XMLConfigBuilder(XPathParser)createDocument()parse()getDocument()new XPathParser()new XMLConfigBuilder()parse()parseConfiguration()build(Configuration)根据时序图可以看得出,创建sessionFactory需要
将读入的配置文件流解析为Document对象将Document对象解析为Configuration对象使用Configuration对象,通过build()方法完成对SqlSessionFactory对象的创建。在执行具体的 org.apache.ibatis.executor.SimpleExecutor.prepareStatement(StatementHandler, Log)处连接数据库,检查是否能连接成功
数据库连接时序图
Created with Raphaël 2.1.0SimpleExecutorSimpleExecutorBaseExecutorBaseExecutorJdbcTransactionJdbcTransactionDataSourceDataSourceUnpooledDataSourceUnpooledDataSourceDriverManagerDriverManagerDriverInfoDriverInfogetConnection()getConnection()getConnection()openConnection()getConnection()popConnection()new PooledConnection()doGetConnection()getConnection()connect()newInstance()''