Align keyColumn support in <generatedKey> tag#1309
Align keyColumn support in <generatedKey> tag#1309dparo wants to merge 1 commit intomybatis:masterfrom
Conversation
Standardize keyColumn handling in the <generatedKey> tag for the following MyBatis Generator targets: - KotlinMyBatis3Kotlin - MyBatis3DynamicSql - MyBatis3 ANNOTATEDMAPPER & MIXEDMAPPER This update brings their behavior in line with the existing implementation in the MyBatis3 XMLMAPPER generator (refer to AbstractXmlElementGenerator::buildInitialInsert).
There was a problem hiding this comment.
Pull Request Overview
Standardize keyColumn handling in the <generatedKey> tag across MyBatis Generator targets to match XMLMAPPER behavior.
- Append
keyColumnattribute to the@Optionsannotation usingOptionalandStringUtility.escapeString - Introduce necessary imports (
Optional,StringUtility) in Kotlin and dynamic SQL fragment generators - Update Java mapper generator to include the same
keyColumnlogic
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| KotlinFragmentGenerator.java | Added Optional import and appended , keyColumn="…" to @Options |
| FragmentGenerator.java | Added Optional import and appended , keyColumn="…" to @Options |
| AbstractJavaMapperMethodGenerator.java | Added StringUtility import and appended , keyColumn="…" to @Options |
Comments suppressed due to low confidence (3)
core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/kotlin/elements/KotlinFragmentGenerator.java:193
- Add or update tests to cover scenarios where
generatedKey.columnis provided and omitted, ensuring thekeyColumnattribute is correctly emitted or skipped.
sb.append(String.format(", keyColumn=\"%s\"", Optional.ofNullable(gk.getColumn()).map(StringUtility::escapeStringForKotlin).orElse("")));
core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/AbstractJavaMapperMethodGenerator.java:43
- Missing import for
java.util.Optional. Addimport java.util.Optional;so thatOptional.ofNullable(...)compiles.
import org.mybatis.generator.internal.util.StringUtility;
core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/kotlin/elements/KotlinFragmentGenerator.java:193
- [nitpick] Consider only appending the
, keyColumn="…"segment whengk.getColumn()is non-null and non-empty to avoid emitting an emptykeyColumnattribute.
sb.append(String.format(", keyColumn=\"%s\"", Optional.ofNullable(gk.getColumn()).map(StringUtility::escapeStringForKotlin).orElse("")));
|
@dparo - first, I want to apologize for taking to long to review this. This is a good idea and I appreciate the contribution. By the time I got to it, the underlying code had changed so much that this was no longer mergeable. Also, the impact was far greater than the places you found initially. I think I found at least six places in the code where there was duplicate logic and inconsistent behavior. So I want ahead and fixed it with a different pull request. Thanks for reporting this! |
Standardize keyColumn handling in the tag for the following MyBatis Generator targets:
This update brings their behavior in line with the existing implementation in the MyBatis3 XMLMAPPER generator (refer to AbstractXmlElementGenerator::buildInitialInsert).