|
1 | 1 | /* |
2 | | - * Copyright 2016-2023 the original author or authors. |
| 2 | + * Copyright 2016-2024 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. |
|
15 | 15 | */ |
16 | 16 | package examples.kotlin.spring.canonical |
17 | 17 |
|
| 18 | +import examples.kotlin.spring.canonical.PersonDynamicSqlSupport.addressId |
18 | 19 | import examples.kotlin.spring.canonical.PersonDynamicSqlSupport.employed |
19 | 20 | import examples.kotlin.spring.canonical.PersonDynamicSqlSupport.person |
20 | 21 | import examples.kotlin.spring.canonical.PersonDynamicSqlSupport.firstName |
21 | 22 | import examples.kotlin.spring.canonical.PersonDynamicSqlSupport.id |
22 | 23 | import examples.kotlin.spring.canonical.PersonDynamicSqlSupport.lastName |
23 | 24 | import org.assertj.core.api.Assertions.assertThat |
| 25 | +import org.assertj.core.api.Assertions.entry |
24 | 26 | import org.junit.jupiter.api.Test |
| 27 | +import org.mybatis.dynamic.sql.util.kotlin.elements.add |
25 | 28 | import org.mybatis.dynamic.sql.util.kotlin.elements.applyOperator |
26 | 29 | import org.mybatis.dynamic.sql.util.kotlin.elements.avg |
27 | 30 | import org.mybatis.dynamic.sql.util.kotlin.elements.concat |
@@ -50,9 +53,11 @@ import org.mybatis.dynamic.sql.util.kotlin.elements.stringConstant |
50 | 53 | import org.mybatis.dynamic.sql.util.kotlin.elements.substring |
51 | 54 | import org.mybatis.dynamic.sql.util.kotlin.elements.subtract |
52 | 55 | import org.mybatis.dynamic.sql.util.kotlin.elements.sum |
| 56 | +import org.mybatis.dynamic.sql.util.kotlin.elements.value |
53 | 57 | import org.mybatis.dynamic.sql.util.kotlin.spring.select |
54 | 58 | import org.mybatis.dynamic.sql.util.kotlin.spring.selectList |
55 | 59 | import org.mybatis.dynamic.sql.util.kotlin.spring.selectOne |
| 60 | +import org.mybatis.dynamic.sql.util.kotlin.spring.update |
56 | 61 | import org.springframework.beans.factory.annotation.Autowired |
57 | 62 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate |
58 | 63 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig |
@@ -654,4 +659,19 @@ open class KotlinElementsTest { |
654 | 659 | assertThat(rows).hasSize(6) |
655 | 660 | assertThat(rows[0]).isEqualTo("Fred") |
656 | 661 | } |
| 662 | + |
| 663 | + @Test |
| 664 | + fun testValue() { |
| 665 | + val updateStatement = update(person) { |
| 666 | + set(addressId) equalTo add(addressId, value(4)) |
| 667 | + where { |
| 668 | + id isEqualTo 5 |
| 669 | + } |
| 670 | + } |
| 671 | + |
| 672 | + assertThat(updateStatement.updateStatement).isEqualTo( |
| 673 | + "update Person set address_id = (address_id + :p1) where id = :p2" |
| 674 | + ) |
| 675 | + assertThat(updateStatement.parameters).containsExactly(entry("p1", 4), entry("p2", 5)) |
| 676 | + } |
657 | 677 | } |
0 commit comments