JDBC IndexStore
JdbcIndexStore は blocking JDBC database を R2D1 の asynchronous IndexStore SPI に適応します。document identifier と indexed field projection だけを保存し、authoritative serialized document は選択した DocumentStore に残します。
サポートする database
built-in dialect は正確な JDBC product name から選ばれます。他の product は schema mutation 前に失敗します。3つの JDBC driver は module に含まれず、DataSource が選んだ driver をアプリケーションが提供します。
| Database | サポートする topology |
|---|---|
| H2 | persistent embedded file、TCP server |
| HSQLDB | persistent embedded file、HSQL server |
| SQLite | local persistent embedded file のみ |
生成
アプリケーション所有の DataSource と blocking JDBC work 用の bounded execution resource を渡します。
implementation("dev.nexcraft:r2d1-jdbc:<version>")DataSource と execution の所有権
JdbcIndexStore は DataSource と JdbcExecution を所有・終了しません。JdbcExecution.create(...) が作成した executor は creator が閉じ、JdbcExecution.using(...) は caller-owned executor を閉じません。
DataSource dataSource = applicationDataSource;
try (JdbcExecution execution = JdbcExecution.create(4, 64)) {
JdbcIndexStore indexes = new JdbcIndexStore(dataSource, execution);
// Pass indexes and indexes::initialize to PersistenceCollectionFactory.
}Execution mode
デフォルトは platform thread です。Java 25 以上では virtual thread を明示的に選べ、暗黙の fallback はありません。maxConcurrency と maxPending は operation admission の制限であり、physical connection 数や pool を変更しません。
JdbcExecutionConfig config =
new JdbcExecutionConfig(JdbcExecutionMode.VIRTUAL_THREAD, 100, 500);
JdbcExecution execution = JdbcExecution.create(config);Schema と SQLite の境界
各 collection は document_id primary key と各 @Index field の required column を持つ table に対応します。対応する logical value は String、long/Long、double/Double、boolean/Boolean で、書き込み時に indexed value は non-null でなければなりません。
SQLite は local persistent file database のみで、remote SQLite service ではありません。1つの JdbcIndexStore instance 内では write を調整しますが、別 instance や外部 process は SQLite locking に従います。
