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
2 changes: 1 addition & 1 deletion core/.mvn/extensions.xml
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
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 @@ -42,7 +42,6 @@ public KotlinFunctionAndImports generateMethodAndImports() {
KotlinFunction.newOneLineFunction(mapperName + ".deleteByPrimaryKey") //$NON-NLS-1$
.withCodeLine("delete {") //$NON-NLS-1$
.build())
.withImport("org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo") //$NON-NLS-1$
.build();

addFunctionComment(functionAndImports);
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 @@ -64,8 +64,8 @@ public KotlinFunctionAndImports generateMethodAndImports() {
functionAndImports.getImports().add(fieldNameAndImport.importString());

function.addCodeLine(" map(" + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ ").toProperty(\"" + column.getJavaProperty() //$NON-NLS-1$
+ "\")"); //$NON-NLS-1$
+ ") toProperty \"" + column.getJavaProperty() //$NON-NLS-1$
+ "\""); //$NON-NLS-1$
}

function.addCodeLine("}"); //$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 @@ -85,8 +85,8 @@ public KotlinFunctionAndImports generateMethodAndImports() {
functionAndImports.getImports().add(fieldNameAndImport.importString());

function.addCodeLine(" map(" + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ ").toProperty(\"" + column.getJavaProperty() //$NON-NLS-1$
+ "\")"); //$NON-NLS-1$
+ ") toProperty \"" + column.getJavaProperty() //$NON-NLS-1$
+ "\""); //$NON-NLS-1$
}

function.addCodeLine("}"); //$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 @@ -65,14 +65,14 @@ public KotlinFunctionParts getPrimaryKeyWhereClauseAndParameters() {
.withDataType(kt.getShortNameWithTypeArguments())
.build());
if (first) {
builder.withCodeLine(" where(" + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ ", isEqualTo(" + argName //$NON-NLS-1$
+ "))"); //$NON-NLS-1$
builder.withCodeLine(" where { " + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ " isEqualTo " + argName //$NON-NLS-1$
+ " }"); //$NON-NLS-1$
first = false;
} else {
builder.withCodeLine(" and(" + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ ", isEqualTo(" + argName //$NON-NLS-1$
+ "))"); //$NON-NLS-1$
builder.withCodeLine(" and { " + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ " isEqualTo " + argName //$NON-NLS-1$
+ " }"); //$NON-NLS-1$
}
}
builder.withCodeLine("}"); //$NON-NLS-1$
Expand All @@ -91,14 +91,14 @@ public KotlinFunctionParts getPrimaryKeyWhereClauseForUpdate() {

builder.withImport(fieldNameAndImport.importString());
if (first) {
builder.withCodeLine(" where(" + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ ", isEqualTo(row." + column.getJavaProperty() //$NON-NLS-1$
+ "!!))"); //$NON-NLS-1$
builder.withCodeLine(" where { " + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ " isEqualTo row." + column.getJavaProperty() //$NON-NLS-1$
+ "!! }"); //$NON-NLS-1$
first = false;
} else {
builder.withCodeLine(" and(" + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ ", isEqualTo(row." + column.getJavaProperty() //$NON-NLS-1$
+ "!!))"); //$NON-NLS-1$
builder.withCodeLine(" and {" + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ " isEqualTo row." + column.getJavaProperty() //$NON-NLS-1$
+ "!! }"); //$NON-NLS-1$
}
}
builder.withCodeLine("}"); //$NON-NLS-1$
Expand Down Expand Up @@ -224,8 +224,7 @@ public KotlinFunctionParts getSetEqualLines(List<IntrospectedColumn> columnList)
builder.withImport(fieldNameAndImport.importString());

builder.withCodeLine(" set(" + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ ").equalToOrNull(row::" + column.getJavaProperty() //$NON-NLS-1$
+ ")"); //$NON-NLS-1$
+ ") equalToOrNull row::" + column.getJavaProperty()); //$NON-NLS-1$
}

return builder.build();
Expand All @@ -243,8 +242,7 @@ public KotlinFunctionParts getSetEqualWhenPresentLines(List<IntrospectedColumn>
builder.withImport(fieldNameAndImport.importString());

builder.withCodeLine(" set(" + fieldNameAndImport.fieldName() //$NON-NLS-1$
+ ").equalToWhenPresent(row::" + column.getJavaProperty() //$NON-NLS-1$
+ ")"); //$NON-NLS-1$
+ ") equalToWhenPresent row::" + column.getJavaProperty()); //$NON-NLS-1$
}

return builder.build();
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 @@ -39,7 +39,6 @@ public KotlinFunctionAndImports generateMethodAndImports() {
KotlinFunction.newOneLineFunction(mapperName + ".selectByPrimaryKey") //$NON-NLS-1$
.withCodeLine("selectOne {") //$NON-NLS-1$
.build())
.withImport("org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo") //$NON-NLS-1$
.build();

addFunctionComment(functionAndImports);
Expand Down
10 changes: 8 additions & 2 deletions core/mybatis-generator-core/src/site/xhtml/index.xhtml
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 @@ -146,11 +146,17 @@ DatabaseMetaData interface, especially the <code>getColumns</code> and
<td>1.1.3+</td>
</tr>
<tr>
<td>MyBatis3DynamicSQL, MyBatis3Kotlin</td>
<td>MyBatis3DynamicSQL</td>
<td>1.4.1+</td>
<td>3.4.2+</td>
<td>1.3.1+</td>
</tr>
<tr>
<td>MyBatis3Kotlin</td>
<td>1.4.1+</td>
<td>3.4.2+</td>
<td>1.4.0+</td>
</tr>
</table>

<h2>Support</h2>
Expand Down
18 changes: 12 additions & 6 deletions core/mybatis-generator-core/src/site/xhtml/whatsNew.xhtml
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 All @@ -27,14 +27,15 @@
<h1>What's New in MyBatis Generator</h1>
<h2>Version 1.4.1</h2>
<p>This release is primarily focused on updating the runtimes for MyBatis Dynamic SQL ("MyBatis3DynamicSQL" and
"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 changes in this release:
"MyBatis3Kotlin"). The generated Java code is now dependent on MyBatis Dynamic SQL version 1.3.1 or later. The
generated Kotlin code is now dependent on MyBatis Dynamic SQL version 1.4.0 or later. See below for details about these
changes. See the GitHub page for milestone 1.4.1 for details other changes in this release:
<a target="_blank" href="https://github.com/mybatis/generator/issues?q=milestone%3A1.4.1">Milestone 1.4.1</a>.</p>

<h3>Updated MyBatis Dynamic SQL Runtimes</h3>
<p>The MyBatis3DynamicSQL and MyBatis3Kotlin runtimes have been updated to generate code that requires
version 1.3.1 or later of MyBatis Dynamic SQL. This should be a relatively minor change for most <b>Java</b> users
<p>The MyBatis3DynamicSQL and MyBatis3Kotlin runtimes have been updated to generate code that requires updated versions
of MyBatis Dynamic SQL. Generated Java code requires version 1.3.1 or later, generated Kotlin code requires version
1.4.0 or later. This should be a relatively minor change for most <b>Java</b> users
and should simply require updating the MyBatis Dynamic SQL version to 1.3.1 or later.</p>

<p>For both Java and Kotlin users, the new database model classes (a.k.a. the "support" classes) now extend
Expand Down Expand Up @@ -115,6 +116,11 @@ required:</p>
}
</pre>

<p>Lastly, the generated code uses upgraded DSL features that should be mostly transparent. But you will notice that any
"where" clauses you write will likely have deprecation warnings. This is due to a change in MyBatis Dynamic SQL. You
can read about remediation of these warnings in the documentation for that project.
</p>

<h3>Other Enhancements</h3>
<ul>
<li>Added capabilities to the SerializablePlugin for Kotlin</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 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 @@ -27,26 +27,19 @@ import java.sql.ResultSet
*/
class FirstNameTypeHandler : TypeHandler<FirstName> {

override fun getResult(cs: CallableStatement, columnIndex: Int): FirstName? {
val value = cs.getString(columnIndex)
return value?.let {makeFirstName(it)}
}
override fun getResult(cs: CallableStatement, columnIndex: Int): FirstName? =
cs.getString(columnIndex)?.toFirstName()

override fun getResult(rs: ResultSet, columnName: String): FirstName? {
val value = rs.getString(columnName)
return value?.let {makeFirstName(it)}
}
override fun getResult(rs: ResultSet, columnName: String): FirstName? =
rs.getString(columnName)?.toFirstName()

override fun getResult(rs: ResultSet, columnIndex: Int): FirstName? {
val value = rs.getString(columnIndex)
return value?.let {makeFirstName(it)}
}
override fun getResult(rs: ResultSet, columnIndex: Int): FirstName? =
rs.getString(columnIndex)?.toFirstName()

private fun makeFirstName(value: String): FirstName {
val answer = FirstName()
answer.value = value
return answer
}
private fun String.toFirstName(): FirstName =
FirstName().also {
it.value = this
}

override fun setParameter(ps: PreparedStatement, i: Int, parameter: FirstName?,
jdbcType: JdbcType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 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 All @@ -18,7 +18,6 @@ package mbg.test.mb3.common
import java.sql.CallableStatement
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.SQLException
import java.sql.Time
import java.util.Calendar

Expand All @@ -35,46 +34,36 @@ import org.apache.ibatis.type.TypeHandler
*/
class MyTimeTypeHandler : TypeHandler<MyTime> {

override fun getResult(cs: CallableStatement, columnIndex: Int): MyTime? {
val time = cs.getTime(columnIndex)
return time?.let { makeTime(it) }
}
override fun getResult(cs: CallableStatement, columnIndex: Int): MyTime? =
cs.getTime(columnIndex)?.toMyTime()

override fun getResult(rs: ResultSet, columnName: String): MyTime? {
val time = rs.getTime(columnName)
return time?.let { makeTime(it) }
}
override fun getResult(rs: ResultSet, columnName: String): MyTime? =
rs.getTime(columnName)?.toMyTime()

override fun getResult(rs: ResultSet, columnIndex: Int): MyTime? {
val time = rs.getTime(columnIndex)
return time?.let { makeTime(it) }
}
override fun getResult(rs: ResultSet, columnIndex: Int): MyTime? =
rs.getTime(columnIndex)?.toMyTime()

private fun makeTime(time: Time): MyTime {
val answer = MyTime()

val c = Calendar.getInstance()
c.time = time
private fun Time.toMyTime(): MyTime =
MyTime().also {
val c = Calendar.getInstance()
c.time = this

answer.hours = c.get(Calendar.HOUR_OF_DAY)
answer.minutes = c.get(Calendar.MINUTE)
answer.seconds = c.get(Calendar.SECOND)
return answer
}
it.hours = c.get(Calendar.HOUR_OF_DAY)
it.minutes = c.get(Calendar.MINUTE)
it.seconds = c.get(Calendar.SECOND)
}

override fun setParameter(ps: PreparedStatement, i: Int, parameter: MyTime?,
jdbcType: JdbcType) {
if (parameter == null) {
ps.setNull(i, jdbcType.TYPE_CODE)
} else {
val c = Calendar.getInstance()
c.set(Calendar.HOUR_OF_DAY, parameter.hours)
c.set(Calendar.MINUTE, parameter.minutes)
c.set(Calendar.SECOND, parameter.seconds)

val time = Time(c.time.time)

ps.setTime(i, time)
with(Calendar.getInstance()) {
set(Calendar.HOUR_OF_DAY, parameter.hours)
set(Calendar.MINUTE, parameter.minutes)
set(Calendar.SECOND, parameter.seconds)
ps.setTime(i, Time(timeInMillis))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 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 All @@ -18,31 +18,30 @@ package mbg.test.mb3.common
import java.sql.CallableStatement
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.SQLException

import org.apache.ibatis.type.JdbcType
import org.apache.ibatis.type.TypeHandler

class StringBooleanTypeHandler : TypeHandler<Boolean> {

override fun getResult(cs: CallableStatement, columnIndex: Int): Boolean? {
val s = cs.getString(columnIndex)
return "Y" == s
}
override fun getResult(cs: CallableStatement, columnIndex: Int): Boolean =
cs.getString(columnIndex).isTrue()

override fun getResult(rs: ResultSet, columnName: String): Boolean? {
val s = rs.getString(columnName)
return "Y" == s
}
override fun getResult(rs: ResultSet, columnName: String): Boolean =
rs.getString(columnName).isTrue()

override fun getResult(rs: ResultSet, columnIndex: Int): Boolean =
rs.getString(columnIndex).isTrue()

private fun String?.isTrue(): Boolean = this?.equals("Y")?: false

override fun setParameter(ps: PreparedStatement, columnIndex: Int, parameter: Boolean?,
jdbcType: JdbcType) {
val s = if (parameter == null) "N" else if (parameter) "Y" else "N"
val s = when(parameter) {
true -> "Y"
false -> "N"
null -> "N"
}
ps.setString(columnIndex, s)
}

override fun getResult(rs: ResultSet, columnIndex: Int): Boolean? {
val s = rs.getString(columnIndex)
return "Y" == s
}
}
Loading