1
1
/*
2
- * Copyright 2016-2020 the original author or authors.
2
+ * Copyright 2016-2021 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.
23
23
import java .util .List ;
24
24
import java .util .Optional ;
25
25
26
- import org .apache .ibatis .annotations .Insert ;
27
26
import org .apache .ibatis .annotations .InsertProvider ;
28
27
import org .apache .ibatis .annotations .Options ;
29
28
import org .apache .ibatis .annotations .Param ;
33
32
import org .apache .ibatis .annotations .SelectProvider ;
34
33
import org .mybatis .dynamic .sql .BasicColumn ;
35
34
import org .mybatis .dynamic .sql .insert .render .InsertStatementProvider ;
36
- import org .mybatis .dynamic .sql .insert .render .MultiRowInsertStatementProvider ;
37
35
import org .mybatis .dynamic .sql .select .SelectDSLCompleter ;
38
36
import org .mybatis .dynamic .sql .select .render .SelectStatementProvider ;
39
37
import org .mybatis .dynamic .sql .update .UpdateDSL ;
42
40
import org .mybatis .dynamic .sql .util .SqlProviderAdapter ;
43
41
44
42
import examples .generated .always .GeneratedAlwaysRecord ;
45
- import org .mybatis .dynamic .sql .util .mybatis3 .CommonInsertMapper ;
46
43
import org .mybatis .dynamic .sql .util .mybatis3 .CommonUpdateMapper ;
47
44
import org .mybatis .dynamic .sql .util .mybatis3 .MyBatis3Utils ;
48
45
49
- public interface GeneratedAlwaysMapper extends CommonInsertMapper < GeneratedAlwaysRecord >, CommonUpdateMapper {
46
+ public interface GeneratedAlwaysMapper extends CommonUpdateMapper {
50
47
@ SelectProvider (type =SqlProviderAdapter .class , method ="select" )
51
48
@ Results (id ="gaResults" , value ={
52
49
@ Result (property ="id" , column ="id" , id =true ),
@@ -60,23 +57,14 @@ public interface GeneratedAlwaysMapper extends CommonInsertMapper<GeneratedAlway
60
57
@ ResultMap ("gaResults" )
61
58
Optional <GeneratedAlwaysRecord > selectOne (SelectStatementProvider selectStatement );
62
59
63
- @ Override
64
60
@ InsertProvider (type =SqlProviderAdapter .class , method ="insert" )
65
61
@ Options (useGeneratedKeys =true , keyProperty ="record.fullName" )
66
62
int insert (InsertStatementProvider <GeneratedAlwaysRecord > insertStatement );
67
63
68
- // This is kludgy. Currently MyBatis does not support nested lists in parameter objects
69
- // when returning generated keys.
70
- // So we need to do this silliness and decompose the multi row insert into its component parts
71
- // for the actual MyBatis call
72
- @ Insert ("${insertStatement}" )
64
+ @ InsertProvider (type =SqlProviderAdapter .class , method ="insertMultipleWithGeneratedKeys" )
73
65
@ Options (useGeneratedKeys =true , keyProperty ="records.fullName" )
74
66
int insertMultiple (@ Param ("insertStatement" ) String statement , @ Param ("records" ) List <GeneratedAlwaysRecord > records );
75
67
76
- default int insertMultiple (MultiRowInsertStatementProvider <GeneratedAlwaysRecord > multiInsert ) {
77
- return insertMultiple (multiInsert .getInsertStatement (), multiInsert .getRecords ());
78
- }
79
-
80
68
BasicColumn [] selectList =
81
69
BasicColumn .columnList (id , firstName , lastName , fullName );
82
70
@@ -100,6 +88,18 @@ default int insert(GeneratedAlwaysRecord record) {
100
88
);
101
89
}
102
90
91
+ default int insertMultiple (GeneratedAlwaysRecord ...records ) {
92
+ return insertMultiple (Arrays .asList (records ));
93
+ }
94
+
95
+ default int insertMultiple (Collection <GeneratedAlwaysRecord > records ) {
96
+ return MyBatis3Utils .insertMultipleWithGeneratedKeys (this ::insertMultiple , records , generatedAlways , c ->
97
+ c .map (id ).toProperty ("id" )
98
+ .map (firstName ).toProperty ("firstName" )
99
+ .map (lastName ).toProperty ("lastName" )
100
+ );
101
+ }
102
+
103
103
default int insertSelective (GeneratedAlwaysRecord record ) {
104
104
return MyBatis3Utils .insert (this ::insert , record , generatedAlways , c ->
105
105
c .map (id ).toPropertyWhenPresent ("id" , record ::getId )
@@ -133,16 +133,4 @@ static UpdateDSL<UpdateModel> updateSelectiveColumns(GeneratedAlwaysRecord recor
133
133
.set (firstName ).equalToWhenPresent (record ::getFirstName )
134
134
.set (lastName ).equalToWhenPresent (record ::getLastName );
135
135
}
136
-
137
- default int insertMultiple (GeneratedAlwaysRecord ...records ) {
138
- return insertMultiple (Arrays .asList (records ));
139
- }
140
-
141
- default int insertMultiple (Collection <GeneratedAlwaysRecord > records ) {
142
- return MyBatis3Utils .insertMultiple (this ::insertMultiple , records , generatedAlways , c ->
143
- c .map (id ).toProperty ("id" )
144
- .map (firstName ).toProperty ("firstName" )
145
- .map (lastName ).toProperty ("lastName" )
146
- );
147
- }
148
136
}
0 commit comments