Skip to content

Commit 12e3de0

Browse files
committed
Add Kotlin Support for new select items
1 parent 1acab1b commit 12e3de0

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@ class KotlinSelectBuilder(private val fromGatherer: QueryExpressionDSL.FromGathe
7676
fun unionAll(unionAll: KotlinUnionBuilder.() -> Unit): Unit =
7777
unionAll(KotlinUnionBuilder(getDsl().unionAll()))
7878

79+
fun forUpdate() {
80+
getDsl().forUpdate()
81+
}
82+
83+
fun forNoKeyUpdate() {
84+
getDsl().forNoKeyUpdate()
85+
}
86+
87+
fun forShare() {
88+
getDsl().forShare()
89+
}
90+
91+
fun forKeyShare() {
92+
getDsl().forKeyShare()
93+
}
94+
95+
fun skipLocked() {
96+
getDsl().skipLocked()
97+
}
98+
99+
fun nowait() {
100+
getDsl().nowait()
101+
}
102+
79103
override fun build(): SelectModel = getDsl().build()
80104

81105
override fun getDsl(): KQueryExpressionDSL = invalidIfNull(dsl, "ERROR.27") //$NON-NLS-1$

src/test/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderTest.kt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,50 @@ class ModelBuilderTest {
4646

4747
assertThat(provider.selectStatement).isEqualTo("select distinct id, description from Table where id = :p1")
4848
}
49+
50+
@Test
51+
fun testSelectBuilderForUpdate() {
52+
val provider = select(id, description) {
53+
from(table)
54+
where { id isEqualTo 3 }
55+
forUpdate()
56+
skipLocked()
57+
}.render(RenderingStrategies.SPRING_NAMED_PARAMETER)
58+
59+
assertThat(provider.selectStatement).isEqualTo("select id, description from Table where id = :p1 for update skip locked")
60+
}
61+
62+
@Test
63+
fun testSelectBuilderForShare() {
64+
val provider = select(id, description) {
65+
from(table)
66+
where { id isEqualTo 3 }
67+
forShare()
68+
nowait()
69+
}.render(RenderingStrategies.SPRING_NAMED_PARAMETER)
70+
71+
assertThat(provider.selectStatement).isEqualTo("select id, description from Table where id = :p1 for share nowait")
72+
}
73+
74+
@Test
75+
fun testSelectBuilderForKeyShare() {
76+
val provider = select(id, description) {
77+
from(table)
78+
where { id isEqualTo 3 }
79+
forKeyShare()
80+
}.render(RenderingStrategies.SPRING_NAMED_PARAMETER)
81+
82+
assertThat(provider.selectStatement).isEqualTo("select id, description from Table where id = :p1 for key share")
83+
}
84+
85+
@Test
86+
fun testSelectBuilderForKeyNoKeyUpdate() {
87+
val provider = select(id, description) {
88+
from(table)
89+
where { id isEqualTo 3 }
90+
forNoKeyUpdate()
91+
}.render(RenderingStrategies.SPRING_NAMED_PARAMETER)
92+
93+
assertThat(provider.selectStatement).isEqualTo("select id, description from Table where id = :p1 for no key update")
94+
}
4995
}

0 commit comments

Comments
 (0)