|
18 | 18 | import static examples.simple.PersonDynamicSqlSupport.*; |
19 | 19 | import static org.mybatis.dynamic.sql.SqlBuilder.*; |
20 | 20 |
|
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.Collection; |
21 | 23 | import java.util.List; |
22 | 24 | import java.util.Optional; |
23 | 25 |
|
|
31 | 33 | import org.apache.ibatis.annotations.UpdateProvider; |
32 | 34 | import org.apache.ibatis.type.JdbcType; |
33 | 35 | import org.mybatis.dynamic.sql.BasicColumn; |
34 | | -import org.mybatis.dynamic.sql.SqlBuilder; |
35 | 36 | import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider; |
36 | 37 | import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider; |
37 | 38 | import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider; |
38 | | -import org.mybatis.dynamic.sql.render.RenderingStrategy; |
39 | 39 | import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; |
40 | 40 | import org.mybatis.dynamic.sql.update.UpdateDSL; |
41 | 41 | import org.mybatis.dynamic.sql.update.UpdateModel; |
@@ -101,45 +101,43 @@ default int deleteByPrimaryKey(Integer id_) { |
101 | 101 | } |
102 | 102 |
|
103 | 103 | default int insert(PersonRecord record) { |
104 | | - return insert(SqlBuilder.insert(record) |
105 | | - .into(person) |
106 | | - .map(id).toProperty("id") |
107 | | - .map(firstName).toProperty("firstName") |
108 | | - .map(lastName).toProperty("lastName") |
109 | | - .map(birthDate).toProperty("birthDate") |
110 | | - .map(employed).toProperty("employed") |
111 | | - .map(occupation).toProperty("occupation") |
112 | | - .map(addressId).toProperty("addressId") |
113 | | - .build() |
114 | | - .render(RenderingStrategy.MYBATIS3)); |
| 104 | + return MyBatis3Utils.insert(this::insert, record, person, h -> |
| 105 | + h.map(id).toProperty("id") |
| 106 | + .map(firstName).toProperty("firstName") |
| 107 | + .map(lastName).toProperty("lastName") |
| 108 | + .map(birthDate).toProperty("birthDate") |
| 109 | + .map(employed).toProperty("employed") |
| 110 | + .map(occupation).toProperty("occupation") |
| 111 | + .map(addressId).toProperty("addressId") |
| 112 | + ); |
115 | 113 | } |
116 | 114 |
|
117 | | - default int insertMultiple(List<PersonRecord> records) { |
118 | | - return insertMultiple(SqlBuilder.insertMultiple(records) |
119 | | - .into(person) |
120 | | - .map(id).toProperty("id") |
121 | | - .map(firstName).toProperty("firstName") |
122 | | - .map(lastName).toProperty("lastName") |
123 | | - .map(birthDate).toProperty("birthDate") |
124 | | - .map(employed).toProperty("employed") |
125 | | - .map(occupation).toProperty("occupation") |
126 | | - .map(addressId).toProperty("addressId") |
127 | | - .build() |
128 | | - .render(RenderingStrategy.MYBATIS3)); |
| 115 | + default int insertMultiple(PersonRecord...records) { |
| 116 | + return insertMultiple(Arrays.asList(records)); |
| 117 | + } |
| 118 | + |
| 119 | + default int insertMultiple(Collection<PersonRecord> records) { |
| 120 | + return MyBatis3Utils.insertMultiple(this::insertMultiple, records, person, h -> |
| 121 | + h.map(id).toProperty("id") |
| 122 | + .map(firstName).toProperty("firstName") |
| 123 | + .map(lastName).toProperty("lastName") |
| 124 | + .map(birthDate).toProperty("birthDate") |
| 125 | + .map(employed).toProperty("employed") |
| 126 | + .map(occupation).toProperty("occupation") |
| 127 | + .map(addressId).toProperty("addressId") |
| 128 | + ); |
129 | 129 | } |
130 | 130 |
|
131 | 131 | default int insertSelective(PersonRecord record) { |
132 | | - return insert(SqlBuilder.insert(record) |
133 | | - .into(person) |
134 | | - .map(id).toPropertyWhenPresent("id", record::getId) |
135 | | - .map(firstName).toPropertyWhenPresent("firstName", record::getFirstName) |
136 | | - .map(lastName).toPropertyWhenPresent("lastName", record::getLastName) |
137 | | - .map(birthDate).toPropertyWhenPresent("birthDate", record::getBirthDate) |
138 | | - .map(employed).toPropertyWhenPresent("employed", record::getEmployed) |
139 | | - .map(occupation).toPropertyWhenPresent("occupation", record::getOccupation) |
140 | | - .map(addressId).toPropertyWhenPresent("addressId", record::getAddressId) |
141 | | - .build() |
142 | | - .render(RenderingStrategy.MYBATIS3)); |
| 132 | + return MyBatis3Utils.insert(this::insert, record, person, h -> |
| 133 | + h.map(id).toPropertyWhenPresent("id", record::getId) |
| 134 | + .map(firstName).toPropertyWhenPresent("firstName", record::getFirstName) |
| 135 | + .map(lastName).toPropertyWhenPresent("lastName", record::getLastName) |
| 136 | + .map(birthDate).toPropertyWhenPresent("birthDate", record::getBirthDate) |
| 137 | + .map(employed).toPropertyWhenPresent("employed", record::getEmployed) |
| 138 | + .map(occupation).toPropertyWhenPresent("occupation", record::getOccupation) |
| 139 | + .map(addressId).toPropertyWhenPresent("addressId", record::getAddressId) |
| 140 | + ); |
143 | 141 | } |
144 | 142 |
|
145 | 143 | static BasicColumn[] selectList = |
|
0 commit comments