MyBatisのソースコード解析(B):SQLSESSION

MyBatisのプロセス:

ここに画像を挿入説明

SQLSESSIONを取得2.

  • )(openSessionFromDataSourceを呼び出し、設定ファイルからExceutor(アクチュエータ)を削除
    ここに画像を挿入説明
  • アクチュエータデフォルトの新しいタイプ:SIMPLE
    ここに画像を挿入説明
  • アクチュエータの3つのタイプがあります。
    ここに画像を挿入説明
  • 注意:
    ここに画像を挿入説明
	executor = (Executor) interceptorChain.pluginAll(executor);

エグゼキュータは、ここで使用インターセプト強化された設計パターンにしたDecoratorパターン

  • その後返す:DefaultSqlSession(configuratioin、エグゼキュータ、業務上の問題)
    ExecutorのCRUD configuratioinの実行をここに画像を挿入説明

概要:SQLSESSIONを取得するプロセス

  • まずSqlSessionFactoryコールのOpenSession()
    SqlSession session = sessionFactory.openSession();
    
  • その後のOpenSession()呼び出しopenSessionFromDataSource()
     @Override
    public SqlSession openSession() {
      return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, false);
    }
    
  • 戻りDefaultSqlSessionオブジェクト、ノートDefaultSqlSessionは、次のとおりです(構成、エグゼキュータ、業務を)
    private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
    Transaction tx = null;
    try {
      final Environment environment = configuration.getEnvironment();
      final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
      tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
      //创建一个新的执行器,类型为execType
      final Executor executor = configuration.newExecutor(tx, execType);
      return new DefaultSqlSession(configuration, executor, autoCommit);
    } catch (Exception e) {
      closeTransaction(tx); // may have fetched a connection so lets call close()
      throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
    } finally {
      ErrorContext.instance().reset();
    }
    }
    
公開された47元の記事 ウォン称賛34 ビュー8873

おすすめ

転載: blog.csdn.net/weixin_42893085/article/details/105181855