diff --git a/CHANGELOG.md b/CHANGELOG.md index d86bab92f..c3be3525d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,7 @@ Kotlin DSL. - Allow the "in when present" conditions to accept a null Collection as a parameter ([#346](https://github.com/mybatis/mybatis-dynamic-sql/pull/346)) - Add Better Support for MyBatis Multi-Row Inserts that Return Generated Keys ([#349](https://github.com/mybatis/mybatis-dynamic-sql/pull/349)) - Major improvement to the Kotlin DSL ([#353](https://github.com/mybatis/mybatis-dynamic-sql/pull/353)) +- Remove use of "record" as an identifier (it is restricted in JDK16) ([#357](https://github.com/mybatis/mybatis-dynamic-sql/pull/357)) ## Release 1.2.1 - September 29, 2020 diff --git a/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java b/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java index f7e342c4f..92cdd2d32 100644 --- a/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java +++ b/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java @@ -128,8 +128,8 @@ static DeleteDSL deleteFrom(SqlTable table) { return DeleteDSL.deleteFrom(table); } - static InsertDSL.IntoGatherer insert(T record) { - return InsertDSL.insert(record); + static InsertDSL.IntoGatherer insert(T row) { + return InsertDSL.insert(row); } /** diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/InsertDSL.java b/src/main/java/org/mybatis/dynamic/sql/insert/InsertDSL.java index 53e69e8ed..35321b222 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/InsertDSL.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/InsertDSL.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-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. @@ -32,12 +32,12 @@ public class InsertDSL implements Buildable> { - private final T record; + private final T row; private final SqlTable table; private final List columnMappings = new ArrayList<>(); - private InsertDSL(T record, SqlTable table) { - this.record = record; + private InsertDSL(T row, SqlTable table) { + this.row = row; this.table = table; } @@ -48,25 +48,25 @@ public ColumnMappingFinisher map(SqlColumn column) { @NotNull @Override public InsertModel build() { - return InsertModel.withRecord(record) + return InsertModel.withRow(row) .withTable(table) .withColumnMappings(columnMappings) .build(); } - public static IntoGatherer insert(T record) { - return new IntoGatherer<>(record); + public static IntoGatherer insert(T row) { + return new IntoGatherer<>(row); } public static class IntoGatherer { - private final T record; + private final T row; - private IntoGatherer(T record) { - this.record = record; + private IntoGatherer(T row) { + this.row = row; } public InsertDSL into(SqlTable table) { - return new InsertDSL<>(record, table); + return new InsertDSL<>(row, table); } } diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/InsertModel.java b/src/main/java/org/mybatis/dynamic/sql/insert/InsertModel.java index be5768672..6409fa8b6 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/InsertModel.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/InsertModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-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. @@ -30,12 +30,12 @@ public class InsertModel { private final SqlTable table; - private final T record; + private final T row; private final List columnMappings; private InsertModel(Builder builder) { table = Objects.requireNonNull(builder.table); - record = Objects.requireNonNull(builder.record); + row = Objects.requireNonNull(builder.row); columnMappings = Objects.requireNonNull(builder.columnMappings); } @@ -43,8 +43,8 @@ public Stream mapColumnMappings(Function mapper return columnMappings.stream().map(mapper); } - public T record() { - return record; + public T row() { + return row; } public SqlTable table() { @@ -59,13 +59,13 @@ public InsertStatementProvider render(RenderingStrategy renderingStrategy) { .render(); } - public static Builder withRecord(T record) { - return new Builder().withRecord(record); + public static Builder withRow(T row) { + return new Builder().withRow(row); } public static class Builder { private SqlTable table; - private T record; + private T row; private final List columnMappings = new ArrayList<>(); public Builder withTable(SqlTable table) { @@ -73,8 +73,8 @@ public Builder withTable(SqlTable table) { return this; } - public Builder withRecord(T record) { - this.record = record; + public Builder withRow(T row) { + this.row = row; return this; } diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/render/BatchInsert.java b/src/main/java/org/mybatis/dynamic/sql/insert/render/BatchInsert.java index c8026c445..a7faed0cf 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/render/BatchInsert.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/render/BatchInsert.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-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. @@ -41,8 +41,8 @@ public List> insertStatements() { .collect(Collectors.toList()); } - private InsertStatementProvider toInsertStatement(T record) { - return DefaultInsertStatementProvider.withRecord(record) + private InsertStatementProvider toInsertStatement(T row) { + return DefaultInsertStatementProvider.withRow(row) .withInsertStatement(insertStatement) .build(); } diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java b/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java index 2befbd327..9cdc67302 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-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. @@ -19,11 +19,16 @@ public class DefaultInsertStatementProvider implements InsertStatementProvider { private final String insertStatement; + // need to keep both row and record for now so we don't break + // old code. The MyBatis reflection utilities don't handle + // the case where the attribute name is different from the getter. private final T record; + private final T row; private DefaultInsertStatementProvider(Builder builder) { insertStatement = Objects.requireNonNull(builder.insertStatement); - record = Objects.requireNonNull(builder.record); + row = Objects.requireNonNull(builder.row); + record = row; } @Override @@ -31,26 +36,31 @@ public T getRecord() { return record; } + @Override + public T getRow() { + return row; + } + @Override public String getInsertStatement() { return insertStatement; } - public static Builder withRecord(T record) { - return new Builder().withRecord(record); + public static Builder withRow(T row) { + return new Builder().withRow(row); } public static class Builder { private String insertStatement; - private T record; + private T row; public Builder withInsertStatement(String insertStatement) { this.insertStatement = insertStatement; return this; } - public Builder withRecord(T record) { - this.record = record; + public Builder withRow(T row) { + this.row = row; return this; } diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertRenderer.java b/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertRenderer.java index dcfe66b31..5dbcc87b5 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertRenderer.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-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. @@ -41,7 +41,7 @@ public InsertStatementProvider render() { List> fieldsAndValues = model.mapColumnMappings(m -> m.accept(visitor)) .collect(Collectors.toList()); - return DefaultInsertStatementProvider.withRecord(model.record()) + return DefaultInsertStatementProvider.withRow(model.row()) .withInsertStatement(calculateInsertStatement(fieldsAndValues)) .build(); } diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java b/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java index c882522db..ab7620cf9 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-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. @@ -16,7 +16,26 @@ package org.mybatis.dynamic.sql.insert.render; public interface InsertStatementProvider { + /** + * Return the row associated with this insert statement. + * + * @deprecated in favor of {@link InsertStatementProvider#getRow()} + * @return the row associated with this insert statement. + */ + @Deprecated T getRecord(); + /** + * Return the row associated with this insert statement. + * + * @return the row associated with this insert statement. + */ + T getRow(); + + /** + * Return the formatted insert statement. + * + * @return the formatted insert statement. + */ String getInsertStatement(); } diff --git a/src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3Utils.java b/src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3Utils.java index a9068dd48..d6fb9e8eb 100644 --- a/src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3Utils.java +++ b/src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3Utils.java @@ -103,16 +103,16 @@ public static int deleteFrom(ToIntFunction mapper, return mapper.applyAsInt(deleteFrom(table, completer)); } - public static InsertStatementProvider insert(R record, SqlTable table, + public static InsertStatementProvider insert(R row, SqlTable table, UnaryOperator> completer) { - return completer.apply(SqlBuilder.insert(record).into(table)) + return completer.apply(SqlBuilder.insert(row).into(table)) .build() .render(RenderingStrategies.MYBATIS3); } - public static int insert(ToIntFunction> mapper, R record, + public static int insert(ToIntFunction> mapper, R row, SqlTable table, UnaryOperator> completer) { - return mapper.applyAsInt(insert(record, table, completer)); + return mapper.applyAsInt(insert(row, table, completer)); } public static GeneralInsertStatementProvider generalInsert(SqlTable table, diff --git a/src/main/java/org/mybatis/dynamic/sql/util/spring/NamedParameterJdbcTemplateExtensions.java b/src/main/java/org/mybatis/dynamic/sql/util/spring/NamedParameterJdbcTemplateExtensions.java index 8907684f7..2c2bd41d7 100644 --- a/src/main/java/org/mybatis/dynamic/sql/util/spring/NamedParameterJdbcTemplateExtensions.java +++ b/src/main/java/org/mybatis/dynamic/sql/util/spring/NamedParameterJdbcTemplateExtensions.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-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. @@ -90,7 +90,7 @@ public int insert(Buildable> insertStatement) { public int insert(InsertStatementProvider insertStatement) { return template.update(insertStatement.getInsertStatement(), - new BeanPropertySqlParameterSource(insertStatement.getRecord())); + new BeanPropertySqlParameterSource(insertStatement.getRow())); } public int insert(Buildable> insertStatement, KeyHolder keyHolder) { @@ -99,7 +99,7 @@ public int insert(Buildable> insertStatement, KeyHolder keyHo public int insert(InsertStatementProvider insertStatement, KeyHolder keyHolder) { return template.update(insertStatement.getInsertStatement(), - new BeanPropertySqlParameterSource(insertStatement.getRecord()), keyHolder); + new BeanPropertySqlParameterSource(insertStatement.getRow()), keyHolder); } public int[] insertBatch(Buildable> insertStatement) { diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/InsertStatements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/InsertStatements.kt index a9ceb5fd2..feecc6d86 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/InsertStatements.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/InsertStatements.kt @@ -22,7 +22,7 @@ import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL // These insert functions help avoid the use of org.mybatis.dynamic.sql.SqlBuilder in Kotlin -fun insert(record: T): InsertDSL.IntoGatherer = SqlBuilder.insert(record) +fun insert(row: T): InsertDSL.IntoGatherer = SqlBuilder.insert(row) fun insertBatch(vararg records: T): BatchInsertDSL.IntoGatherer = insertBatch(records.asList()) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt index 1359280cc..f7b1ec457 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt @@ -69,11 +69,11 @@ fun deleteFrom(mapper: (DeleteStatementProvider) -> Int, table: SqlTable, comple fun insert( mapper: (InsertStatementProvider) -> Int, - record: T, + row: T, table: SqlTable, completer: InsertCompleter ): Int = - insert(record).into(table, completer).run(mapper) + insert(row).into(table, completer).run(mapper) fun BatchInsert.execute(mapper: (InsertStatementProvider) -> Int): List = insertStatements().map(mapper) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt index c1ad39059..0bce0d734 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt @@ -76,18 +76,18 @@ fun NamedParameterJdbcTemplate.insertBatch(vararg records: T): BatchIn fun NamedParameterJdbcTemplate.insertBatch(records: List): BatchInsertHelper = BatchInsertHelper(records, this) -// single record insert +// single row insert fun NamedParameterJdbcTemplate.insert(insertStatement: InsertStatementProvider): Int = - update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement.record)) + update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement.row)) fun NamedParameterJdbcTemplate.insert( insertStatement: InsertStatementProvider, keyHolder: KeyHolder ): Int = - update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement.record), keyHolder) + update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement.row), keyHolder) -fun NamedParameterJdbcTemplate.insert(record: T): SingleRowInsertHelper = - SingleRowInsertHelper(record, this) +fun NamedParameterJdbcTemplate.insert(row: T): SingleRowInsertHelper = + SingleRowInsertHelper(row, this) // general insert fun NamedParameterJdbcTemplate.generalInsert(insertStatement: GeneralInsertStatementProvider): Int = @@ -102,7 +102,7 @@ fun NamedParameterJdbcTemplate.generalInsert( fun NamedParameterJdbcTemplate.insertInto(table: SqlTable, completer: GeneralInsertCompleter): Int = generalInsert(org.mybatis.dynamic.sql.util.kotlin.spring.insertInto(table, completer)) -// multiple record insert +// multiple row insert fun NamedParameterJdbcTemplate.insertMultiple(vararg records: T): MultiRowInsertHelper = insertMultiple(records.asList()) @@ -236,8 +236,8 @@ class KeyHolderHelper(private val keyHolder: KeyHolder, private val template: Na fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): Int = template.generalInsert(org.mybatis.dynamic.sql.util.kotlin.spring.insertInto(table, completer), keyHolder) - fun insert(record: T): SingleRowInsertWithKeyHolderHelper = - SingleRowInsertWithKeyHolderHelper(record, template, keyHolder) + fun insert(row: T): SingleRowInsertWithKeyHolderHelper = + SingleRowInsertWithKeyHolderHelper(row, template, keyHolder) fun insertMultiple(vararg records: T): MultiRowInsertWithKeyHolderHelper = insertMultiple(records.asList()) @@ -280,23 +280,23 @@ class MultiRowInsertWithKeyHolderHelper( @MyBatisDslMarker class SingleRowInsertHelper( - private val record: T, + private val row: T, private val template: NamedParameterJdbcTemplate ) { fun into(table: SqlTable, completer: InsertCompleter): Int = - with(insert(record).into(table, completer)) { + with(insert(row).into(table, completer)) { template.insert(this) } } @MyBatisDslMarker class SingleRowInsertWithKeyHolderHelper( - private val record: T, + private val row: T, private val template: NamedParameterJdbcTemplate, private val keyHolder: KeyHolder ) { fun into(table: SqlTable, completer: InsertCompleter): Int = - with(insert(record).into(table, completer)) { + with(insert(row).into(table, completer)) { template.insert(this, keyHolder) } } diff --git a/src/site/markdown/docs/insert.md b/src/site/markdown/docs/insert.md index 9e461a201..7aa5ca8a6 100644 --- a/src/site/markdown/docs/insert.md +++ b/src/site/markdown/docs/insert.md @@ -1,26 +1,26 @@ # Insert Statements The library will generate a variety of INSERT statements: -1. An insert for a single record -1. An insert for multiple records with a single statement -1. An insert for multiple records with a JDBC batch +1. An insert for a single row +1. An insert for multiple rows with a single statement +1. An insert for multiple rows with a JDBC batch 1. A general insert statement 1. An insert with a select statement -## Single Record Insert +## Single Row Insert A single record insert is a statement that inserts a single record into a table. This statement is configured differently than other statements in the library so that MyBatis' support for generated keys will work properly. To use the statement, you must first create an object that will map to the database row, then map object attributes to fields in the database. For example: ```java ... - SimpleTableRecord record = new SimpleTableRecord(); - record.setId(100); - record.setFirstName("Joe"); - record.setLastName("Jones"); - record.setBirthDate(new Date()); - record.setEmployed(true); - record.setOccupation("Developer"); - - InsertStatementProvider insertStatement = insert(record) + SimpleTableRecord row = new SimpleTableRecord(); + row.setId(100); + row.setFirstName("Joe"); + row.setLastName("Jones"); + row.setBirthDate(new Date()); + row.setEmployed(true); + row.setOccupation("Developer"); + + InsertStatementProvider insertStatement = insert(row) .into(simpleTable) .map(id).toProperty("id") .map(firstName).toProperty("firstName") @@ -43,7 +43,7 @@ Notice the `map` method. It is used to map a database column to an attribute of 4. `map(column).toProperty(property)` will insert a value from the record into a column. The value of the property will be bound to the SQL statement as a prepared statement parameter 5. `map(column).toPropertyWhenPresent(property, Supplier valueSupplier)` will insert a value from the record into a column if the value is non-null. The value of the property will be bound to the SQL statement as a prepared statement parameter. This is used to generate a "selective" insert as defined in MyBatis Generator. -### Annotated Mapper for Single Record Insert Statements +### Annotated Mapper for Single Row Insert Statements The InsertStatementProvider object can be used as a parameter to a MyBatis mapper method directly. If you are using an annotated mapper, the insert method should look like this (with @Options added for generated values if necessary): @@ -59,7 +59,7 @@ import org.mybatis.dynamic.sql.util.SqlProviderAdapter; ``` -### XML Mapper for Single Record Insert Statements +### XML Mapper for Single Row Insert Statements We do not recommend using an XML mapper for insert statements, but if you want to do so the InsertStatementProvider object can be used as a parameter to a MyBatis mapper method directly. If you are using an XML mapper, the insert method should look like this in the Java interface: @@ -82,17 +82,17 @@ The XML element should look like this (with attributes added for generated value ``` ### Generated Values -MyBatis supports returning generated values from a single record insert, or a batch insert. In either case, it is simply a matter of configuring the insert mapper method appropriately. For example, to retrieve the value of a calculated column configure your mapper method like this: +MyBatis supports returning generated values from a single row insert, or a batch insert. In either case, it is simply a matter of configuring the insert mapper method appropriately. For example, to retrieve the value of a calculated column configure your mapper method like this: ```java ... @InsertProvider(type=SqlProviderAdapter.class, method="insert") - @Options(useGeneratedKeys=true, keyProperty="record.fullName") + @Options(useGeneratedKeys=true, keyProperty="row.fullName") int insert(InsertStatementProvider insertStatement); ... ``` -The important thing is that the `keyProperty` is set correctly. It should always be in the form `record.` where `` is the attribute of the record class that should be updated with the generated value. +The important thing is that the `keyProperty` is set correctly. It should always be in the form `row.` where `` is the attribute of the record class that should be updated with the generated value. ## Multiple Row Insert Support A multiple row insert is a single insert statement that inserts multiple rows into a table. This can be a convenient way to insert a few rows into a table, but it has some limitations: diff --git a/src/site/markdown/docs/kotlinMyBatis3.md b/src/site/markdown/docs/kotlinMyBatis3.md index cee424fc2..2edfd510a 100644 --- a/src/site/markdown/docs/kotlinMyBatis3.md +++ b/src/site/markdown/docs/kotlinMyBatis3.md @@ -304,10 +304,10 @@ There is an extension method that can be used to delete all rows in a table: val rows = mapper.delete { allRows() } ``` -## Single Record Insert Statement +## Single Row Insert Statement ### Two-Step Method -Single record insert statements are constructed as shown on the Kotlin overview page. This method creates +Single row insert statements are constructed as shown on the Kotlin overview page. This method creates an `InsertStatementProvider` that can be executed with a MyBatis3 mapper method. MyBatis3 mappers should declare an `insert` method as follows: @@ -346,8 +346,8 @@ insert statement: ```kotlin import org.mybatis.dynamic.sql.util.kotlin.mybatis3.insert -fun PersonMapper.insert(record: PersonRecord) = - insert(this::insert, record, Person) { +fun PersonMapper.insert(row: PersonRecord) = + insert(this::insert, row, Person) { map(id).toProperty("id") map(firstName).toProperty("firstName") map(lastName).toProperty("lastName") @@ -376,13 +376,13 @@ configures generated key support. You cannot use the built-in base interface whe ```kotlin interface GeneratedAlwaysMapper { @InsertProvider(type = SqlProviderAdapter::class, method = "insert") - @Options(useGeneratedKeys = true, keyProperty = "record.id,record.fullName", keyColumn = "id,full_name") + @Options(useGeneratedKeys = true, keyProperty = "row.id,row.fullName", keyColumn = "id,full_name") fun insert(insertStatement: InsertStatementProvider): Int } ``` This method will return two generated values in each row: `id` and `full_name`. The values will be placed into the -record properties `id` and `fullName` respectively. +row properties `id` and `fullName` respectively. ## General Insert Statement ### Two-Step Method diff --git a/src/site/markdown/docs/kotlinOverview.md b/src/site/markdown/docs/kotlinOverview.md index 9baca2ff0..2debf7183 100644 --- a/src/site/markdown/docs/kotlinOverview.md +++ b/src/site/markdown/docs/kotlinOverview.md @@ -134,7 +134,7 @@ The library supports the following types of statements: statements support where clauses, joins, and subqueries. 1. Delete statement with or without a where clause. 1. Insert statements of various types: - 1. Single record insert - a statement where the insert values are obtained from a record class + 1. Single row insert - a statement where the insert values are obtained from a record class 1. General insert - a statement where the insert values are set directly in the statement 1. Multi-row Insert - a statement where the insert values are derived from a collection of records 1. Batch insert - a set of insert statements appropriate for use as a JDBC batch @@ -208,7 +208,7 @@ This method creates models or providers depending on which package is used: | org.mybatis.dynamic.sql.util.kotlin.mybatis3 | org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider (rendered for MyBatis3) | | org.mybatis.dynamic.sql.util.kotlin.spring | org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider (rendered for Spring) | -## Single Record Insert Statement +## Single Row Insert Statement This method support enables the creation of arbitrary insert statements given a class that matches a database row. If you do not with to create such a class, then see the general insert support following this section. @@ -226,15 +226,15 @@ data class PersonRecord( val addressId: Int ) -val record = PersonRecord(100, "Joe", "Jones", Date(), true, "Developer", 1) +val row = PersonRecord(100, "Joe", "Jones", Date(), true, "Developer", 1) -val insertRecordStatement = insert(record).into(person) { +val insertRecordStatement = insert(row).into(person) { map(id).toProperty("id") map(firstName).toProperty("firstName") map(lastName).toProperty("lastName") map(birthDate).toProperty("birthDate") map(employed).toProperty("employedAsString") - map(occupation).toPropertyWhenPresent("occupation", record::occupation) + map(occupation).toPropertyWhenPresent("occupation", row::occupation) map(addressId).toProperty("addressId") } ``` diff --git a/src/site/markdown/docs/kotlinSpring.md b/src/site/markdown/docs/kotlinSpring.md index 4af49c7b2..56d31de00 100644 --- a/src/site/markdown/docs/kotlinSpring.md +++ b/src/site/markdown/docs/kotlinSpring.md @@ -171,7 +171,7 @@ val rows = template.deleteFrom(person) { } ``` -## Single Record Insert Statement +## Single Row Insert Statement ### Two-Step Method Single record insert statements are constructed as shown on the Kotlin overview page. These methods create a @@ -194,15 +194,15 @@ val rows = template.insert(insertStatement, keyHolder) // rows is an Int Single record insert statements can be constructed and executed in a single step with code like the following: ```kotlin -val record = PersonRecord(100, "Joe", "Jones", Date(), true, "Developer", 1) +val row = PersonRecord(100, "Joe", "Jones", Date(), true, "Developer", 1) -val rows = template.insert(record).into(Person) { +val rows = template.insert(row).into(Person) { map(id).toProperty("id") map(firstName).toProperty("firstName") map(lastName).toProperty("lastName") map(birthDate).toProperty("birthDate") map(employed).toProperty("employedAsString") - map(occupation).toPropertyWhenPresent("occupation", record::occupation) + map(occupation).toPropertyWhenPresent("occupation", row::occupation) map(addressId).toProperty("addressId") } ``` @@ -214,16 +214,16 @@ Using a KeyHolder with the single step method looks like this: ```kotlin val keyHolder = GeneratedKeyHolder() -val record = PersonRecord(100, "Joe", "Jones", Date(), true, "Developer", 1) +val row = PersonRecord(100, "Joe", "Jones", Date(), true, "Developer", 1) val rows = template.withKeyHolder(keyHolder) { - insert(record).into(Person) { + insert(row).into(Person) { map(id).toProperty("id") map(firstName).toProperty("firstName") map(lastName).toProperty("lastName") map(birthDate).toProperty("birthDate") map(employed).toProperty("employedAsString") - map(occupation).toPropertyWhenPresent("occupation", record::occupation) + map(occupation).toPropertyWhenPresent("occupation", row::occupation) map(addressId).toProperty("addressId") } } diff --git a/src/site/markdown/docs/mybatis3.md b/src/site/markdown/docs/mybatis3.md index b82d528b6..e3ae2ab60 100644 --- a/src/site/markdown/docs/mybatis3.md +++ b/src/site/markdown/docs/mybatis3.md @@ -443,14 +443,14 @@ int rows = mapper.update(c -> It is also possible to write a utility method that will set values. For example: ```java -static UpdateDSL updateSelectiveColumns(PersonRecord record, +static UpdateDSL updateSelectiveColumns(PersonRecord row, UpdateDSL dsl) { - return dsl.set(id).equalToWhenPresent(record::getId) - .set(firstName).equalToWhenPresent(record::getFirstName) - .set(lastName).equalToWhenPresent(record::getLastName) - .set(birthDate).equalToWhenPresent(record::getBirthDate) - .set(employed).equalToWhenPresent(record::getEmployed) - .set(occupation).equalToWhenPresent(record::getOccupation); + return dsl.set(id).equalToWhenPresent(row::getId) + .set(firstName).equalToWhenPresent(row::getFirstName) + .set(lastName).equalToWhenPresent(row::getLastName) + .set(birthDate).equalToWhenPresent(row::getBirthDate) + .set(employed).equalToWhenPresent(row::getEmployed) + .set(occupation).equalToWhenPresent(row::getOccupation); } ``` diff --git a/src/site/markdown/docs/update.md b/src/site/markdown/docs/update.md index 67f00257c..eb1298515 100644 --- a/src/site/markdown/docs/update.md +++ b/src/site/markdown/docs/update.md @@ -3,7 +3,7 @@ Update statements are composed by specifying the table and columns to update, an ```java UpdateStatementProvider updateStatement = update(animalData) - .set(bodyWeight).equalTo(record.getBodyWeight()) + .set(bodyWeight).equalTo(row.getBodyWeight()) .set(animalName).equalToNull() .where(id, isIn(1, 5, 7)) .or(id, isIn(2, 6, 8), and(animalName, isLike("%bat"))) @@ -32,7 +32,7 @@ For example: ```java UpdateStatementProvider updateStatement = update(animalData) - .set(bodyWeight).equalTo(record.getBodyWeight()) + .set(bodyWeight).equalTo(row.getBodyWeight()) .set(animalName).equalToNull() .build() .render(RenderingStrategies.MYBATIS3); diff --git a/src/test/kotlin/examples/kotlin/mybatis3/canonical/GeneratedAlwaysMapper.kt b/src/test/kotlin/examples/kotlin/mybatis3/canonical/GeneratedAlwaysMapper.kt index 4be03f2b6..653d83d60 100644 --- a/src/test/kotlin/examples/kotlin/mybatis3/canonical/GeneratedAlwaysMapper.kt +++ b/src/test/kotlin/examples/kotlin/mybatis3/canonical/GeneratedAlwaysMapper.kt @@ -32,7 +32,7 @@ import org.mybatis.dynamic.sql.util.kotlin.mybatis3.insertMultipleWithGeneratedK interface GeneratedAlwaysMapper { @InsertProvider(type = SqlProviderAdapter::class, method = "insert") - @Options(useGeneratedKeys = true, keyProperty = "record.id,record.fullName", keyColumn = "id,full_name") + @Options(useGeneratedKeys = true, keyProperty = "row.id,row.fullName", keyColumn = "id,full_name") fun insert(insertStatement: InsertStatementProvider): Int @InsertProvider(type = SqlProviderAdapter::class, method = "generalInsert")