1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.dynamic.sql.insert;
17
18 import java.util.Collection;
19
20 import org.mybatis.dynamic.sql.insert.render.MultiRowInsertRenderer;
21 import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
22 import org.mybatis.dynamic.sql.render.RenderingStrategy;
23 import org.mybatis.dynamic.sql.util.Validator;
24
25 public class MultiRowInsertModel<T> extends AbstractMultiRowInsertModel<T> {
26
27 private MultiRowInsertModel(Builder<T> builder) {
28 super(builder);
29 Validator.assertNotEmpty(records(), "ERROR.20");
30 Validator.assertNotEmpty(columnMappings, "ERROR.8");
31 }
32
33 public MultiRowInsertStatementProvider<T> render(RenderingStrategy renderingStrategy) {
34 return MultiRowInsertRenderer.withMultiRowInsertModel(this)
35 .withRenderingStrategy(renderingStrategy)
36 .build()
37 .render();
38 }
39
40 public static <T> Builder<T> withRecords(Collection<T> records) {
41 return new Builder<T>().withRecords(records);
42 }
43
44 public static class Builder<T> extends AbstractBuilder<T, Builder<T>> {
45 @Override
46 protected Builder<T> getThis() {
47 return this;
48 }
49
50 public MultiRowInsertModel<T> build() {
51 return new MultiRowInsertModel<>(this);
52 }
53 }
54 }