Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow DefaultSqlSessionFactory to provide a custom SqlSession #3128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

epochcoder
Copy link
Contributor

@epochcoder epochcoder commented Apr 3, 2024

Hi Maintainers!

While extending SqlSessionFactoryBuilder allows users to fully customise their implementations of SqlSessionFactory and SqlSession, the drawback is that you cannot use the safe defaults MyBatis provides anymore, which leaves two options:

  • Duplicate (copy/paste) DefaultSqlSession and DefaultSqlSessionFactory, the drawbacks here are that you do not get upstream updates anymore and have to compare and update these files every release.
  • Use reflection, the drawbacks here are that this is quite dirty and suffers from the same problems mentioned above.

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 call selectList(...), 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.

Additionally, allow subclasses of DefaultSqlSession to call `selectList(...)`
@coveralls
Copy link

Coverage Status

coverage: 87.168% (-0.008%) from 87.176%
when pulling c49bfc5 on epochcoder:feat/custom-sql-session-using-defaults
into 498c79c on mybatis:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants