|
31 | 31 | import org.mybatis.dynamic.sql.insert.GeneralInsertModel;
|
32 | 32 | import org.mybatis.dynamic.sql.insert.InsertModel;
|
33 | 33 | import org.mybatis.dynamic.sql.insert.MultiRowInsertModel;
|
| 34 | +import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider; |
| 35 | +import org.mybatis.dynamic.sql.render.RenderingStrategies; |
34 | 36 | import org.mybatis.dynamic.sql.select.SelectModel;
|
35 | 37 | import org.mybatis.dynamic.sql.update.UpdateModel;
|
36 | 38 | import org.mybatis.dynamic.sql.util.Buildable;
|
@@ -379,6 +381,32 @@ void testInsertSelective() {
|
379 | 381 | assertThat(rows).isEqualTo(1);
|
380 | 382 | }
|
381 | 383 |
|
| 384 | + @Test |
| 385 | + void testGeneralInsertWhenTypeConverterReturnsNull() { |
| 386 | + |
| 387 | + GeneralInsertStatementProvider insertStatement = insertInto(person) |
| 388 | + .set(id).toValue(100) |
| 389 | + .set(firstName).toValue("Joe") |
| 390 | + .set(lastName).toValueWhenPresent(LastName.of("Slate")) |
| 391 | + .set(birthDate).toValue(new Date()) |
| 392 | + .set(employed).toValue(true) |
| 393 | + .set(occupation).toValue("Quarry Owner") |
| 394 | + .set(addressId).toValue(1) |
| 395 | + .build() |
| 396 | + .render(RenderingStrategies.SPRING_NAMED_PARAMETER); |
| 397 | + |
| 398 | + assertThat(insertStatement.getInsertStatement()) |
| 399 | + .isEqualTo("insert into Person (id, first_name, birth_date, employed, occupation, address_id) values (:p1, :p2, :p3, :p4, :p5, :p6)"); |
| 400 | + int rows = template.generalInsert(insertStatement); |
| 401 | + assertThat(rows).isEqualTo(1); |
| 402 | + |
| 403 | + Buildable<SelectModel> selectStatement = select(id, firstName, lastName, birthDate, employed, occupation, addressId) |
| 404 | + .from(person) |
| 405 | + .where(id, isEqualTo(100)); |
| 406 | + Optional<PersonRecord> newRecord = template.selectOne(selectStatement, personRowMapper); |
| 407 | + assertThat(newRecord).hasValueSatisfying(r -> assertThat(r.getLastName().getName()).isNull()); |
| 408 | + } |
| 409 | + |
382 | 410 | @Test
|
383 | 411 | void testUpdateByPrimaryKey() {
|
384 | 412 |
|
|
0 commit comments