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

idea about make MBG more pluggable #1073

Open
ningpp opened this issue Oct 14, 2023 · 3 comments
Open

idea about make MBG more pluggable #1073

ningpp opened this issue Oct 14, 2023 · 3 comments

Comments

@ningpp
Copy link

ningpp commented Oct 14, 2023

current behavior:
targetRuntime determines what type of IntrospectedTable to create,
IntrospectedTable use generators to gen 'base' files.
eg. when targetRuntime = MyBatis3DynamicSql, IntrospectedTableMyBatis3DynamicSqlImpl
use DynamicSqlMapperGenerator, DynamicSqlSupportClassGenerator and DynamicSqlModelGenerator
to gen XxxModelMapper XxxModelDynamicSqlSupport and XxxModel

my idea is treat targetRuntime as an composite plugin
eg. when targetRuntime = MyBatis3DynamicSql mbg will use MyBatis3DynamicSqlCompositePlugn
to gen files, it actually use DynamicSqlMapperGeneratorPlugin,
DynamicSqlSupportClassGeneratorPlugin and DynamicSqlModelGeneratorPlugin to gen files.

what's next?

IntrospectedTable no longer need methods such as calculateGenerators, getGeneratedJavaFiles...

IntrospectedTable only store table metadata, Plugins for generate various files.

@jeffgbutler
Copy link
Member

@ningpp thanks for the idea. I've had similar ideas too - that the basic generator engine should just drive plugins. And IntrospectedTable is an example of the God Object Anti-Pattern. The generator could certainly have a better architecture.

The problem is compatibility. I think making a change like this would break every plugin - and I think there are quite a lot of plugins in use. It would need to be done in a version 2.0 that would break backwards compatibility.

I started a rewrite some time ago, but ultimately abandoned it when I started work on MyBatis Dynamic SQL. I'm not sure when or if I will get back to that.

If you have thoughts about the difficulties of backwards compatibility, I'm interested to hear them.

@ningpp
Copy link
Author

ningpp commented Oct 14, 2023

@jeffgbutler yes, backwards compatibility is very important.
i will give a try.

@ningpp
Copy link
Author

ningpp commented Oct 19, 2023

hi @jeffgbutler , i wrote a demo, can you give me some advices? ningpp@50de1a8

what did i do?
step 1: new IntrospectedTable implementation(it generates nothing)
step 2: add some Plugins to generate model, mapper, xml, etc (they use the existing generators to gen files)
step 3: add some tests( Compare the generated files to see if they are the same as the original way)

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

No branches or pull requests

2 participants