MyBatis(二)

一、获得Mapper动态代理

二、获得MapperMethod对象

代理类实现了InvocationHandler,所以一定会执行invoke()方法
cacheMapperMethod()

1)SqlCommand

resolveMappedStatement()
resolveMappedStatement()
sqlCommand创建完毕

2)MethodSignature

TypeParameterResolver.resolveReturnType()
TypeParameterResolver.resolverType()
MapperMethod.getMapKey()
MapperMethod.getUniqueParamIndex()
MapperMethod.getUniqueParamIndex()
ParamNameResolver.isSpecialParameter()
methodSignature创建完毕
MethodProxy.cachedMapperMethod()

MyBatis跟一般JDK动态代理的区别:

由于没有实现类,所以在Proxy对象执行invoke方法的时候实际没有调用真正的目标方法(UserMapper无实现类,故并无目标方法)。所有的逻辑直接在invoke方法中处理

三、根据SQL指令跳转执行语句

MapperMethod.execute()
MapperMethod.execute()
MapperMethod.execute()
MapperMethod.execute()
MapperMethod.execute()
MethodSignature.convertArgsToSqlCommandParam()
MethodSignature.convertArgsToSqlCommandParam()
ParamNameResolver.getNamesParams()
ParamNameResolver.getNamesParams()
ParamNameResolver.getNamesParams()
ParamNameResolver.getNamesParams()
ParamNameResolver.getNamesParams()
MapperMethod.execute()

四、查询前的缓存处理

DefaultSqlSession.selectOne() 
DefaultSqlSession.selectList() 
Configuration,getMappedStatement()
Configuration,buildAllStatements()
Configuration,getMappedStatement()
CachingExecutor.query()
MappedStatement.getBoundSql()
RowSqlSource.getBoundSql()
StaticSqlSource.getBoundSql()
MappedStatement.getBoundSql()
MappedStatement.getBoundSql()
MappedStatement.getBoundSql()
CachingExecutor.query()
CachingExecutor.createCacheKey()
BaseExecutor.createCacheKey()
BaseExecutor.createCacheKey()
CacheKey.update()
BaseExecutor.createCacheKey()
BaseExecutor.createCacheKey()
BaseExecutor.createCacheKey()
Configuration.newMetaObject()
MetaObject.forObject()
BaseExecutor.createCacheKey()
BaseExecutor.createCacheKey()
CachingExecutor.query()
CachingExecutor.query(重载方法)
CachingExecutor.query(重载方法)
BaseExecutor.query()
BaseExecutor.query()
BaseExecutor.query()

五、执行DB查询操作

BaseExecute.queryFromDatabase()
BaseExecute.queryFromDatabase()
SimpleExecutor.doQuery()
SimpleExecutor.doQuery()
Configuration.newStatementHandler()
SimpleExecutor.doQuery()
SimpleExecutor.prepareStatement()
SimpleExecutor.prepareStatement()
RoutingStatement.prepare()
BaseStatementHandler.prepare()
BaseStatementHandler.prepare()
PreparedStatementHandler.instantiateStatement()
PreparedStatementHandler.instantiateStatement()
BaseStatementHandler.prepare()
SimpleExecutor.prepareStatement() 
RoutingStatementHandler.parameterize()
PreparedStatementHandler.parameterize()
DefaultParameterHandler.setParameters()
DefaultParameterHandler.setParameters()
DefaultParameterHandler.setParameters()
DefaultParameterHandler.setParameters()
DefaultParameterHandler.setParameters()
DefaultParameterHandler.setParameters()
BaseTypeHandler.setParameter()
BaseTypeHandler.setParameter()
LongTypeHandler.setNonNullParameter()
SimpleExecutor.doQuery()
RoutingStatementHandler.query()
PreparedStatementHandler.query()

六、针对ResultSet结果集转换为POJO

PreparedStatementHandler.query()
DefaultResultSetHandler.handleResultSets()
DefaultResultSetHandler.handleResultSets()
DefaultResultSetHandler.getFirstResultSet()
DefaultResultSetHandler.getFirstResultSet()
DefaultResultSetHandler.getFirstResultSet()
DefaultResultSetHandler.getFirstResultSet()
DefaultResultSetHandler.handleResultSet()
DefaultResultSetHandler.handleResultSet()
DefaultResultSetHandler.handleRowValues()
DefaultResultSetHandler.handleRowValues()
DefaultResultSetHandler.handleRowValuesForSimpleResultMap()
DefaultResultSetHandler.skipRows()
DefaultResultSetHandler.skipRows()
DefaultResultSetHandler.handleRowValuesForSimpleResultMap()
DefaultResultSetHandler.handleRowValuesForSimpleResultMap()
DefaultResultSetHandler.handleRowValuesForSimpleResultMap()
DefaultResultSetHandler.getRowValue()
DefaultResultSetHandler.createResultObject()
DefaultResultSetHandler.createResultObject(重载方法)
DefaultResultSetHandler.createResultObject()
DefaultResultSetHandler.createResultObject()
DefaultResultSetHandler.createResultObject()
DefaultResultSetHandler.getRowValue()
DefaultResultSetHandler.getRowValue()
DefaultResultSetHandler.applyAutomaticMappings()
DefaultResultSetHandler.createAutomaticMappings()
DefaultResultSetHandler.createAutomaticMappings()
DefaultResultSetHandler.createAutomaticMappings()
DefaultResultSetHandler.createAutomaticMappings()
DefaultResultSetHandler.createAutomaticMappings()
DefaultResultSetHandler.applyAutomaticMappings()
DefaultResultSetHandler.applyAutomaticMappings()
DefaultResultSetHandler.applyAutomaticMappings()
DefaultResultSetHandler.applyAutomaticMappings()
DefaultResultSetHandler.getRowValue()
DefaultResultSetHandler.getRowValue()
DefaultResultSetHandler.handleRowValuesForSimpleResultMap()
DefaultResultSetHandler.storeObject()
DefaultResultSetHandler.callResultHandler()
DefaultResultSetHandler.handleResultSet()
DefaultResultSetHandler.handleResultSets()
DefaultResultSetHandler.collapseSingleResultList()

七、查询完毕返回结果

PreparedStatementHandler.query() 
BaseExecutor.queryFromDatabase()
BaseExecutor.queryFromDatabase()
BaseExecutor.queryFromDatabase()
CachingExecutor.query()
DefaultSqlSession.selectOne()
MapperMethod.execute()

你可能感兴趣的:(MyBatis(二))