Sql 执行过程
debug 了一下,大概执行流程如下:
- getMapper
- Proxy.newInstance
- selectById()
- MapperProxy#invoke
- cacheInvoke
- MapperMethod#execute
- select or update ...
- convertArgsToSqlCommandParam
- sqlSession.selectOne
- sqlSession.selectList
- configuration.getMappedStatement(statement)
- Executor#query
- CacheKey(二级缓存)
- queryFromDatabase
- doQuery
- prepareStatement(打开 jdbc Connection)
- PreparedStatement.execute
- resultSetHandler.handleResultSets(ps); (处理返回值类型和 java 对应)
说明:
主要分为两部分,获取 Mapper、创建 MapperProxy、Execute 执行起调用执行、获取 jdbc connection、创建 sql Statement 执行。