Execution Context & Resolver
Giải thích cách MongoTemplateResolver chọn MongoExecutionContext theo key và DriverMongoExecutionContext cung cấp ranh giới database, session, mapping.
Hợp đồng MongoTemplateResolver
MongoTemplateResolver.java
javaReactiveMongoDsl<K>는 key마다 MongoExecutionContext를 가져옵니다. MongoExecutionContext가 MongoDatabase, ClientSession, collection naming, entity ↔ Document mapping과 save lifecycle hook의 경계를 담당합니다.
DriverMongoExecutionContext
기본 collection 이름은 entity simple class name을 decapitalize해서 결정합니다. 프로젝트의 실제 naming 규칙이 다르면 생성자에 collection-name resolver를 전달합니다.
Đặt tên Collection
Nếu tên collection cố định hoàn toàn trong suốt vòng đời ứng dụng, có thể sử dụng DriverMongoExecutionContext.cachedCollectionNameResolver(...). Không sử dụng helper cache cho resolver có tên thay đổi theo tenant/request/time.
Phạm vi Session và giao dịch
ClientSession được tạo ra trong getTxJob(...) chỉ được truyền qua MongoExecutionContext#getSessionScope() cho cùng một thực thi DSL. DriverMongoExecutionContext mặc định sử dụng MongoClient của riêng mình làm phạm vi session.