Skip to content

Commit d084d53

Browse files
committed
Factor out some common code
1 parent 4fb784b commit d084d53

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
import static org.mybatis.dynamic.sql.util.StringUtilities.spaceBefore;
1919

2020
import java.util.Objects;
21-
import java.util.function.Function;
2221

2322
import org.mybatis.dynamic.sql.insert.BatchInsertModel;
2423
import org.mybatis.dynamic.sql.render.RenderingStrategy;
25-
import org.mybatis.dynamic.sql.util.InsertMapping;
2624

2725
public class BatchInsertRenderer<T> {
2826

@@ -36,22 +34,14 @@ private BatchInsertRenderer(Builder<T> builder) {
3634

3735
public BatchInsert<T> render() {
3836
ValuePhraseVisitor visitor = new ValuePhraseVisitor(renderingStrategy, "record"); //$NON-NLS-1$
39-
FieldAndValueCollector collector = model.mapColumnMappings(toFieldAndValue(visitor))
37+
FieldAndValueCollector collector = model.mapColumnMappings(MultiRowRenderingUtilities.toFieldAndValue(visitor))
4038
.collect(FieldAndValueCollector.collect());
4139

4240
return BatchInsert.withRecords(model.records())
4341
.withInsertStatement(calculateInsertStatement(collector))
4442
.build();
4543
}
4644

47-
private Function<InsertMapping, FieldAndValue> toFieldAndValue(ValuePhraseVisitor visitor) {
48-
return insertMapping -> toFieldAndValue(visitor, insertMapping);
49-
}
50-
51-
private FieldAndValue toFieldAndValue(ValuePhraseVisitor visitor, InsertMapping insertMapping) {
52-
return insertMapping.accept(visitor);
53-
}
54-
5545
private String calculateInsertStatement(FieldAndValueCollector collector) {
5646
return "insert into" //$NON-NLS-1$
5747
+ spaceBefore(model.table().tableNameAtRuntime())

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
import static org.mybatis.dynamic.sql.util.StringUtilities.spaceBefore;
1919

2020
import java.util.Objects;
21-
import java.util.function.Function;
2221

2322
import org.mybatis.dynamic.sql.insert.MultiRowInsertModel;
2423
import org.mybatis.dynamic.sql.render.RenderingStrategy;
25-
import org.mybatis.dynamic.sql.util.InsertMapping;
2624

2725
public class MultiRowInsertRenderer<T> {
2826

@@ -36,22 +34,14 @@ private MultiRowInsertRenderer(Builder<T> builder) {
3634

3735
public MultiRowInsertStatementProvider<T> render() {
3836
ValuePhraseVisitor visitor = new ValuePhraseVisitor(renderingStrategy, "records[%s]"); //$NON-NLS-1$
39-
FieldAndValueCollector collector = model.mapColumnMappings(toFieldAndValue(visitor))
37+
FieldAndValueCollector collector = model.mapColumnMappings(MultiRowRenderingUtilities.toFieldAndValue(visitor))
4038
.collect(FieldAndValueCollector.collect());
4139

4240
return new DefaultMultiRowInsertStatementProvider.Builder<T>().withRecords(model.records())
4341
.withInsertStatement(calculateInsertStatement(collector))
4442
.build();
4543
}
4644

47-
private Function<InsertMapping, FieldAndValue> toFieldAndValue(ValuePhraseVisitor visitor) {
48-
return insertMapping -> toFieldAndValue(visitor, insertMapping);
49-
}
50-
51-
private FieldAndValue toFieldAndValue(ValuePhraseVisitor visitor, InsertMapping insertMapping) {
52-
return insertMapping.accept(visitor);
53-
}
54-
5545
private String calculateInsertStatement(FieldAndValueCollector collector) {
5646
return "insert into" //$NON-NLS-1$
5747
+ spaceBefore(model.table().tableNameAtRuntime())
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.insert.render;
17+
18+
import java.util.function.Function;
19+
20+
import org.mybatis.dynamic.sql.util.InsertMapping;
21+
22+
public class MultiRowRenderingUtilities {
23+
24+
private MultiRowRenderingUtilities() {}
25+
26+
public static Function<InsertMapping, FieldAndValue> toFieldAndValue(ValuePhraseVisitor visitor) {
27+
return insertMapping -> MultiRowRenderingUtilities.toFieldAndValue(visitor, insertMapping);
28+
}
29+
30+
public static FieldAndValue toFieldAndValue(ValuePhraseVisitor visitor, InsertMapping insertMapping) {
31+
return insertMapping.accept(visitor);
32+
}
33+
}

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