Skip to content

Commit 26ea467

Browse files
committed
Reuse existing functions for the between conditions
1 parent c951c97 commit 26ea467

File tree

2 files changed

+20
-48
lines changed

2 files changed

+20
-48
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,24 @@ class GroupingCriteriaCollector {
267267
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent(values))
268268

269269
infix fun <T : Any> BindableColumn<T>.isBetween(value1: T) =
270-
InfixBetweenBuilder(value1) { invoke(it) }
270+
SecondValueCollector<T> {
271+
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isBetween(value1).and(it))
272+
}
271273

272274
infix fun <T : Any> BindableColumn<T>.isBetweenWhenPresent(value1: T?) =
273-
InfixBetweenWhenPresentBuilder(value1) { invoke(it) }
275+
NullableSecondValueCollector<T> {
276+
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isBetweenWhenPresent(value1).and(it))
277+
}
274278

275279
infix fun <T : Any> BindableColumn<T>.isNotBetween(value1: T) =
276-
InfixNotBetweenBuilder(value1) { invoke(it) }
280+
SecondValueCollector<T> {
281+
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetween(value1).and(it))
282+
}
277283

278284
infix fun <T : Any> BindableColumn<T>.isNotBetweenWhenPresent(value1: T?) =
279-
InfixNotBetweenWhenPresentBuilder(value1) { invoke(it) }
285+
NullableSecondValueCollector<T> {
286+
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetweenWhenPresent(value1).and(it))
287+
}
280288

281289
// for string columns, but generic for columns with type handlers
282290
infix fun <T : Any> BindableColumn<T>.isLike(value: T) =
@@ -332,3 +340,11 @@ class GroupingCriteriaCollector {
332340
infix fun BindableColumn<String>.isNotInCaseInsensitiveWhenPresent(values: Collection<String?>?) =
333341
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInCaseInsensitiveWhenPresent(values))
334342
}
343+
344+
class SecondValueCollector<T> (private val consumer: (T) -> Unit) {
345+
infix fun and(value2: T) = consumer.invoke(value2)
346+
}
347+
348+
class NullableSecondValueCollector<T> (private val consumer: (T?) -> Unit) {
349+
infix fun and(value2: T?) = consumer.invoke(value2)
350+
}

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

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)