Skip to content

Commit 35706cd

Browse files
committed
Refactor Kotlin Paging DSL
1 parent 016ea37 commit 35706cd

File tree

3 files changed

+44
-32
lines changed

3 files changed

+44
-32
lines changed

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import org.mybatis.dynamic.sql.util.Buildable
2626
typealias MultiSelectCompleter = KotlinMultiSelectBuilder.() -> Unit
2727

2828
@MyBatisDslMarker
29-
class KotlinMultiSelectBuilder: Buildable<MultiSelectModel> {
29+
class KotlinMultiSelectBuilder: Buildable<MultiSelectModel>, KotlinPagingDSL {
3030
private var dsl: MultiSelectDSL? = null
3131
set(value) {
3232
assertNull(field, "ERROR.33") //$NON-NLS-1$
@@ -63,27 +63,15 @@ class KotlinMultiSelectBuilder: Buildable<MultiSelectModel> {
6363
getDsl().orderBy(columns.asList())
6464
}
6565

66-
fun limit(limit: Long) {
67-
limitWhenPresent(limit)
68-
}
69-
70-
fun limitWhenPresent(limit: Long?) {
66+
override fun limitWhenPresent(limit: Long?) {
7167
getDsl().limitWhenPresent(limit)
7268
}
7369

74-
fun offset(offset: Long) {
75-
offsetWhenPresent(offset)
76-
}
77-
78-
fun offsetWhenPresent(offset: Long?) {
70+
override fun offsetWhenPresent(offset: Long?) {
7971
getDsl().offsetWhenPresent(offset)
8072
}
8173

82-
fun fetchFirst(fetchFirstRows: Long) {
83-
fetchFirstWhenPresent(fetchFirstRows)
84-
}
85-
86-
fun fetchFirstWhenPresent(fetchFirstRows: Long?) {
74+
override fun fetchFirstWhenPresent(fetchFirstRows: Long?) {
8775
getDsl().fetchFirstWhenPresent(fetchFirstRows).rowsOnly()
8876
}
8977

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2016-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.util.kotlin
17+
18+
interface KotlinPagingDSL {
19+
fun limit(limit: Long) {
20+
limitWhenPresent(limit)
21+
}
22+
23+
fun limitWhenPresent(limit: Long?)
24+
25+
fun offset(offset: Long) {
26+
offsetWhenPresent(offset)
27+
}
28+
29+
fun offsetWhenPresent(offset: Long?)
30+
31+
fun fetchFirst(fetchFirstRows: Long) {
32+
fetchFirstWhenPresent(fetchFirstRows)
33+
}
34+
35+
fun fetchFirstWhenPresent(fetchFirstRows: Long?)
36+
}

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typealias SelectCompleter = KotlinSelectBuilder.() -> Unit
2828

2929
@Suppress("TooManyFunctions")
3030
class KotlinSelectBuilder(private val fromGatherer: QueryExpressionDSL.FromGatherer<SelectModel>) :
31-
KotlinBaseJoiningBuilder<QueryExpressionDSL<SelectModel>>(), Buildable<SelectModel> {
31+
KotlinBaseJoiningBuilder<QueryExpressionDSL<SelectModel>>(), Buildable<SelectModel>, KotlinPagingDSL {
3232

3333
private var dsl: KQueryExpressionDSL? = null
3434

@@ -58,27 +58,15 @@ class KotlinSelectBuilder(private val fromGatherer: QueryExpressionDSL.FromGathe
5858
getDsl().orderBy(columns.toList())
5959
}
6060

61-
fun limit(limit: Long) {
62-
limitWhenPresent(limit)
63-
}
64-
65-
fun limitWhenPresent(limit: Long?) {
61+
override fun limitWhenPresent(limit: Long?) {
6662
getDsl().limitWhenPresent(limit)
6763
}
6864

69-
fun offset(offset: Long) {
70-
offsetWhenPresent(offset)
71-
}
72-
73-
fun offsetWhenPresent(offset: Long?) {
65+
override fun offsetWhenPresent(offset: Long?) {
7466
getDsl().offsetWhenPresent(offset)
7567
}
7668

77-
fun fetchFirst(fetchFirstRows: Long) {
78-
fetchFirstWhenPresent(fetchFirstRows)
79-
}
80-
81-
fun fetchFirstWhenPresent(fetchFirstRows: Long?) {
69+
override fun fetchFirstWhenPresent(fetchFirstRows: Long?) {
8270
getDsl().fetchFirstWhenPresent(fetchFirstRows).rowsOnly()
8371
}
8472

0 commit comments

Comments
 (0)