|
38 | 38 | import org.mybatis.dynamic.sql.render.RenderingStrategy;
|
39 | 39 | import org.mybatis.dynamic.sql.select.SelectDSL;
|
40 | 40 | import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
|
| 41 | +import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter; |
41 | 42 | import org.mybatis.dynamic.sql.update.UpdateDSL;
|
42 | 43 | import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
|
43 | 44 | import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
|
44 | 45 | import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3CountByExampleHelper;
|
45 | 46 | import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3DeleteByExampleHelper;
|
46 | 47 | import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3SelectByExampleHelper;
|
47 |
| -import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3UpdateByExampleCompleter; |
48 | 48 | import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3UpdateByExampleHelper;
|
49 | 49 |
|
50 | 50 | /**
|
@@ -171,57 +171,49 @@ default SimpleTableRecord selectByPrimaryKey(Integer id_) {
|
171 | 171 | .execute();
|
172 | 172 | }
|
173 | 173 |
|
174 |
| - default MyBatis3UpdateByExampleCompleter<SimpleTableRecord> updateByExample(MyBatis3UpdateByExampleHelper helper) { |
175 |
| - return new MyBatis3UpdateByExampleCompleter.Builder<SimpleTableRecord>() |
176 |
| - .withHelper(helper) |
177 |
| - .withMapper(this::update) |
178 |
| - .withTable(simpleTable) |
179 |
| - .withValueSetter((record, dsl) -> |
180 |
| - dsl.set(id).equalTo(record::getId) |
181 |
| - .set(firstName).equalTo(record::getFirstName) |
182 |
| - .set(lastName).equalTo(record::getLastName) |
183 |
| - .set(birthDate).equalTo(record::getBirthDate) |
184 |
| - .set(employed).equalTo(record::getEmployed) |
185 |
| - .set(occupation).equalTo(record::getOccupation)) |
186 |
| - .build(); |
187 |
| - } |
188 |
| - |
189 |
| - default MyBatis3UpdateByExampleCompleter<SimpleTableRecord> updateByExampleSelective(MyBatis3UpdateByExampleHelper helper) { |
190 |
| - return new MyBatis3UpdateByExampleCompleter.Builder<SimpleTableRecord>() |
191 |
| - .withHelper(helper) |
192 |
| - .withMapper(this::update) |
193 |
| - .withTable(simpleTable) |
194 |
| - .withValueSetter((record, dsl) -> |
195 |
| - dsl.set(id).equalToWhenPresent(record::getId) |
196 |
| - .set(firstName).equalToWhenPresent(record::getFirstName) |
197 |
| - .set(lastName).equalToWhenPresent(record::getLastName) |
198 |
| - .set(birthDate).equalToWhenPresent(record::getBirthDate) |
199 |
| - .set(employed).equalToWhenPresent(record::getEmployed) |
200 |
| - .set(occupation).equalToWhenPresent(record::getOccupation)) |
201 |
| - .build(); |
| 174 | + default int update(MyBatis3UpdateByExampleHelper helper) { |
| 175 | + return helper.apply(UpdateDSL.updateWithMapper(this::update, simpleTable)) |
| 176 | + .build() |
| 177 | + .execute(); |
202 | 178 | }
|
203 | 179 |
|
204 |
| - default int updateByPrimaryKey(SimpleTableRecord record) { |
205 |
| - return UpdateDSL.updateWithMapper(this::update, simpleTable) |
| 180 | + static UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> setAll(SimpleTableRecord record, UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> dsl) { |
| 181 | + return dsl.set(id).equalTo(record::getId) |
206 | 182 | .set(firstName).equalTo(record::getFirstName)
|
207 | 183 | .set(lastName).equalTo(record::getLastName)
|
208 | 184 | .set(birthDate).equalTo(record::getBirthDate)
|
209 | 185 | .set(employed).equalTo(record::getEmployed)
|
210 |
| - .set(occupation).equalTo(record::getOccupation) |
211 |
| - .where(id, isEqualTo(record::getId)) |
212 |
| - .build() |
213 |
| - .execute(); |
| 186 | + .set(occupation).equalTo(record::getOccupation); |
214 | 187 | }
|
215 |
| - |
216 |
| - default int updateByPrimaryKeySelective(SimpleTableRecord record) { |
217 |
| - return UpdateDSL.updateWithMapper(this::update, simpleTable) |
| 188 | + |
| 189 | + static UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> setSelective(SimpleTableRecord record, UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> dsl) { |
| 190 | + return dsl.set(id).equalToWhenPresent(record::getId) |
218 | 191 | .set(firstName).equalToWhenPresent(record::getFirstName)
|
219 | 192 | .set(lastName).equalToWhenPresent(record::getLastName)
|
220 | 193 | .set(birthDate).equalToWhenPresent(record::getBirthDate)
|
221 | 194 | .set(employed).equalToWhenPresent(record::getEmployed)
|
222 |
| - .set(occupation).equalToWhenPresent(record::getOccupation) |
223 |
| - .where(id, isEqualTo(record::getId)) |
224 |
| - .build() |
225 |
| - .execute(); |
| 195 | + .set(occupation).equalToWhenPresent(record::getOccupation); |
| 196 | + } |
| 197 | + |
| 198 | + default int updateByPrimaryKey(SimpleTableRecord record) { |
| 199 | + return update(h -> |
| 200 | + h.set(firstName).equalTo(record::getFirstName) |
| 201 | + .set(lastName).equalTo(record::getLastName) |
| 202 | + .set(birthDate).equalTo(record::getBirthDate) |
| 203 | + .set(employed).equalTo(record::getEmployed) |
| 204 | + .set(occupation).equalTo(record::getOccupation) |
| 205 | + .where(id, isEqualTo(record::getId)) |
| 206 | + ); |
| 207 | + } |
| 208 | + |
| 209 | + default int updateByPrimaryKeySelective(SimpleTableRecord record) { |
| 210 | + return update(h -> |
| 211 | + h.set(firstName).equalToWhenPresent(record::getFirstName) |
| 212 | + .set(lastName).equalToWhenPresent(record::getLastName) |
| 213 | + .set(birthDate).equalToWhenPresent(record::getBirthDate) |
| 214 | + .set(employed).equalToWhenPresent(record::getEmployed) |
| 215 | + .set(occupation).equalToWhenPresent(record::getOccupation) |
| 216 | + .where(id, isEqualTo(record::getId)) |
| 217 | + ); |
226 | 218 | }
|
227 | 219 | }
|
0 commit comments