1
1
/**
2
- * Copyright 2016-2018 the original author or authors.
2
+ * Copyright 2016-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package org .mybatis .dynamic .sql .insert .render ;
17
17
18
- import static org .mybatis .dynamic .sql .util .StringUtilities .spaceBefore ;
19
-
20
18
import java .util .ArrayList ;
21
19
import java .util .Collections ;
22
20
import java .util .List ;
23
21
import java .util .Objects ;
24
22
import java .util .stream .Collectors ;
25
23
26
24
public class BatchInsert <T > {
27
- private String tableName ;
28
- private String columnsPhrase ;
29
- private String valuesPhrase ;
25
+ private String insertStatement ;
30
26
private List <T > records ;
31
27
32
28
private BatchInsert (Builder <T > builder ) {
33
- tableName = Objects .requireNonNull (builder .tableName );
34
- columnsPhrase = Objects .requireNonNull (builder .columnsPhrase );
35
- valuesPhrase = Objects .requireNonNull (builder .valuesPhrase );
29
+ insertStatement = Objects .requireNonNull (builder .insertStatement );
36
30
records = Collections .unmodifiableList (Objects .requireNonNull (builder .records ));
37
31
}
38
32
@@ -49,9 +43,7 @@ public List<InsertStatementProvider<T>> insertStatements() {
49
43
50
44
private InsertStatementProvider <T > toInsertStatement (T record ) {
51
45
return DefaultInsertStatementProvider .withRecord (record )
52
- .withTableName (tableName )
53
- .withColumnsPhrase (columnsPhrase )
54
- .withValuesPhrase (valuesPhrase )
46
+ .withInsertStatement (insertStatement )
55
47
.build ();
56
48
}
57
49
@@ -61,37 +53,22 @@ private InsertStatementProvider<T> toInsertStatement(T record) {
61
53
* @return the generated INSERT statement
62
54
*/
63
55
public String getInsertStatementSQL () {
64
- return "insert into" //$NON-NLS-1$
65
- + spaceBefore (tableName )
66
- + spaceBefore (columnsPhrase )
67
- + spaceBefore (valuesPhrase );
56
+ return insertStatement ;
68
57
}
69
58
70
59
public static <T > Builder <T > withRecords (List <T > records ) {
71
60
return new Builder <T >().withRecords (records );
72
61
}
73
62
74
63
public static class Builder <T > {
75
- private String tableName ;
76
- private String columnsPhrase ;
77
- private String valuesPhrase ;
64
+ private String insertStatement ;
78
65
private List <T > records = new ArrayList <>();
79
66
80
- public Builder <T > withTableName (String tableName ) {
81
- this .tableName = tableName ;
67
+ public Builder <T > withInsertStatement (String insertStatement ) {
68
+ this .insertStatement = insertStatement ;
82
69
return this ;
83
70
}
84
71
85
- public Builder <T > withColumnsPhrase (String columnsPhrase ) {
86
- this .columnsPhrase = columnsPhrase ;
87
- return this ;
88
- }
89
-
90
- public Builder <T > withValuesPhrase (String valuesPhrase ) {
91
- this .valuesPhrase = valuesPhrase ;
92
- return this ;
93
- }
94
-
95
72
public Builder <T > withRecords (List <T > records ) {
96
73
this .records .addAll (records );
97
74
return this ;
0 commit comments