Skip to content

Commit f7ccb0d

Browse files
committed
Remove "record" identifier as it is restricted in JDK16
1 parent d023ee8 commit f7ccb0d

File tree

20 files changed

+134
-104
lines changed

20 files changed

+134
-104
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Kotlin DSL.
101101
- Allow the "in when present" conditions to accept a null Collection as a parameter ([#346](https://github.com/mybatis/mybatis-dynamic-sql/pull/346))
102102
- Add Better Support for MyBatis Multi-Row Inserts that Return Generated Keys ([#349](https://github.com/mybatis/mybatis-dynamic-sql/pull/349))
103103
- Major improvement to the Kotlin DSL ([#353](https://github.com/mybatis/mybatis-dynamic-sql/pull/353))
104+
- Remove use of "record" as an identifier (it is restricted in JDK16)
104105

105106
## Release 1.2.1 - September 29, 2020
106107

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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 11 additions & 11 deletions
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

Lines changed: 10 additions & 10 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 17 additions & 7 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 20 additions & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy