Skip to content

Remove "record" identifier as it is restricted in JDK16 #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ static DeleteDSL<DeleteModel> deleteFrom(SqlTable table) {
return DeleteDSL.deleteFrom(table);
}

static <T> InsertDSL.IntoGatherer<T> insert(T record) {
return InsertDSL.insert(record);
static <T> InsertDSL.IntoGatherer<T> insert(T row) {
return InsertDSL.insert(row);
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/mybatis/dynamic/sql/insert/InsertDSL.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -32,12 +32,12 @@

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

private final T record;
private final T row;
private final SqlTable table;
private final List<AbstractColumnMapping> columnMappings = new ArrayList<>();

private InsertDSL(T record, SqlTable table) {
this.record = record;
private InsertDSL(T row, SqlTable table) {
this.row = row;
this.table = table;
}

Expand All @@ -48,25 +48,25 @@ public <F> ColumnMappingFinisher<F> map(SqlColumn<F> column) {
@NotNull
@Override
public InsertModel<T> build() {
return InsertModel.withRecord(record)
return InsertModel.withRow(row)
.withTable(table)
.withColumnMappings(columnMappings)
.build();
}

public static <T> IntoGatherer<T> insert(T record) {
return new IntoGatherer<>(record);
public static <T> IntoGatherer<T> insert(T row) {
return new IntoGatherer<>(row);
}

public static class IntoGatherer<T> {
private final T record;
private final T row;

private IntoGatherer(T record) {
this.record = record;
private IntoGatherer(T row) {
this.row = row;
}

public InsertDSL<T> into(SqlTable table) {
return new InsertDSL<>(record, table);
return new InsertDSL<>(row, table);
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/mybatis/dynamic/sql/insert/InsertModel.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -30,21 +30,21 @@

public class InsertModel<T> {
private final SqlTable table;
private final T record;
private final T row;
private final List<AbstractColumnMapping> columnMappings;

private InsertModel(Builder<T> builder) {
table = Objects.requireNonNull(builder.table);
record = Objects.requireNonNull(builder.record);
row = Objects.requireNonNull(builder.row);
columnMappings = Objects.requireNonNull(builder.columnMappings);
}

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

public T record() {
return record;
public T row() {
return row;
}

public SqlTable table() {
Expand All @@ -59,22 +59,22 @@ public InsertStatementProvider<T> render(RenderingStrategy renderingStrategy) {
.render();
}

public static <T> Builder<T> withRecord(T record) {
return new Builder<T>().withRecord(record);
public static <T> Builder<T> withRow(T row) {
return new Builder<T>().withRow(row);
}

public static class Builder<T> {
private SqlTable table;
private T record;
private T row;
private final List<AbstractColumnMapping> columnMappings = new ArrayList<>();

public Builder<T> withTable(SqlTable table) {
this.table = table;
return this;
}

public Builder<T> withRecord(T record) {
this.record = record;
public Builder<T> withRow(T row) {
this.row = row;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -41,8 +41,8 @@ public List<InsertStatementProvider<T>> insertStatements() {
.collect(Collectors.toList());
}

private InsertStatementProvider<T> toInsertStatement(T record) {
return DefaultInsertStatementProvider.withRecord(record)
private InsertStatementProvider<T> toInsertStatement(T row) {
return DefaultInsertStatementProvider.withRow(row)
.withInsertStatement(insertStatement)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,38 +19,48 @@

public class DefaultInsertStatementProvider<T> implements InsertStatementProvider<T> {
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<T> builder) {
insertStatement = Objects.requireNonNull(builder.insertStatement);
record = Objects.requireNonNull(builder.record);
row = Objects.requireNonNull(builder.row);
record = row;
}

@Override
public T getRecord() {
return record;
}

@Override
public T getRow() {
return row;
}

@Override
public String getInsertStatement() {
return insertStatement;
}

public static <T> Builder<T> withRecord(T record) {
return new Builder<T>().withRecord(record);
public static <T> Builder<T> withRow(T row) {
return new Builder<T>().withRow(row);
}

public static class Builder<T> {
private String insertStatement;
private T record;
private T row;

public Builder<T> withInsertStatement(String insertStatement) {
this.insertStatement = insertStatement;
return this;
}

public Builder<T> withRecord(T record) {
this.record = record;
public Builder<T> withRow(T row) {
this.row = row;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -41,7 +41,7 @@ public InsertStatementProvider<T> render() {
List<Optional<FieldAndValue>> fieldsAndValues = model.mapColumnMappings(m -> m.accept(visitor))
.collect(Collectors.toList());

return DefaultInsertStatementProvider.withRecord(model.record())
return DefaultInsertStatementProvider.withRow(model.row())
.withInsertStatement(calculateInsertStatement(fieldsAndValues))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,7 +16,26 @@
package org.mybatis.dynamic.sql.insert.render;

public interface InsertStatementProvider<T> {
/**
* 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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ public static int deleteFrom(ToIntFunction<DeleteStatementProvider> mapper,
return mapper.applyAsInt(deleteFrom(table, completer));
}

public static <R> InsertStatementProvider<R> insert(R record, SqlTable table,
public static <R> InsertStatementProvider<R> insert(R row, SqlTable table,
UnaryOperator<InsertDSL<R>> completer) {
return completer.apply(SqlBuilder.insert(record).into(table))
return completer.apply(SqlBuilder.insert(row).into(table))
.build()
.render(RenderingStrategies.MYBATIS3);
}

public static <R> int insert(ToIntFunction<InsertStatementProvider<R>> mapper, R record,
public static <R> int insert(ToIntFunction<InsertStatementProvider<R>> mapper, R row,
SqlTable table, UnaryOperator<InsertDSL<R>> completer) {
return mapper.applyAsInt(insert(record, table, completer));
return mapper.applyAsInt(insert(row, table, completer));
}

public static GeneralInsertStatementProvider generalInsert(SqlTable table,
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -90,7 +90,7 @@ public <T> int insert(Buildable<InsertModel<T>> insertStatement) {

public <T> int insert(InsertStatementProvider<T> insertStatement) {
return template.update(insertStatement.getInsertStatement(),
new BeanPropertySqlParameterSource(insertStatement.getRecord()));
new BeanPropertySqlParameterSource(insertStatement.getRow()));
}

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

public <T> int insert(InsertStatementProvider<T> insertStatement, KeyHolder keyHolder) {
return template.update(insertStatement.getInsertStatement(),
new BeanPropertySqlParameterSource(insertStatement.getRecord()), keyHolder);
new BeanPropertySqlParameterSource(insertStatement.getRow()), keyHolder);
}

public <T> int[] insertBatch(Buildable<BatchInsertModel<T>> insertStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> insert(record: T): InsertDSL.IntoGatherer<T> = SqlBuilder.insert(record)
fun <T> insert(row: T): InsertDSL.IntoGatherer<T> = SqlBuilder.insert(row)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ fun deleteFrom(mapper: (DeleteStatementProvider) -> Int, table: SqlTable, comple

fun <T> insert(
mapper: (InsertStatementProvider<T>) -> Int,
record: T,
row: T,
table: SqlTable,
completer: InsertCompleter<T>
): Int =
insert(record).into(table, completer).run(mapper)
insert(row).into(table, completer).run(mapper)

fun <T> BatchInsert<T>.execute(mapper: (InsertStatementProvider<T>) -> Int): List<Int> =
insertStatements().map(mapper)
Expand Down
Loading