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
7 changes: 6 additions & 1 deletion core/mybatis-generator-core/pom.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 Expand Up @@ -182,6 +182,11 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions core/mybatis-generator-core/src/site/site.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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 @@ -64,7 +64,7 @@
<item href="configreference/table.html" name="&amp;lt;table&amp;gt;" />
</item>
<item href="generatedobjects/results.html" name="Using the Generated Objects" collapse="true" >
<item href="generatedobjects/dynamicSqlV2.html" name="MyBatis Dynamic SQL Usage Notes" />
<item href="generatedobjects/dynamicSql.html" name="MyBatis Dynamic SQL Usage Notes" />
<item href="generatedobjects/dynamicSqlKotlin.html" name="MyBatis Dynamic SQL with Kotlin Usage Notes" />
<item href="generatedobjects/legacy.html" name="Legacy Generators">
<item href="generatedobjects/javamodel.html" name="Java Model Objects" />
Expand All @@ -73,7 +73,6 @@
<item href="generatedobjects/exampleClassUsage.html" name="Example Class Usage Notes" />
<item href="generatedobjects/extendingExampleClass.html" name="Extending the Example Classes" />
</item>
<item href="generatedobjects/dynamicSqlV1.html" name="MyBatis Dynamic SQL Usage Notes - V1 (Deprecated)" />
</item>
<item href="usage/intro.html" name="Database Specific Information" collapse="true" >
<item href="usage/db2.html" name="DB2" />
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 @@ -46,7 +46,7 @@ about how the library works.</p>
<li>Model classes are always generated in the "flat" model meaning there is no separate primary key class or BLOBs class</li>
<li>Java 8 or higher is required</li>
<li>MyBatis 3.4.2 or higher is required</li>
<li>MyBatis Dynamic SQL 1.1.3 or higher is required</li>
<li>MyBatis Dynamic SQL 1.3.1 or higher is required</li>
</ul>

<h2>Format of the "Support" classes</h2>
Expand All @@ -69,12 +69,12 @@ public final class TableCodeDynamicSqlSupport {
public static final SqlColumn&lt;Integer&gt; id = tableCode.id;
public static final SqlColumn&lt;String&gt; description = tableCode.description;

public static final class TableCode extends SqlTable {
public static final class TableCode extends AliasableSqlTable&lt;TableCode&gt; {
public final SqlColumn&lt;Integer&gt; id = column("ID", JDBCType.INTEGER);
public final SqlColumn&lt;String&gt; description = column("DESCRIPTION", JDBCType.VARCHAR);

public TableCode() {
super("MYSCHEMA.TABLE_CODE");
super("MYSCHEMA.TABLE_CODE", TableCode::new);
}
}
}
Expand All @@ -87,16 +87,17 @@ in either a direct or qualified manner - "id" or "tableCode.id".</p>
<h2>Usage of the Mapper Classes</h2>
<p>The following methods work the same as the other runtimes and we won't cover them here:</p>
<ul>
<li>Delete by Primary Key</li>
<li>Insert - will insert nulls</li>
<li>insert selective - ignores null properties</li>
<li>Select by Primary Key</li>
<li>Update by Primary Key - will set null values</li>
<li>Update by Primary Key Selective - ignores null values</li>
<li>deleteByPrimaryKey</li>
<li>insert - insert a single row (will insert nulls)</li>
<li>insertMultiple - insert multiple rows (will insert nulls)</li>
<li>insertSelective - insert a single row and ignore null properties</li>
<li>selectByPrimaryKey</li>
<li>updateByPrimaryKey - will set null values</li>
<li>updateByPrimaryKey Selective - ignores null values</li>
</ul>

<p>There are no "by example" methods. Instead, there are general purpose methods that allow you to specify a
where clause with a lambda. The generator will create the following general:</p>
where clause with a lambda. The generator will create the following general methods:</p>
<ul>
<li>count</li>
<li>delete</li>
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 @@ -33,15 +33,15 @@ about how the library works. In particular, see the
<a href="https://mybatis.org/mybatis-dynamic-sql/docs/kotlinMyBatis3.html">Kotlin Usage Page</a> for full details.</p>

<h2>Generated Files</h2>
<p>For each introspected table, the generator will generate four Kotlin files:</p>
<p>For each introspected table, the generator will generate three Kotlin files:</p>
<ol>
<li>A Kotlin data class that represents a row in the table. By default the class will be named based
<li>A Kotlin data class that represents a row in the table. By default, the class will be named based
on the table name</li>
<li>A "support" class that includes a table definition and column definitions for the database table</li>
<li>A mapper interface with the basic MyBatis mapper methods</li>
<li>A mapper extensions file with extension methods that simplify and reuse the methods in the basic interface.
This is similar to the default interface methods generated in the other runtimes, but it is accomplished
with extension methods in Kotlin. </li>
<li>A mapper interface with the basic MyBatis mapper methods and extension methods that simplify reuse of the basic
mapper methods. This is similar to the default interface methods generated in the other runtimes, but it is accomplished
with extension methods in Kotlin.
</li>
</ol>

<p>Important notes about the generated objects:</p>
Expand All @@ -54,7 +54,7 @@ about how the library works. In particular, see the
<li>Java 8 or higher is required</li>
<li>Any recent version of Kotlin should work</li>
<li>MyBatis 3.4.2 or higher is required</li>
<li>MyBatis Dynamic SQL 1.1.4 or higher is required</li>
<li>MyBatis Dynamic SQL 1.4.0 or higher is required</li>
</ul>

<h2>Format of the "Support" classes</h2>
Expand All @@ -69,15 +69,15 @@ will write.</p>
package example

import java.sql.JDBCType
import org.mybatis.dynamic.sql.SqlTable
import org.mybatis.dynamic.sql.AliasableSqlTable
import org.mybatis.dynamic.sql.util.kotlin.elements.column

object TableCodeDynamicSqlSupport {
val tableCode = TableCode()
val id = tableCode.id
val description = tableCode.description

class TableCode : SqlTable("MYSCHEMA.TABLE_CODE") {
class TableCode : AliasableSqlTable&lt;TableCode&gt;("MYSCHEMA.TABLE_CODE", ::TableCode) {
val id = column&lt;Int&gt;(name = "ID", jdbcType = JDBCType.INTEGER)
val description = column&lt;String&gt;(name = "DESCRIPTION", jdbcType = JDBCType.VARCHAR)
}
Expand All @@ -86,21 +86,22 @@ object TableCodeDynamicSqlSupport {

<p>In your code you can import that table object and/or each generated column (Kotlin does not support a star "*" import in this case).
With these imports you can refer to the fields
in either a direct or qualified manner - "id" or "TableCode.id".</p>
in either a direct or qualified manner - "id" or "tableCode.id".</p>

<h2>Usage of the Mapper Classes</h2>
<p>The following methods work the same as the other runtimes and we won't cover them here:</p>
<ul>
<li>Delete by Primary Key</li>
<li>Insert - will insert nulls</li>
<li>insert selective - ignores null properties</li>
<li>Select by Primary Key</li>
<li>Update by Primary Key - will set null values</li>
<li>Update by Primary Key Selective - ignores null values</li>
<li>deleteByPrimaryKey</li>
<li>insert - insert a single row (will insert nulls)</li>
<li>insertMultiple - insert multiple rows (will insert nulls)</li>
<li>insertSelective - insert a single row and ignore null properties</li>
<li>selectByPrimaryKey</li>
<li>updateByPrimaryKey - will set null values</li>
<li>updateByPrimaryKey Selective - ignores null values</li>
</ul>

<p>There are no "by example" methods. Instead, there are general purpose methods that allow you to specify a
where clause with a lambda. The generator will create the following general:</p>
where clause with a lambda. The generator will create the following general methods:</p>
<ul>
<li>count</li>
<li>delete</li>
Expand Down Expand Up @@ -133,20 +134,16 @@ complex where clauses, and "ORDER BY" phrases as shown below:</p>

<pre>
// import the generated "support" items...
import example.TableCodeDynamicSqlSupport.tableCode
import example.TableCodeDynamicSqlSupport.description
import example.TableCodeDynamicSqlSupport.id

// import MyBatis Dynamic SQL where support
import org.mybatis.dynamic.sql.SqlBuilder.*

class SomeService {

fun simpleWhere() {
...
// Simple WHERE clause
val records = mapper.select {
where(id, isEqualTo(3))
where { id isEqualTo 3 }
}
...
}
Expand All @@ -155,8 +152,8 @@ class SomeService {
...
// Simple WHERE clause with OR
val records = mapper.select {
where(id, isEqualTo(3))
or(description, isLike("f%"))
where { id isEqualTo 3 }
or { description isLike "f%" }
}
...
}
Expand All @@ -165,10 +162,11 @@ class SomeService {
...
// complex WHERE and ORDER BY
val records = mapper.select {
where(id, isLessThan(10)) {
and(description, isEqualTo("foo"))
where {
id isLessThan 10
and { description isEqualTo "foo" }
}
or(description, isLike("b%"))
or { description isLike "b%" }
orderBy(id.descending())
}
...
Expand All @@ -182,22 +180,18 @@ as well as updates that mimic the old updateByExample and updateByExampleSelecti

<pre>
// import the generated "support" items...
import example.TableCodeDynamicSqlSupport.tableCode
import example.TableCodeDynamicSqlSupport.description
import example.TableCodeDynamicSqlSupport.id

// import MyBatis Dynamic SQL where support
import org.mybatis.dynamic.sql.SqlBuilder.*

class SomeService {

fun simpleUpdate() {
...
// Flexible update - no backing record needed
val rows = mapper.update {
set(id).equalTo(1)
set(id) equalTo 1
set(description).equalToNull()
where(id, isEqualTo(3))
where { id isEqualTo 3 }
}
...
}
Expand All @@ -207,8 +201,8 @@ class SomeService {
// Update like the old updateByExample method
val rows = mapper.update {
updateAllColumns(row)
where(id, isEqualTo(3))
or(description, isLike("f%"))
where { id isEqualTo 3 }
or { description isLike "f%" }
}
...
}
Expand All @@ -218,8 +212,8 @@ class SomeService {
// Update like the old updateByExampleSelective method
val rows = mapper.update {
updateSelectiveColumns(row)
where(id, isEqualTo(3))
or(description, isLike("f%"))
where { id isEqualTo 3 }
or { description isLike "f%" }
}
...
}
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-2019 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,9 +50,9 @@ at GitHub then follow these steps:</p>
<a target="_blank" href="https://github.com/mybatis/generator">
https://github.com/mybatis/generator</a>
</li>
<li>Open a command window in the directory where you checked out the source and
run the command <code>mvn clean install</code> - or any of the other Maven lifecycle commands.
</li>
<li>Open a command window in the directory where you checked out the source</li>
<li><code>cd core</code></li>
<li>Run the command <code>mvn clean install</code> - or any of the other Maven lifecycle commands.</li>
</ol>


Expand Down
Loading