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

Feature Request: template in generator configuration #973

Open
WestFarmer opened this issue Feb 20, 2023 · 4 comments
Open

Feature Request: template in generator configuration #973

WestFarmer opened this issue Feb 20, 2023 · 4 comments

Comments

@WestFarmer
Copy link

for example I have many table share same config like below:

<table catalog="" schema="" tableName="PMS_PLAN" domainObjectName="Plan">
	<property name="sea_locator" value="pms/plan" />
	<property name="rootClass" value="fwx.commons.model.InputUpdateMetaData" />
	<columnOverride column="IU" property="inputUser"></columnOverride>
	<columnOverride column="IO" property="inputOrg"></columnOverride>
	<columnOverride column="IT" property="inputTime"></columnOverride>
	<columnOverride column="UU" property="updateUser"></columnOverride>
	<columnOverride column="UO" property="updateOrg"></columnOverride>
	<columnOverride column="UT" property="updateTime"></columnOverride>
</table>

can we define a template like this:

<template id="commonProperties">
        <columnOverride column="IU" property="inputUser"></columnOverride>
	<columnOverride column="IO" property="inputOrg"></columnOverride>
	<columnOverride column="IT" property="inputTime"></columnOverride>
	<columnOverride column="UU" property="updateUser"></columnOverride>
	<columnOverride column="UO" property="updateOrg"></columnOverride>
	<columnOverride column="UT" property="updateTime"></columnOverride>
<template>

then reference it like this:

<table catalog="" schema="" tableName="PMS_PLAN" domainObjectName="Plan">
	<property name="sea_locator" value="pms/plan" />
	<property name="rootClass" value="fwx.commons.model.InputUpdateMetaData" />
	<templateRef id="commonProperties" />
</table>
@WestFarmer
Copy link
Author

for the xml dtd part, I think it will be easy to define a table template element which can have exact child elements of table element.

@WestFarmer
Copy link
Author

@jeffgbutler can you give me a hint which java class to work on, I want to contribute on this one .

@jeffgbutler
Copy link
Member

@WestFarmer I think this is a good idea. However, I suggest implementing it a bit differently because it might be difficult to lookup the templateref fragments with the current structure of the parser. I've thought about something like this:

<tableSet>
  <table tableName="foo"/>
  <table tableName="bar"/>
  <columnOverride column="IU" property="inputUser"/>
  <columnOverride column="IO" property="inputOrg"/>
  <columnOverride column="IT" property="inputTime"/>
  <columnOverride column="UU" property="updateUser"/>
  <columnOverride column="UO" property="updateOrg"/>
  <columnOverride column="UT" property="updateTime"/>
</tableSet>

What do you think of this idea?

The configuration parser is here: https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/config/xml/MyBatisGeneratorConfigurationParser.java

The DTD is here: https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/resources/org/mybatis/generator/config/xml/mybatis-generator-config_1_0.dtd

@WestFarmer
Copy link
Author

I think it's ok, will work on this.
@jeffgbutler

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