feat: allow DefaultSqlSessionFactory
to provide a custom SqlSession
#3128
+91
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Maintainers!
While extending
SqlSessionFactoryBuilder
allows users to fully customise their implementations ofSqlSessionFactory
andSqlSession
, the drawback is that you cannot use the safe defaults MyBatis provides anymore, which leaves two options:DefaultSqlSession
andDefaultSqlSessionFactory
, the drawbacks here are that you do not get upstream updates anymore and have to compare and update these files every release.I added a minimal test case which shows a structure that would allow the use of the defaults while providing important extension points.
Additionally, allow subclasses of
DefaultSqlSession
to callselectList(...)
, which allows providing a system wide result handler if user code did not specify one.I understand that this is definitely not a common use case, but believe the changes required are so minimal that it would provide a good tradeoff.
PS: note that the result handler is not the only reason here, we do quite some custom work (in our codebase) in the factory and session respectively.