タグ(スペースで区切っ):MyBatisの
アクチュエータの概要
- Tomcatのような、たかった、MyBatisのアクチュエータも存在するが、劣らず、複雑なアクチュエータのTomcat。
- アクチュエータは、キャッシュ、FlashStatementインタフェースをクリアし、トランザクションをロールバックし、トランザクションをコミットし、変更し、クエリを提供します。
- アクチュエータは、コンフィギュレーションによって作成されたSQLSESSION、に対応しています。
- 委託モード設計、BaseExecutor、SimpleExecutor、ReuseExecutor、CachingExecutorその実装クラスを使用してMyBatisのアクチュエータ。デリゲートオブジェクトは、その中核機能の実装によって達成される保持CachingExecutor。
- キャッシュ機能を実現するBaseExecutorベースでCachingExecutor。
- 簡単に言えばキュータは、データベースとの相互作用を実現しています。
ソース決意
- のは、MyBatisのの作成執行の過程を見てみましょう
実装プロセスは:openSessionFromDataSourceが子供の内部のOpenSession()メソッドで、MyBatisのはSQLSESSIONの作成において、エグゼキュータを新たにして、我々はまた、それSQLSESSIONがエグゼキュータを保持し、このように解釈することができます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);
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();
}
}
以下の通りであるnewExecutor openSessionFromDataSource方法コード:
public Executor newExecutor(Transaction transaction, ExecutorType executorType) {
executorType = executorType == null ? defaultExecutorType : executorType;
executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
Executor executor;
if (ExecutorType.BATCH == executorType) {
executor = new BatchExecutor(this, transaction);
} else if (ExecutorType.REUSE == executorType) {
executor = new ReuseExecutor(this, transaction);
} else {
executor = new SimpleExecutor(this, transaction);
}
if (cacheEnabled) {
executor = new CachingExecutor(executor);
}
executor = (Executor) interceptorChain.pluginAll(executor);
return executor;
}
newExecutor設定方法では、決意の種類に応じてexecutorTypeバッチ処理またはReuseExecutor、SimpleExecutordを生成することで
、cacheEnabledは、2つのキャッシュを有効にするかどうかを示します。デリゲートデリゲートオブジェクトはpluginAll変換方法で行われ、実際の実装オブジェクト、責任のinterceptorChainインターセプタチェーン、エグゼキュータは、そこCachingExecutorあり、最終エグゼキュータは、プロキシオブジェクトです。
PS:アクチュエータ、インターセプター、キャッシュは、3つの部分MyBatisの中で最も重要なです。
以下は、アクチュエータの委任モードからわかるように、クラス図MyBatisのアクチュエータです。