Skip to content

Commit 2269855

Browse files
committed
Simplify the hierarchy for column mappings.
We now have a single visitor interface with default methods where appropriate.
1 parent 764e82f commit 2269855

32 files changed

+126
-273
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@
2424
import java.util.stream.Stream;
2525

2626
import org.mybatis.dynamic.sql.SqlTable;
27-
import org.mybatis.dynamic.sql.util.InsertMapping;
27+
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
2828

2929
public abstract class AbstractMultiRowInsertModel<T> {
3030
private SqlTable table;
3131
private List<T> records;
32-
private List<InsertMapping> columnMappings;
32+
private List<AbstractColumnMapping> columnMappings;
3333

3434
protected AbstractMultiRowInsertModel(AbstractBuilder<T, ?> builder) {
3535
table = Objects.requireNonNull(builder.table);
3636
records = Collections.unmodifiableList(Objects.requireNonNull(builder.records));
3737
columnMappings = Objects.requireNonNull(builder.columnMappings);
3838
}
3939

40-
public <R> Stream<R> mapColumnMappings(Function<InsertMapping, R> mapper) {
40+
public <R> Stream<R> mapColumnMappings(Function<AbstractColumnMapping, R> mapper) {
4141
return columnMappings.stream().map(mapper);
4242
}
4343

@@ -56,7 +56,7 @@ public int recordCount() {
5656
public abstract static class AbstractBuilder<T, S extends AbstractBuilder<T, S>> {
5757
private SqlTable table;
5858
private List<T> records = new ArrayList<>();
59-
private List<InsertMapping> columnMappings = new ArrayList<>();
59+
private List<AbstractColumnMapping> columnMappings = new ArrayList<>();
6060

6161
public S withTable(SqlTable table) {
6262
this.table = table;
@@ -68,7 +68,7 @@ public S withRecords(Collection<T> records) {
6868
return getThis();
6969
}
7070

71-
public S withColumnMappings(List<InsertMapping> columnMappings) {
71+
public S withColumnMappings(List<AbstractColumnMapping> columnMappings) {
7272
this.columnMappings.addAll(columnMappings);
7373
return getThis();
7474
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
import org.mybatis.dynamic.sql.SqlColumn;
2424
import org.mybatis.dynamic.sql.SqlTable;
25+
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
2526
import org.mybatis.dynamic.sql.util.ConstantMapping;
26-
import org.mybatis.dynamic.sql.util.InsertMapping;
2727
import org.mybatis.dynamic.sql.util.NullMapping;
2828
import org.mybatis.dynamic.sql.util.PropertyMapping;
2929
import org.mybatis.dynamic.sql.util.StringConstantMapping;
@@ -32,7 +32,7 @@ public class BatchInsertDSL<T> {
3232

3333
private Collection<T> records;
3434
private SqlTable table;
35-
private List<InsertMapping> columnMappings = new ArrayList<>();
35+
private List<AbstractColumnMapping> columnMappings = new ArrayList<>();
3636

3737
private BatchInsertDSL(Collection<T> records, SqlTable table) {
3838
this.records = records;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
import org.mybatis.dynamic.sql.SqlColumn;
2424
import org.mybatis.dynamic.sql.SqlTable;
2525
import org.mybatis.dynamic.sql.select.SelectModel;
26+
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
2627
import org.mybatis.dynamic.sql.util.Buildable;
2728
import org.mybatis.dynamic.sql.util.ConstantMapping;
28-
import org.mybatis.dynamic.sql.util.GeneralInsertMapping;
2929
import org.mybatis.dynamic.sql.util.NullMapping;
3030
import org.mybatis.dynamic.sql.util.SelectMapping;
3131
import org.mybatis.dynamic.sql.util.StringConstantMapping;
3232
import org.mybatis.dynamic.sql.util.ValueMapping;
3333

3434
public class GeneralInsertDSL {
35-
private List<GeneralInsertMapping> insertMappings = new ArrayList<>();
35+
private List<AbstractColumnMapping> insertMappings = new ArrayList<>();
3636
private SqlTable table;
3737

3838
private GeneralInsertDSL(SqlTable table) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525
import org.mybatis.dynamic.sql.insert.render.GeneralInsertRenderer;
2626
import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider;
2727
import org.mybatis.dynamic.sql.render.RenderingStrategy;
28-
import org.mybatis.dynamic.sql.util.GeneralInsertMapping;
28+
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
2929

3030
public class GeneralInsertModel {
3131

3232
private SqlTable table;
33-
private List<GeneralInsertMapping> insertMappings;
33+
private List<AbstractColumnMapping> insertMappings;
3434

3535
private GeneralInsertModel(Builder builder) {
3636
table = Objects.requireNonNull(builder.table);
3737
insertMappings = builder.insertMappings;
3838
}
3939

40-
public <R> Stream<R> mapColumnMappings(Function<GeneralInsertMapping, R> mapper) {
40+
public <R> Stream<R> mapColumnMappings(Function<AbstractColumnMapping, R> mapper) {
4141
return insertMappings.stream().map(mapper);
4242
}
4343

@@ -54,14 +54,14 @@ public GeneralInsertStatementProvider render(RenderingStrategy renderingStrategy
5454

5555
public static class Builder {
5656
private SqlTable table;
57-
private List<GeneralInsertMapping> insertMappings = new ArrayList<>();
57+
private List<AbstractColumnMapping> insertMappings = new ArrayList<>();
5858

5959
public Builder withTable(SqlTable table) {
6060
this.table = table;
6161
return this;
6262
}
6363

64-
public Builder withInsertMappings(List<GeneralInsertMapping> insertMappings) {
64+
public Builder withInsertMappings(List<AbstractColumnMapping> insertMappings) {
6565
this.insertMappings.addAll(insertMappings);
6666
return this;
6767
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2019 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.
@@ -21,8 +21,8 @@
2121

2222
import org.mybatis.dynamic.sql.SqlColumn;
2323
import org.mybatis.dynamic.sql.SqlTable;
24+
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
2425
import org.mybatis.dynamic.sql.util.ConstantMapping;
25-
import org.mybatis.dynamic.sql.util.InsertMapping;
2626
import org.mybatis.dynamic.sql.util.NullMapping;
2727
import org.mybatis.dynamic.sql.util.PropertyMapping;
2828
import org.mybatis.dynamic.sql.util.StringConstantMapping;
@@ -31,7 +31,7 @@ public class InsertDSL<T> {
3131

3232
private T record;
3333
private SqlTable table;
34-
private List<InsertMapping> columnMappings = new ArrayList<>();
34+
private List<AbstractColumnMapping> columnMappings = new ArrayList<>();
3535

3636
private InsertDSL(T record, SqlTable table) {
3737
this.record = record;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2019 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.
@@ -25,20 +25,20 @@
2525
import org.mybatis.dynamic.sql.insert.render.InsertRenderer;
2626
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
2727
import org.mybatis.dynamic.sql.render.RenderingStrategy;
28-
import org.mybatis.dynamic.sql.util.InsertMapping;
28+
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
2929

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

3535
private InsertModel(Builder<T> builder) {
3636
table = Objects.requireNonNull(builder.table);
3737
record = Objects.requireNonNull(builder.record);
3838
columnMappings = Objects.requireNonNull(builder.columnMappings);
3939
}
4040

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

@@ -64,7 +64,7 @@ public static <T> Builder<T> withRecord(T record) {
6464
public static class Builder<T> {
6565
private SqlTable table;
6666
private T record;
67-
private List<InsertMapping> columnMappings = new ArrayList<>();
67+
private List<AbstractColumnMapping> columnMappings = new ArrayList<>();
6868

6969
public Builder<T> withTable(SqlTable table) {
7070
this.table = table;
@@ -76,7 +76,7 @@ public Builder<T> withRecord(T record) {
7676
return this;
7777
}
7878

79-
public Builder<T> withColumnMappings(List<InsertMapping> columnMappings) {
79+
public Builder<T> withColumnMappings(List<AbstractColumnMapping> columnMappings) {
8080
this.columnMappings.addAll(columnMappings);
8181
return this;
8282
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
import org.mybatis.dynamic.sql.SqlColumn;
2424
import org.mybatis.dynamic.sql.SqlTable;
25+
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
2526
import org.mybatis.dynamic.sql.util.ConstantMapping;
26-
import org.mybatis.dynamic.sql.util.InsertMapping;
2727
import org.mybatis.dynamic.sql.util.NullMapping;
2828
import org.mybatis.dynamic.sql.util.PropertyMapping;
2929
import org.mybatis.dynamic.sql.util.StringConstantMapping;
@@ -32,7 +32,7 @@ public class MultiRowInsertDSL<T> {
3232

3333
private Collection<T> records;
3434
private SqlTable table;
35-
private List<InsertMapping> columnMappings = new ArrayList<>();
35+
private List<AbstractColumnMapping> columnMappings = new ArrayList<>();
3636

3737
private MultiRowInsertDSL(Collection<T> records, SqlTable table) {
3838
this.records = records;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import org.mybatis.dynamic.sql.insert.GeneralInsertModel;
2424
import org.mybatis.dynamic.sql.render.RenderingStrategy;
25-
import org.mybatis.dynamic.sql.util.GeneralInsertMapping;
25+
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
2626

2727
public class GeneralInsertRenderer {
2828

@@ -51,11 +51,11 @@ private String calculateInsertStatement(FieldAndValueAndParametersCollector coll
5151
+ spaceBefore(collector.valuesPhrase());
5252
}
5353

54-
private Function<GeneralInsertMapping, FieldAndValueAndParameters> toFieldAndValue(GeneralInsertValuePhraseVisitor visitor) {
54+
private Function<AbstractColumnMapping, FieldAndValueAndParameters> toFieldAndValue(GeneralInsertValuePhraseVisitor visitor) {
5555
return insertMapping -> toFieldAndValue(visitor, insertMapping);
5656
}
5757

58-
private FieldAndValueAndParameters toFieldAndValue(GeneralInsertValuePhraseVisitor visitor, GeneralInsertMapping insertMapping) {
58+
private FieldAndValueAndParameters toFieldAndValue(GeneralInsertValuePhraseVisitor visitor, AbstractColumnMapping insertMapping) {
5959
return insertMapping.accept(visitor);
6060
}
6161

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
import org.mybatis.dynamic.sql.render.RenderingStrategy;
2323
import org.mybatis.dynamic.sql.select.render.SelectRenderer;
2424
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
25+
import org.mybatis.dynamic.sql.util.ColumnMappingVisitor;
2526
import org.mybatis.dynamic.sql.util.ConstantMapping;
26-
import org.mybatis.dynamic.sql.util.GeneralInsertMappingVisitor;
2727
import org.mybatis.dynamic.sql.util.NullMapping;
2828
import org.mybatis.dynamic.sql.util.SelectMapping;
2929
import org.mybatis.dynamic.sql.util.StringConstantMapping;
3030
import org.mybatis.dynamic.sql.util.ValueMapping;
3131

32-
public class GeneralInsertValuePhraseVisitor implements GeneralInsertMappingVisitor<FieldAndValueAndParameters> {
32+
public class GeneralInsertValuePhraseVisitor implements ColumnMappingVisitor<FieldAndValueAndParameters> {
3333

3434
protected RenderingStrategy renderingStrategy;
3535
private AtomicInteger sequence = new AtomicInteger(1);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import org.mybatis.dynamic.sql.insert.InsertModel;
2424
import org.mybatis.dynamic.sql.render.RenderingStrategy;
25-
import org.mybatis.dynamic.sql.util.InsertMapping;
25+
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
2626

2727
public class InsertRenderer<T> {
2828

@@ -51,11 +51,11 @@ private String calculateInsertStatement(FieldAndValueCollector collector) {
5151
+ spaceBefore(collector.valuesPhrase());
5252
}
5353

54-
private Function<InsertMapping, FieldAndValue> toFieldAndValue(ValuePhraseVisitor visitor) {
54+
private Function<AbstractColumnMapping, FieldAndValue> toFieldAndValue(ValuePhraseVisitor visitor) {
5555
return insertMapping -> toFieldAndValue(visitor, insertMapping);
5656
}
5757

58-
private FieldAndValue toFieldAndValue(ValuePhraseVisitor visitor, InsertMapping insertMapping) {
58+
private FieldAndValue toFieldAndValue(ValuePhraseVisitor visitor, AbstractColumnMapping insertMapping) {
5959
return insertMapping.accept(visitor);
6060
}
6161

0 commit comments

Comments
 (0)