【源码】MyBatis

 


 

mybatis-spring

public class SqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {
 
bean初始化
public void afterPropertiesSet() throws Exception {
        Assert.notNull(this.dataSource, "Property 'dataSource' is required");
        Assert.notNull(this.sqlSessionFactoryBuilder, "Property 'sqlSessionFactoryBuilder' is required");
        Assert.state(this.configuration == null && this.configLocation == null || this.configuration == null || this.configLocation == null, "Property 'configuration' and 'configLocation' can not specified with together");
        this.sqlSessionFactory = this.buildSqlSessionFactory();
    }
SqlSessionFactoryBuilder
 SqlSessionFactory build(Reader reader)

DefaultSqlSessionFactory

public class DefaultSqlSessionFactory implements SqlSessionFactory {
  public
SqlSession openSession(boolean autoCommit) { return this.openSessionFromDataSource(this.configuration.getDefaultExecutorType(), (TransactionIsolationLevel)null, autoCommit); }
// ..
}

DefaultSqlSession

public class DefaultSqlSession implements SqlSession {
    select
    selectList
    insert
    update  
   // ...
}

spring事件监听

public void onApplicationEvent(ApplicationEvent event) {
    if (this.failFast && event instanceof ContextRefreshedEvent) {
        this.sqlSessionFactory.getConfiguration().getMappedStatementNames();
    }
}

 

 

 

posted @ 2023-08-01 20:24  飞翔在天  阅读(2)  评论(0编辑  收藏  举报