Skip to content

Commit 007ab15

Browse files
committed
Insert SET methods can be infix
1 parent 4d1178e commit 007ab15

File tree

6 files changed

+54
-54
lines changed

6 files changed

+54
-54
lines changed

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertHelpers.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,38 @@ class KotlinGeneralInsertBuilder(private val dsl: GeneralInsertDSL) : Buildable<
4747
set(column).toNull()
4848
}
4949

50-
fun toConstant(constant: String): Unit =
50+
infix fun toConstant(constant: String): Unit =
5151
applyToDsl {
5252
set(column).toConstant(constant)
5353
}
5454

55-
fun toStringConstant(constant: String): Unit =
55+
infix fun toStringConstant(constant: String): Unit =
5656
applyToDsl {
5757
set(column).toStringConstant(constant)
5858
}
5959

60-
fun toValue(value: T): Unit = toValue { value }
60+
infix fun toValue(value: T): Unit = toValue { value }
6161

62-
fun toValue(value: () -> T): Unit =
62+
infix fun toValue(value: () -> T): Unit =
6363
applyToDsl {
6464
set(column).toValue(value)
6565
}
6666

67-
fun toValueOrNull(value: T?): Unit = toValueOrNull { value }
67+
infix fun toValueOrNull(value: T?): Unit = toValueOrNull { value }
6868

69-
fun toValueOrNull(value: () -> T?): Unit =
69+
infix fun toValueOrNull(value: () -> T?): Unit =
7070
applyToDsl {
7171
set(column).toValueOrNull(value)
7272
}
7373

74-
fun toValueWhenPresent(value: T?): Unit = toValueWhenPresent { value }
74+
infix fun toValueWhenPresent(value: T?): Unit = toValueWhenPresent { value }
7575

76-
fun toValueWhenPresent(value: () -> T?): Unit =
76+
infix fun toValueWhenPresent(value: () -> T?): Unit =
7777
applyToDsl {
7878
set(column).toValueWhenPresent(value)
7979
}
8080

81-
private fun applyToDsl(block: GeneralInsertDSL.() -> Unit): Unit {
81+
private fun applyToDsl(block: GeneralInsertDSL.() -> Unit) {
8282
this@KotlinGeneralInsertBuilder.dsl.apply(block)
8383
}
8484
}

src/test/kotlin/examples/kotlin/mybatis3/canonical/GeneratedAlwaysTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -129,8 +129,8 @@ class GeneratedAlwaysTest {
129129
val mapper = session.getMapper(GeneratedAlwaysMapper::class.java)
130130

131131
val insertStatement = insertInto(generatedAlways) {
132-
set(firstName).toValue("Fred")
133-
set(lastName).toValue("Flintstone")
132+
set(firstName) toValue "Fred"
133+
set(lastName) toValue "Flintstone"
134134
}
135135

136136
val rows = mapper.generalInsert(insertStatement)

src/test/kotlin/examples/kotlin/mybatis3/canonical/PersonMapperTest.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ class PersonMapperTest {
228228
val mapper = session.getMapper(PersonMapper::class.java)
229229

230230
val rows = mapper.generalInsert {
231-
set(id).toValue(100)
232-
set(firstName).toValue("Joe")
233-
set(lastName).toValue(LastName("Jones"))
234-
set(employed).toValue(true)
235-
set(occupation).toValue("Developer")
236-
set(addressId).toValue(1)
237-
set(birthDate).toValue(Date())
231+
set(id) toValue 100
232+
set(firstName) toValue "Joe"
233+
set(lastName) toValue LastName("Jones")
234+
set(employed) toValue true
235+
set(occupation) toValue "Developer"
236+
set(addressId) toValue 1
237+
set(birthDate) toValue Date()
238238
}
239239

240240
assertThat(rows).isEqualTo(1)
@@ -718,11 +718,11 @@ class PersonMapperTest {
718718
val mapper: AddressMapper = session.getMapper(AddressMapper::class.java)
719719

720720
val insertStatement = insertInto(address) {
721-
set(address.id).toValue(4)
722-
set(address.streetAddress).toValue("987 Elm Street")
723-
set(address.city).toValue("Mayberry")
724-
set(address.state).toValue("NC")
725-
set(address.addressType).toValue(AddressType.HOME)
721+
set(address.id) toValue 4
722+
set(address.streetAddress) toValue "987 Elm Street"
723+
set(address.city) toValue "Mayberry"
724+
set(address.state) toValue "NC"
725+
set(address.addressType) toValue AddressType.HOME
726726
}
727727

728728
val rows = mapper.generalInsert(insertStatement)

src/test/kotlin/examples/kotlin/mybatis3/custom/render/KCustomRenderingTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ class KCustomRenderingTest {
125125
sqlSessionFactory.openSession().use { sqlSession ->
126126
val mapper = sqlSession.getMapper(KJsonTestMapper::class.java)
127127
var insertStatement = insertInto(jsonTest) {
128-
set(id).toValue(1)
129-
set(description).toValue("Fred")
130-
set(info).toValue("{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}")
128+
set(id) toValue 1
129+
set(description) toValue "Fred"
130+
set(info) toValue "{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}"
131131
}
132132
val expected = "insert into JsonTest (id, description, info) " +
133133
"values (#{parameters.p1,jdbcType=INTEGER}, #{parameters.p2,jdbcType=VARCHAR}, " +
@@ -136,9 +136,9 @@ class KCustomRenderingTest {
136136
var rows = mapper!!.generalInsert(insertStatement)
137137
assertThat(rows).isEqualTo(1)
138138
insertStatement = insertInto(jsonTest) {
139-
set(id).toValue(2)
140-
set(description).toValue("Wilma")
141-
set(info).toValue("{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 25}")
139+
set(id) toValue 2
140+
set(description) toValue "Wilma"
141+
set(info) toValue "{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 25}"
142142
}
143143
rows = mapper.generalInsert(insertStatement)
144144
assertThat(rows).isEqualTo(1)

src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTemplateDirectTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ open class CanonicalSpringKotlinTemplateDirectTest {
190190
@Test
191191
fun testGeneralInsert() {
192192
val rows = template.insertInto(person) {
193-
set(id).toValue(100)
194-
set(firstName).toValue("Joe")
195-
set(lastName).toValue(LastName("Jones"))
196-
set(birthDate).toValue(Date())
197-
set(employed).toValue(true)
198-
set(occupation).toValue("Developer")
199-
set(addressId).toValue(1)
193+
set(id) toValue 100
194+
set(firstName) toValue "Joe"
195+
set(lastName) toValue LastName("Jones")
196+
set(birthDate) toValue Date()
197+
set(employed) toValue true
198+
set(occupation) toValue "Developer"
199+
set(addressId) toValue 1
200200
}
201201

202202
assertThat(rows).isEqualTo(1)
@@ -279,8 +279,8 @@ open class CanonicalSpringKotlinTemplateDirectTest {
279279

280280
val rows = template.withKeyHolder(keyHolder) {
281281
insertInto(generatedAlways) {
282-
set(generatedAlways.firstName).toValue("Fred")
283-
set(generatedAlways.lastName).toValue("Flintstone")
282+
set(generatedAlways.firstName) toValue "Fred"
283+
set(generatedAlways.lastName) toValue "Flintstone"
284284
}
285285
}
286286

src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTest.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ open class CanonicalSpringKotlinTest {
272272
fun testGeneralInsert() {
273273

274274
val insertStatement = insertInto(person) {
275-
set(id).toConstant("100")
276-
set(firstName).toStringConstant("Joe")
277-
set(lastName).toValue(LastName("Jones"))
278-
set(birthDate).toValue(Date())
279-
set(employed).toValue(true)
275+
set(id) toConstant "100"
276+
set(firstName) toStringConstant "Joe"
277+
set(lastName) toValue LastName("Jones")
278+
set(birthDate) toValue Date()
279+
set(employed) toValue true
280280
set(occupation).toNull()
281-
set(addressId).toValue(1)
281+
set(addressId) toValue 1
282282
}
283283

284284
val expected =
@@ -309,13 +309,13 @@ open class CanonicalSpringKotlinTest {
309309
fun testGeneralInsertSpecialConditions() {
310310

311311
val insertStatement = insertInto(person) {
312-
set(id).toConstant("100")
313-
set(firstName).toStringConstant("Joe")
314-
set(lastName).toValue(LastName("Jones"))
315-
set(birthDate).toValue(Date())
316-
set(employed).toValueOrNull(true)
317-
set(occupation).toValueWhenPresent(null)
318-
set(addressId).toValue(1)
312+
set(id) toConstant "100"
313+
set(firstName) toStringConstant "Joe"
314+
set(lastName) toValue LastName("Jones")
315+
set(birthDate) toValue Date()
316+
set(employed) toValueOrNull true
317+
set(occupation) toValueWhenPresent null
318+
set(addressId) toValue 1
319319
}
320320

321321
val expected =
@@ -453,8 +453,8 @@ open class CanonicalSpringKotlinTest {
453453
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
454454
fun testGeneralInsertWithGeneratedKey() {
455455
val insertStatement = insertInto(generatedAlways) {
456-
set(generatedAlways.firstName).toValue("Fred")
457-
set(generatedAlways.lastName).toValue("Flintstone")
456+
set(generatedAlways.firstName) toValue "Fred"
457+
set(generatedAlways.lastName) toValue "Flintstone"
458458
}
459459

460460
val keyHolder = GeneratedKeyHolder()

0 commit comments

Comments
 (0)