Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -95,7 +95,8 @@ protected enum InternalAttribute {
ATTR_MYBATIS3_UPDATE_BY_EXAMPLE_WHERE_CLAUSE_ID,
ATTR_MYBATIS3_SQL_PROVIDER_TYPE,
ATTR_MYBATIS_DYNAMIC_SQL_SUPPORT_TYPE,
ATTR_KOTLIN_RECORD_TYPE
ATTR_KOTLIN_RECORD_TYPE,
ATTR_MYBATIS_DYNAMIC_SQL_TABLE_OBJECT_NAME
}

protected TableConfiguration tableConfiguration;
Expand Down Expand Up @@ -646,6 +647,14 @@ public String getCountByExampleStatementId() {
.get(InternalAttribute.ATTR_COUNT_BY_EXAMPLE_STATEMENT_ID);
}

public String getMyBatisDynamicSQLTableObjectName() {
return internalAttributes.get(InternalAttribute.ATTR_MYBATIS_DYNAMIC_SQL_TABLE_OBJECT_NAME);
}

public void setMyBatisDynamicSQLTableObjectName(String name) {
internalAttributes.put(InternalAttribute.ATTR_MYBATIS_DYNAMIC_SQL_TABLE_OBJECT_NAME, name);
}

private boolean isSubPackagesEnabled(PropertyHolder propertyHolder) {
return isTrue(propertyHolder.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES));
}
Expand Down Expand Up @@ -725,6 +734,12 @@ protected void calculateJavaClientAttributes() {
sb.append("DynamicSqlSupport"); //$NON-NLS-1$
}
setMyBatisDynamicSqlSupportType(sb.toString());

if(stringHasValue(tableConfiguration.getDynamicSqlTableObjectName())) {
setMyBatisDynamicSQLTableObjectName(tableConfiguration.getDynamicSqlTableObjectName());
} else {
setMyBatisDynamicSQLTableObjectName(fullyQualifiedTable.getDomainObjectName());
}
}

protected String calculateJavaModelPackage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -50,6 +50,7 @@ private PropertyRegistry() {}
public static final String TABLE_MODEL_ONLY = "modelOnly"; //$NON-NLS-1$
public static final String TABLE_SELECT_ALL_ORDER_BY_CLAUSE = "selectAllOrderByClause"; //$NON-NLS-1$
public static final String TABLE_DYNAMIC_SQL_SUPPORT_CLASS_NAME = "dynamicSqlSupportClassName"; //$NON-NLS-1$
public static final String TABLE_DYNAMIC_SQL_TABLE_OBJECT_NAME = "dynamicSqlTableObjectName"; //$NON-NLS-1$

public static final String CONTEXT_BEGINNING_DELIMITER = "beginningDelimiter"; //$NON-NLS-1$
public static final String CONTEXT_ENDING_DELIMITER = "endingDelimiter"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -468,4 +468,8 @@ public void setSqlProviderName(String sqlProviderName) {
public String getDynamicSqlSupportClassName() {
return getProperty(PropertyRegistry.TABLE_DYNAMIC_SQL_SUPPORT_CLASS_NAME);
}

public String getDynamicSqlTableObjectName() {
return getProperty(PropertyRegistry.TABLE_DYNAMIC_SQL_TABLE_OBJECT_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -128,7 +128,7 @@ protected void preCalculate() {
recordType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
resultMapId = recordType.getShortNameWithoutTypeArguments() + "Result"; //$NON-NLS-1$
tableFieldName =
JavaBeansUtil.getValidPropertyName(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
JavaBeansUtil.getValidPropertyName(introspectedTable.getMyBatisDynamicSQLTableObjectName());
fragmentGenerator = new FragmentGenerator.Builder()
.withIntrospectedTable(introspectedTable)
.withResultMapId(resultMapId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -72,7 +72,7 @@ private TopLevelClass buildBasicClass() {

private InnerClass buildInnerTableClass(TopLevelClass topLevelClass) {
FullyQualifiedJavaType fqjt =
new FullyQualifiedJavaType(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
new FullyQualifiedJavaType(introspectedTable.getMyBatisDynamicSQLTableObjectName());
InnerClass innerClass = new InnerClass(fqjt.getShortName());
innerClass.setVisibility(JavaVisibility.PUBLIC);
innerClass.setStatic(true);
Expand All @@ -96,17 +96,17 @@ private InnerClass buildInnerTableClass(TopLevelClass topLevelClass) {

private Field calculateTableDefinition(TopLevelClass topLevelClass) {
FullyQualifiedJavaType fqjt =
new FullyQualifiedJavaType(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
new FullyQualifiedJavaType(introspectedTable.getMyBatisDynamicSQLTableObjectName());
String fieldName =
JavaBeansUtil.getValidPropertyName(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
JavaBeansUtil.getValidPropertyName(introspectedTable.getMyBatisDynamicSQLTableObjectName());
Field field = new Field(fieldName, fqjt);
commentGenerator.addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes());
field.setVisibility(JavaVisibility.PUBLIC);
field.setStatic(true);
field.setFinal(true);

String initializationString = String.format("new %s()", //$NON-NLS-1$
escapeStringForJava(introspectedTable.getFullyQualifiedTable().getDomainObjectName()));
escapeStringForJava(introspectedTable.getMyBatisDynamicSQLTableObjectName()));
field.setInitializationString(initializationString);
return field;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -120,7 +120,7 @@ private KotlinType buildOuterObject(KotlinFile kotlinFile, FullyQualifiedJavaTyp


private KotlinType buildInnerClass() {
String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
String domainObjectName = introspectedTable.getMyBatisDynamicSQLTableObjectName();

return KotlinType.newClass(domainObjectName)
.withSuperType("AliasableSqlTable<" + domainObjectName + ">(\"" //$NON-NLS-1$ //$NON-NLS-2$
Expand All @@ -131,9 +131,9 @@ private KotlinType buildInnerClass() {
}

private KotlinProperty calculateTableProperty() {
String tableType = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
String tableType = introspectedTable.getMyBatisDynamicSQLTableObjectName();
String fieldName =
JavaBeansUtil.getValidPropertyName(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
JavaBeansUtil.getValidPropertyName(introspectedTable.getMyBatisDynamicSQLTableObjectName());

return KotlinProperty.newVal(fieldName)
.withInitializationString(tableType + "()") //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2006-2021 the original author or authors.
Copyright 2006-2022 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.
Expand Down Expand Up @@ -345,6 +345,13 @@ specified with the <a href="property.html">&lt;property&gt;</a> child element:</
<p>Since version 1.4.1</p>
</td>
</tr>
<tr>
<td valign="top">dynamicSqlTableObjectName</td>
<td>The name to use for the inner class generated in support classes for MyBatis Dynamic SQL. If not
specified, the name will be the calculated domain object name (typically the table name). The value
if this property will be used as is for the inner class name (case-sensitive). An outer class
property name will also be calculated from this name (typically with the initial letter lower-cased).</td>
</tr>
<tr>
<td valign="top">ignoreQualifiersAtRuntime</td>
<td>If true, then
Expand Down
1 change: 1 addition & 0 deletions core/mybatis-generator-core/src/site/xhtml/whatsNew.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ required:</p>
<li>Added the ability to specify a package for MyBatis Dynamic SQL Support Classes</li>
<li>Added the ability to specify a MyBatis Dynamic SQL Support class name on the table configuration</li>
<li>Added a plugin to generate @CacheNamespace annotations</li>
<li>Added the ability to specify a name for the inner class generated in the MyBatis Dynamic SQL support class</li>
</ul>

<h3>Removed Items</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2006-2021 the original author or authors.
Copyright 2006-2022 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.
Expand Down Expand Up @@ -48,6 +48,7 @@
</table>
<table tableName="PKFields" alias="B" >
<property name="selectAllOrderByClause" value="ID1, ID2"/>
<property name="dynamicSqlTableObjectName" value="Pkfieldstable"/>
<columnOverride column="wierd$Field" delimitedColumnName="true"/>
<columnOverride column="stringBoolean" javaType="boolean" typeHandler="mbg.test.mb3.common.StringBooleanTypeHandler"/>
</table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2006-2021 the original author or authors.
Copyright 2006-2022 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.
Expand Down Expand Up @@ -47,6 +47,7 @@
</table>
<table tableName="PKFields" alias="B" >
<property name="selectAllOrderByClause" value="ID1, ID2"/>
<property name="dynamicSqlTableObjectName" value="Pkfieldstable"/>
<columnOverride column="wierd$Field" delimitedColumnName="true"/>
<columnOverride column="stringBoolean" javaType="boolean" typeHandler="mbg.test.mb3.common.StringBooleanTypeHandler"/>
</table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2006-2021 the original author or authors.
Copyright 2006-2022 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.
Expand Down Expand Up @@ -48,6 +48,7 @@
</table>
<table tableName="PKFields" alias="B" >
<property name="selectAllOrderByClause" value="ID1, ID2"/>
<property name="dynamicSqlTableObjectName" value="Pkfieldstable"/>
<columnOverride column="wierd$Field" delimitedColumnName="true"/>
<columnOverride column="stringBoolean" javaType="boolean" typeHandler="mbg.test.mb3.common.StringBooleanTypeHandler"/>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import mbg.test.mb3.generated.dsql.kotlin.mapper.AwfulTableDynamicSqlSupport.awf
import mbg.test.mb3.generated.dsql.kotlin.mapper.FieldsblobsDynamicSqlSupport.fieldsblobs
import mbg.test.mb3.generated.dsql.kotlin.mapper.FieldsonlyDynamicSqlSupport.fieldsonly
import mbg.test.mb3.generated.dsql.kotlin.mapper.PkblobsDynamicSqlSupport.pkblobs
import mbg.test.mb3.generated.dsql.kotlin.mapper.PkfieldsDynamicSqlSupport.pkfields
import mbg.test.mb3.generated.dsql.kotlin.mapper.PkfieldsDynamicSqlSupport.pkfieldstable
import mbg.test.mb3.generated.dsql.kotlin.mapper.PkfieldsblobsDynamicSqlSupport.pkfieldsblobs
import mbg.test.mb3.generated.dsql.kotlin.mapper.PkonlyDynamicSqlSupport.pkonly
import mbg.test.mb3.generated.dsql.kotlin.mapper.mbgtest.*
Expand Down Expand Up @@ -464,7 +464,7 @@ class DynamicSqlTest : AbstractTest() {
assertThat(answer).hasSize(2)

val rows = mapper.delete {
where { pkfields.lastname isLike "J%" }
where { pkfieldstable.lastname isLike "J%" }
}
assertThat(rows).isEqualTo(1)

Expand Down Expand Up @@ -506,8 +506,8 @@ class DynamicSqlTest : AbstractTest() {
mapper.insert(Pkfields(id1 = 2, id2 = 3, firstname = "Bamm Bamm", lastname = "Rubble"))

val answer = mapper.select {
where { pkfields.firstname isLike "B%" }
orderBy(pkfields.id1, pkfields.id2)
where { pkfieldstable.firstname isLike "B%" }
orderBy(pkfieldstable.id1, pkfieldstable.id2)
}

assertThat(answer).hasSize(3)
Expand All @@ -532,8 +532,8 @@ class DynamicSqlTest : AbstractTest() {
mapper.insert(Pkfields(id1 = 2, id2 = 3, firstname = "Bamm Bamm", lastname = "Rubble"))

val answer = mapper.select {
where { pkfields.firstname isNotLike "B%" }
orderBy(pkfields.id1, pkfields.id2)
where { pkfieldstable.firstname isNotLike "B%" }
orderBy(pkfieldstable.id1, pkfieldstable.id2)
}

assertThat(answer).hasSize(3)
Expand All @@ -559,11 +559,11 @@ class DynamicSqlTest : AbstractTest() {

val answer = mapper.select {
where {
pkfields.firstname isLike "B%"
and { pkfields.id2 isEqualTo 3 }
pkfieldstable.firstname isLike "B%"
and { pkfieldstable.id2 isEqualTo 3 }
}
or { pkfields.firstname isLike "Wi%" }
orderBy(pkfields.id1, pkfields.id2)
or { pkfieldstable.firstname isLike "Wi%" }
orderBy(pkfieldstable.id1, pkfieldstable.id2)
}

assertThat(answer).hasSize(2)
Expand All @@ -586,8 +586,8 @@ class DynamicSqlTest : AbstractTest() {
mapper.insert(Pkfields(id1 = 2, id2 = 3, firstname = "Bamm Bamm", lastname = "Rubble"))

val answer = mapper.select {
where { pkfields.id2.isIn(1, 3) }
orderBy(pkfields.id1, pkfields.id2)
where { pkfieldstable.id2.isIn(1, 3) }
orderBy(pkfieldstable.id1, pkfieldstable.id2)
}

assertThat(answer).hasSize(4)
Expand All @@ -614,8 +614,8 @@ class DynamicSqlTest : AbstractTest() {
mapper.insert(Pkfields(id1 = 2, id2 = 3, firstname = "Bamm Bamm", lastname = "Rubble"))

val answer = mapper.select {
where { pkfields.id2 isBetween 1 and 3 }
orderBy(pkfields.id1, pkfields.id2)
where { pkfieldstable.id2 isBetween 1 and 3 }
orderBy(pkfieldstable.id1, pkfieldstable.id2)
}
assertThat(answer).hasSize(6)
}
Expand All @@ -634,7 +634,7 @@ class DynamicSqlTest : AbstractTest() {

val answer = mapper.select {
allRows()
orderBy(pkfields.id1, pkfields.id2)
orderBy(pkfieldstable.id1, pkfieldstable.id2)
}

assertThat(answer).hasSize(6)
Expand All @@ -659,7 +659,7 @@ class DynamicSqlTest : AbstractTest() {

val answer = mapper.select {
allRows()
orderBy(pkfields.id1, pkfields.id2)
orderBy(pkfieldstable.id1, pkfieldstable.id2)
}

assertThat(answer).hasSize(6)
Expand All @@ -678,9 +678,9 @@ class DynamicSqlTest : AbstractTest() {
mapper.insert(Pkfields(id1 = 2, id2 = 3, firstname = "Bamm Bamm", lastname = "Rubble", wierdField = 66))

val answer = mapper.select {
where { pkfields.wierdField isLessThan 40 }
and { pkfields.wierdField.isIn(11, 22) }
orderBy(pkfields.id1, pkfields.id2)
where { pkfieldstable.wierdField isLessThan 40 }
and { pkfieldstable.wierdField.isIn(11, 22) }
orderBy(pkfieldstable.id1, pkfieldstable.id2)
}

assertThat(answer).hasSize(2)
Expand All @@ -695,7 +695,7 @@ class DynamicSqlTest : AbstractTest() {
mapper.insert(Pkfields(id1 = 3, id2 = 4, firstname = "Bob", lastname = "Jones"))

var rows = mapper.count {
where { pkfields.lastname isLike "J%" }
where { pkfieldstable.lastname isLike "J%" }
}

assertThat(rows).isEqualTo(1)
Expand Down
Loading