Skip to content

Commit 6060fc3

Browse files
committed
Merge branch 'master' into final-doc-updates
2 parents cb61b46 + bb0d1e4 commit 6060fc3

21 files changed

+137
-107
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Kotlin DSL.
125125
- Allow the "in when present" conditions to accept a null Collection as a parameter ([#346](https://github.com/mybatis/mybatis-dynamic-sql/pull/346))
126126
- Add Better Support for MyBatis Multi-Row Inserts that Return Generated Keys ([#349](https://github.com/mybatis/mybatis-dynamic-sql/pull/349))
127127
- Major improvement to the Kotlin DSL ([#353](https://github.com/mybatis/mybatis-dynamic-sql/pull/353))
128+
- Remove use of "record" as an identifier (it is restricted in JDK16) ([#357](https://github.com/mybatis/mybatis-dynamic-sql/pull/357))
128129

129130
## Release 1.2.1 - September 29, 2020
130131

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>org.mybatis</groupId>
2222
<artifactId>mybatis-parent</artifactId>
23-
<version>32</version>
23+
<version>33</version>
2424
</parent>
2525
<groupId>org.mybatis.dynamic-sql</groupId>
2626
<artifactId>mybatis-dynamic-sql</artifactId>
@@ -38,8 +38,8 @@
3838
<spring.batch.version>4.3.2</spring.batch.version>
3939
<clirr.comparisonVersion>1.2.0</clirr.comparisonVersion>
4040
<module.name>org.mybatis.dynamic.sql</module.name>
41-
<!-- Kotlin 1.5.0/IR Compiler must wait for Jacoco 0.8.7 -->
42-
<kotlin.version>1.4.32</kotlin.version>
41+
<kotlin.version>1.5.0</kotlin.version>
42+
<jacoco.version>0.8.7</jacoco.version>
4343
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
4444
<sonar.sources>pom.xml,src/main/java,src/main/kotlin</sonar.sources>
4545
<sonar.tests>src/test/java,src/test/kotlin</sonar.tests>

src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ static DeleteDSL<DeleteModel> deleteFrom(SqlTable table) {
128128
return DeleteDSL.deleteFrom(table);
129129
}
130130

131-
static <T> InsertDSL.IntoGatherer<T> insert(T record) {
132-
return InsertDSL.insert(record);
131+
static <T> InsertDSL.IntoGatherer<T> insert(T row) {
132+
return InsertDSL.insert(row);
133133
}
134134

135135
/**

src/main/java/org/mybatis/dynamic/sql/insert/InsertDSL.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,12 +32,12 @@
3232

3333
public class InsertDSL<T> implements Buildable<InsertModel<T>> {
3434

35-
private final T record;
35+
private final T row;
3636
private final SqlTable table;
3737
private final List<AbstractColumnMapping> columnMappings = new ArrayList<>();
3838

39-
private InsertDSL(T record, SqlTable table) {
40-
this.record = record;
39+
private InsertDSL(T row, SqlTable table) {
40+
this.row = row;
4141
this.table = table;
4242
}
4343

@@ -48,25 +48,25 @@ public <F> ColumnMappingFinisher<F> map(SqlColumn<F> column) {
4848
@NotNull
4949
@Override
5050
public InsertModel<T> build() {
51-
return InsertModel.withRecord(record)
51+
return InsertModel.withRow(row)
5252
.withTable(table)
5353
.withColumnMappings(columnMappings)
5454
.build();
5555
}
5656

57-
public static <T> IntoGatherer<T> insert(T record) {
58-
return new IntoGatherer<>(record);
57+
public static <T> IntoGatherer<T> insert(T row) {
58+
return new IntoGatherer<>(row);
5959
}
6060

6161
public static class IntoGatherer<T> {
62-
private final T record;
62+
private final T row;
6363

64-
private IntoGatherer(T record) {
65-
this.record = record;
64+
private IntoGatherer(T row) {
65+
this.row = row;
6666
}
6767

6868
public InsertDSL<T> into(SqlTable table) {
69-
return new InsertDSL<>(record, table);
69+
return new InsertDSL<>(row, table);
7070
}
7171
}
7272

src/main/java/org/mybatis/dynamic/sql/insert/InsertModel.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,21 +30,21 @@
3030

3131
public class InsertModel<T> {
3232
private final SqlTable table;
33-
private final T record;
33+
private final T row;
3434
private final List<AbstractColumnMapping> columnMappings;
3535

3636
private InsertModel(Builder<T> builder) {
3737
table = Objects.requireNonNull(builder.table);
38-
record = Objects.requireNonNull(builder.record);
38+
row = Objects.requireNonNull(builder.row);
3939
columnMappings = Objects.requireNonNull(builder.columnMappings);
4040
}
4141

4242
public <R> Stream<R> mapColumnMappings(Function<AbstractColumnMapping, R> mapper) {
4343
return columnMappings.stream().map(mapper);
4444
}
4545

46-
public T record() {
47-
return record;
46+
public T row() {
47+
return row;
4848
}
4949

5050
public SqlTable table() {
@@ -59,22 +59,22 @@ public InsertStatementProvider<T> render(RenderingStrategy renderingStrategy) {
5959
.render();
6060
}
6161

62-
public static <T> Builder<T> withRecord(T record) {
63-
return new Builder<T>().withRecord(record);
62+
public static <T> Builder<T> withRow(T row) {
63+
return new Builder<T>().withRow(row);
6464
}
6565

6666
public static class Builder<T> {
6767
private SqlTable table;
68-
private T record;
68+
private T row;
6969
private final List<AbstractColumnMapping> columnMappings = new ArrayList<>();
7070

7171
public Builder<T> withTable(SqlTable table) {
7272
this.table = table;
7373
return this;
7474
}
7575

76-
public Builder<T> withRecord(T record) {
77-
this.record = record;
76+
public Builder<T> withRow(T row) {
77+
this.row = row;
7878
return this;
7979
}
8080

src/main/java/org/mybatis/dynamic/sql/insert/render/BatchInsert.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,8 +41,8 @@ public List<InsertStatementProvider<T>> insertStatements() {
4141
.collect(Collectors.toList());
4242
}
4343

44-
private InsertStatementProvider<T> toInsertStatement(T record) {
45-
return DefaultInsertStatementProvider.withRecord(record)
44+
private InsertStatementProvider<T> toInsertStatement(T row) {
45+
return DefaultInsertStatementProvider.withRow(row)
4646
.withInsertStatement(insertStatement)
4747
.build();
4848
}

src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,38 +19,48 @@
1919

2020
public class DefaultInsertStatementProvider<T> implements InsertStatementProvider<T> {
2121
private final String insertStatement;
22+
// need to keep both row and record for now so we don't break
23+
// old code. The MyBatis reflection utilities don't handle
24+
// the case where the attribute name is different from the getter.
2225
private final T record;
26+
private final T row;
2327

2428
private DefaultInsertStatementProvider(Builder<T> builder) {
2529
insertStatement = Objects.requireNonNull(builder.insertStatement);
26-
record = Objects.requireNonNull(builder.record);
30+
row = Objects.requireNonNull(builder.row);
31+
record = row;
2732
}
2833

2934
@Override
3035
public T getRecord() {
3136
return record;
3237
}
3338

39+
@Override
40+
public T getRow() {
41+
return row;
42+
}
43+
3444
@Override
3545
public String getInsertStatement() {
3646
return insertStatement;
3747
}
3848

39-
public static <T> Builder<T> withRecord(T record) {
40-
return new Builder<T>().withRecord(record);
49+
public static <T> Builder<T> withRow(T row) {
50+
return new Builder<T>().withRow(row);
4151
}
4252

4353
public static class Builder<T> {
4454
private String insertStatement;
45-
private T record;
55+
private T row;
4656

4757
public Builder<T> withInsertStatement(String insertStatement) {
4858
this.insertStatement = insertStatement;
4959
return this;
5060
}
5161

52-
public Builder<T> withRecord(T record) {
53-
this.record = record;
62+
public Builder<T> withRow(T row) {
63+
this.row = row;
5464
return this;
5565
}
5666

src/main/java/org/mybatis/dynamic/sql/insert/render/InsertRenderer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ public InsertStatementProvider<T> render() {
4141
List<Optional<FieldAndValue>> fieldsAndValues = model.mapColumnMappings(m -> m.accept(visitor))
4242
.collect(Collectors.toList());
4343

44-
return DefaultInsertStatementProvider.withRecord(model.record())
44+
return DefaultInsertStatementProvider.withRow(model.row())
4545
.withInsertStatement(calculateInsertStatement(fieldsAndValues))
4646
.build();
4747
}

src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,26 @@
1616
package org.mybatis.dynamic.sql.insert.render;
1717

1818
public interface InsertStatementProvider<T> {
19+
/**
20+
* Return the row associated with this insert statement.
21+
*
22+
* @deprecated in favor of {@link InsertStatementProvider#getRow()}
23+
* @return the row associated with this insert statement.
24+
*/
25+
@Deprecated
1926
T getRecord();
2027

28+
/**
29+
* Return the row associated with this insert statement.
30+
*
31+
* @return the row associated with this insert statement.
32+
*/
33+
T getRow();
34+
35+
/**
36+
* Return the formatted insert statement.
37+
*
38+
* @return the formatted insert statement.
39+
*/
2140
String getInsertStatement();
2241
}

src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3Utils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ public static int deleteFrom(ToIntFunction<DeleteStatementProvider> mapper,
103103
return mapper.applyAsInt(deleteFrom(table, completer));
104104
}
105105

106-
public static <R> InsertStatementProvider<R> insert(R record, SqlTable table,
106+
public static <R> InsertStatementProvider<R> insert(R row, SqlTable table,
107107
UnaryOperator<InsertDSL<R>> completer) {
108-
return completer.apply(SqlBuilder.insert(record).into(table))
108+
return completer.apply(SqlBuilder.insert(row).into(table))
109109
.build()
110110
.render(RenderingStrategies.MYBATIS3);
111111
}
112112

113-
public static <R> int insert(ToIntFunction<InsertStatementProvider<R>> mapper, R record,
113+
public static <R> int insert(ToIntFunction<InsertStatementProvider<R>> mapper, R row,
114114
SqlTable table, UnaryOperator<InsertDSL<R>> completer) {
115-
return mapper.applyAsInt(insert(record, table, completer));
115+
return mapper.applyAsInt(insert(row, table, completer));
116116
}
117117

118118
public static GeneralInsertStatementProvider generalInsert(SqlTable table,

src/main/java/org/mybatis/dynamic/sql/util/spring/NamedParameterJdbcTemplateExtensions.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -90,7 +90,7 @@ public <T> int insert(Buildable<InsertModel<T>> insertStatement) {
9090

9191
public <T> int insert(InsertStatementProvider<T> insertStatement) {
9292
return template.update(insertStatement.getInsertStatement(),
93-
new BeanPropertySqlParameterSource(insertStatement.getRecord()));
93+
new BeanPropertySqlParameterSource(insertStatement.getRow()));
9494
}
9595

9696
public <T> int insert(Buildable<InsertModel<T>> insertStatement, KeyHolder keyHolder) {
@@ -99,7 +99,7 @@ public <T> int insert(Buildable<InsertModel<T>> insertStatement, KeyHolder keyHo
9999

100100
public <T> int insert(InsertStatementProvider<T> insertStatement, KeyHolder keyHolder) {
101101
return template.update(insertStatement.getInsertStatement(),
102-
new BeanPropertySqlParameterSource(insertStatement.getRecord()), keyHolder);
102+
new BeanPropertySqlParameterSource(insertStatement.getRow()), keyHolder);
103103
}
104104

105105
public <T> int[] insertBatch(Buildable<BatchInsertModel<T>> insertStatement) {

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/InsertStatements.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL
2222

2323
// These insert functions help avoid the use of org.mybatis.dynamic.sql.SqlBuilder in Kotlin
2424

25-
fun <T> insert(record: T): InsertDSL.IntoGatherer<T> = SqlBuilder.insert(record)
25+
fun <T> insert(row: T): InsertDSL.IntoGatherer<T> = SqlBuilder.insert(row)
2626

2727
fun <T> insertBatch(vararg records: T): BatchInsertDSL.IntoGatherer<T> = insertBatch(records.asList())
2828

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ fun deleteFrom(mapper: (DeleteStatementProvider) -> Int, table: SqlTable, comple
6969

7070
fun <T> insert(
7171
mapper: (InsertStatementProvider<T>) -> Int,
72-
record: T,
72+
row: T,
7373
table: SqlTable,
7474
completer: InsertCompleter<T>
7575
): Int =
76-
insert(record).into(table, completer).run(mapper)
76+
insert(row).into(table, completer).run(mapper)
7777

7878
fun <T> BatchInsert<T>.execute(mapper: (InsertStatementProvider<T>) -> Int): List<Int> =
7979
insertStatements().map(mapper)

0 commit comments

Comments
 (0)