From 721d38b4ed282a4e48b7580ee9cdb79127c10915 Mon Sep 17 00:00:00 2001
From: Jeff Butler
Date: Sun, 19 Dec 2021 09:41:42 -0500
Subject: [PATCH] MyBatis Dynamic SQL support classes now extend
AliasableSqlTable
This improves the code for self joins and makes the code a bit clearer
---
.../sql/DynamicSqlSupportClassGenerator.java | 10 ++++++----
.../KotlinDynamicSqlSupportClassGenerator.java | 7 ++++---
.../src/site/xhtml/index.xhtml | 2 +-
.../src/site/xhtml/whatsNew.xhtml | 16 +++++++++++-----
core/pom.xml | 2 +-
5 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlSupportClassGenerator.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlSupportClassGenerator.java
index 42bb2f6316..4a1c687feb 100644
--- a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlSupportClassGenerator.java
+++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlSupportClassGenerator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2020 the original author or authors.
+ * Copyright 2006-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ private TopLevelClass buildBasicClass() {
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
topLevelClass.setFinal(true);
topLevelClass.addImportedType(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlColumn")); //$NON-NLS-1$
- topLevelClass.addImportedType(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlTable")); //$NON-NLS-1$
+ topLevelClass.addImportedType(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.AliasableSqlTable")); //$NON-NLS-1$
topLevelClass.addImportedType(new FullyQualifiedJavaType("java.sql.JDBCType")); //$NON-NLS-1$
return topLevelClass;
}
@@ -76,14 +76,16 @@ private InnerClass buildInnerTableClass(TopLevelClass topLevelClass) {
innerClass.setVisibility(JavaVisibility.PUBLIC);
innerClass.setStatic(true);
innerClass.setFinal(true);
- innerClass.setSuperClass(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlTable")); //$NON-NLS-1$
+ innerClass.setSuperClass(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.AliasableSqlTable<" //$NON-NLS-1$
+ + fqjt.getShortName() + ">")); //$NON-NLS-1$
Method method = new Method(fqjt.getShortName());
method.setVisibility(JavaVisibility.PUBLIC);
method.setConstructor(true);
method.addBodyLine("super(\"" //$NON-NLS-1$
+ escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime())
- + "\");"); //$NON-NLS-1$
+ + "\", " + fqjt.getShortName() + "::new" //$NON-NLS-1$ //$NON-NLS-2$
+ + ");"); //$NON-NLS-1$
innerClass.addMethod(method);
commentGenerator.addClassAnnotation(innerClass, introspectedTable, topLevelClass.getImportedTypes());
diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/kotlin/KotlinDynamicSqlSupportClassGenerator.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/kotlin/KotlinDynamicSqlSupportClassGenerator.java
index f875efaf95..fe9381933a 100644
--- a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/kotlin/KotlinDynamicSqlSupportClassGenerator.java
+++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/kotlin/KotlinDynamicSqlSupportClassGenerator.java
@@ -111,7 +111,7 @@ private KotlinType buildOuterObject(KotlinFile kotlinFile, FullyQualifiedJavaTyp
KotlinType outerObject = KotlinType.newObject(type.getShortNameWithoutTypeArguments())
.build();
- kotlinFile.addImport("org.mybatis.dynamic.sql.SqlTable"); //$NON-NLS-1$
+ kotlinFile.addImport("org.mybatis.dynamic.sql.AliasableSqlTable"); //$NON-NLS-1$
kotlinFile.addImport("org.mybatis.dynamic.sql.util.kotlin.elements.column"); //$NON-NLS-1$
kotlinFile.addImport("java.sql.JDBCType"); //$NON-NLS-1$
kotlinFile.addNamedItem(outerObject);
@@ -123,9 +123,10 @@ private KotlinType buildInnerClass() {
String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
return KotlinType.newClass(domainObjectName)
- .withSuperType("SqlTable(\"" //$NON-NLS-1$
+ .withSuperType("AliasableSqlTable<" + domainObjectName +">(\"" //$NON-NLS-1$ //$NON-NLS-2$
+ escapeStringForKotlin(introspectedTable.getFullyQualifiedTableNameAtRuntime())
- + "\")") //$NON-NLS-1$
+ + "\", ::" + domainObjectName //$NON-NLS-1$
+ + ")") //$NON-NLS-1$
.build();
}
diff --git a/core/mybatis-generator-core/src/site/xhtml/index.xhtml b/core/mybatis-generator-core/src/site/xhtml/index.xhtml
index 0d87b14b47..a6b43a2dcc 100644
--- a/core/mybatis-generator-core/src/site/xhtml/index.xhtml
+++ b/core/mybatis-generator-core/src/site/xhtml/index.xhtml
@@ -149,7 +149,7 @@ DatabaseMetaData interface, especially the getColumns
and
MyBatis3DynamicSQL, MyBatis3Kotlin |
1.4.1+ |
3.4.2+ |
- 1.3.0+ |
+ 1.3.1+ |
diff --git a/core/mybatis-generator-core/src/site/xhtml/whatsNew.xhtml b/core/mybatis-generator-core/src/site/xhtml/whatsNew.xhtml
index fbe95d0bcf..644eacd80a 100644
--- a/core/mybatis-generator-core/src/site/xhtml/whatsNew.xhtml
+++ b/core/mybatis-generator-core/src/site/xhtml/whatsNew.xhtml
@@ -27,15 +27,21 @@
What's New in MyBatis Generator
Version 1.4.1
This release is primarily focused on updating the runtimes for MyBatis Dynamic SQL ("MyBatis3DynamicSQL" and
-"MyBatis3Kotlin"). The generated code is now dependant on MyBatis Dynamic SQL version 1.3.0 or later
+"MyBatis3Kotlin"). The generated code is now dependent on MyBatis Dynamic SQL version 1.3.1 or later
and makes use of newer features in that library. See below for details about that change.
-See the GitHub page for milestone 1.4.1 for details other other changes in this release:
+See the GitHub page for milestone 1.4.1 for details other changes in this release:
Milestone 1.4.1.
Updated MyBatis Dynamic SQL Runtimes
The MyBatis3DynamicSQL and MyBatis3Kotlin runtimes have been updated to generate code that requires
-version 1.3.0 or later of MyBatis Dynamic SQL. This should be a relatively minor change for most Java users
-and should simply require updating the MyBatis Dynamic SQL version to 1.3.0 or later.
+version 1.3.1 or later of MyBatis Dynamic SQL. This should be a relatively minor change for most Java users
+and should simply require updating the MyBatis Dynamic SQL version to 1.3.1 or later.
+
+For both Java and Kotlin users, the new database model classes (a.k.a. the "support" classes) now extend
+ AliasableSqlTable
. This allows you to specify a table alias directly within an instance
+ of a table class, rather than specifying the alias in a select statement. This can make the code a bit clearer
+ if you are doing a self join.
+
Differences for Kotlin users are more extensive. As a result of the changes detailed below, several plugin
methods related to the generated Kotlin files have changed or been deprecated. If a method has been deprecated,
@@ -60,7 +66,7 @@ This has the following benefits:
This update will require changes in existing code if you regenerate Kotlin code using this updated version.
-Generated Kotlin data classes no longer have the word "Record" appended to their names. Otherwise they are
+
Generated Kotlin data classes no longer have the word "Record" appended to their names. Otherwise, they are
the same. Your use of these classes will need to change. In most cases, you can simply remove the word "Record" from the
reference. For example, if you have a table named "Bar", you may see code like this:
diff --git a/core/pom.xml b/core/pom.xml
index 2b15ffecaf..14aca67fcd 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -273,7 +273,7 @@
org.mybatis.dynamic-sql
mybatis-dynamic-sql
- 1.3.0
+ 1.3.1
org.jetbrains.kotlin