Skip to content

Commit f0c1d5a

Browse files
authored
Merge pull request #496 from jeffgbutler/definitely-non-null
[Kotlin] Update to Definitely Non-Null Types Where Appropriate
2 parents 453c2b7 + ec771bd commit f0c1d5a

31 files changed

+2242
-94
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=miles
1212
2. Added the ability to specify a table alias on DELETE and UPDATE statements.
1313
This is especially useful when working with a sub-query with an exists or not exists condition.
1414
([#489](https://github.com/mybatis/mybatis-dynamic-sql/pull/489))
15+
3. Updated the Kotlin DSL to use Kotlin 1.7's new "definitely non-null" types where appropriate. This helps us to more
16+
accurately represent the nullable/non-nullable expectations for API method calls.
17+
([#496](https://github.com/mybatis/mybatis-dynamic-sql/pull/496))
1518

1619
## Release 1.4.0 - March 3, 2022
1720

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@
230230
<optional>true</optional>
231231
</dependency>
232232

233+
<dependency>
234+
<groupId>org.jetbrains.kotlin</groupId>
235+
<artifactId>kotlin-compiler</artifactId>
236+
<version>${kotlin.version}</version>
237+
<scope>test</scope>
238+
</dependency>
233239
<dependency>
234240
<groupId>org.junit.jupiter</groupId>
235241
<artifactId>junit-jupiter-api</artifactId>

src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSL.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public R build() {
5959
return adapterFunction.apply(deleteModel);
6060
}
6161

62-
public static <R> DeleteDSL<R> deleteFrom(Function<DeleteModel, R> adapterFunction, SqlTable table, String tableAlias) {
62+
public static <R> DeleteDSL<R> deleteFrom(Function<DeleteModel, R> adapterFunction, SqlTable table,
63+
String tableAlias) {
6364
return new DeleteDSL<>(table, tableAlias, adapterFunction);
6465
}
6566

src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java

Lines changed: 4 additions & 1 deletion
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.
@@ -17,6 +17,8 @@
1717

1818
import java.util.Objects;
1919

20+
import org.jetbrains.annotations.NotNull;
21+
2022
public class DefaultInsertStatementProvider<T> implements InsertStatementProvider<T> {
2123
private final String insertStatement;
2224
// need to keep both row and record for now so we don't break
@@ -37,6 +39,7 @@ public T getRecord() {
3739
}
3840

3941
@Override
42+
@NotNull
4043
public T getRow() {
4144
return row;
4245
}

src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.mybatis.dynamic.sql.insert.render;
1717

18+
import org.jetbrains.annotations.NotNull;
19+
1820
public interface InsertStatementProvider<T> {
1921
/**
2022
* Return the row associated with this insert statement.
@@ -30,6 +32,7 @@ public interface InsertStatementProvider<T> {
3032
*
3133
* @return the row associated with this insert statement.
3234
*/
35+
@NotNull
3336
T getRow();
3437

3538
/**

src/main/java/org/mybatis/dynamic/sql/update/render/SetPhraseVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public SetPhraseVisitor(AtomicInteger sequence, RenderingStrategy renderingStrat
5555

5656
@Override
5757
public Optional<FragmentAndParameters> visit(NullMapping mapping) {
58-
return FragmentAndParameters.withFragment(mapping.mapColumn(aliasedColumnNameFunction) + " = null") //$NON-NLS-1$
58+
return FragmentAndParameters
59+
.withFragment(mapping.mapColumn(aliasedColumnNameFunction) + " = null") //$NON-NLS-1$
5960
.buildOptional();
6061
}
6162

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class GroupingCriteriaCollector {
243243

244244
fun BindableColumn<*>.isNotNull() = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotNull())
245245

246-
infix fun <T : Any> BindableColumn<T>.isEqualTo(value: T) =
246+
infix fun <T> BindableColumn<T>.isEqualTo(value: T & Any) =
247247
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo(value))
248248

249249
infix fun BindableColumn<*>.isEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit) =
@@ -252,10 +252,10 @@ class GroupingCriteriaCollector {
252252
infix fun BindableColumn<*>.isEqualTo(column: BasicColumn) =
253253
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo(column))
254254

255-
infix fun <T : Any> BindableColumn<T>.isEqualToWhenPresent(value: T?) =
255+
infix fun <T> BindableColumn<T>.isEqualToWhenPresent(value: T?) =
256256
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isEqualToWhenPresent(value))
257257

258-
infix fun <T : Any> BindableColumn<T>.isNotEqualTo(value: T) =
258+
infix fun <T> BindableColumn<T>.isNotEqualTo(value: T & Any) =
259259
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualTo(value))
260260

261261
infix fun BindableColumn<*>.isNotEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit) =
@@ -264,10 +264,10 @@ class GroupingCriteriaCollector {
264264
infix fun BindableColumn<*>.isNotEqualTo(column: BasicColumn) =
265265
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualTo(column))
266266

267-
infix fun <T : Any> BindableColumn<T>.isNotEqualToWhenPresent(value: T?) =
267+
infix fun <T> BindableColumn<T>.isNotEqualToWhenPresent(value: T?) =
268268
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualToWhenPresent(value))
269269

270-
infix fun <T : Any> BindableColumn<T>.isGreaterThan(value: T) =
270+
infix fun <T> BindableColumn<T>.isGreaterThan(value: T & Any) =
271271
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThan(value))
272272

273273
infix fun BindableColumn<*>.isGreaterThan(subQuery: KotlinSubQueryBuilder.() -> Unit) =
@@ -276,10 +276,10 @@ class GroupingCriteriaCollector {
276276
infix fun BindableColumn<*>.isGreaterThan(column: BasicColumn) =
277277
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThan(column))
278278

279-
infix fun <T : Any> BindableColumn<T>.isGreaterThanWhenPresent(value: T?) =
279+
infix fun <T> BindableColumn<T>.isGreaterThanWhenPresent(value: T?) =
280280
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanWhenPresent(value))
281281

282-
infix fun <T : Any> BindableColumn<T>.isGreaterThanOrEqualTo(value: T) =
282+
infix fun <T> BindableColumn<T>.isGreaterThanOrEqualTo(value: T & Any) =
283283
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanOrEqualTo(value))
284284

285285
infix fun BindableColumn<*>.isGreaterThanOrEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit) =
@@ -288,10 +288,10 @@ class GroupingCriteriaCollector {
288288
infix fun BindableColumn<*>.isGreaterThanOrEqualTo(column: BasicColumn) =
289289
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanOrEqualTo(column))
290290

291-
infix fun <T : Any> BindableColumn<T>.isGreaterThanOrEqualToWhenPresent(value: T?) =
291+
infix fun <T> BindableColumn<T>.isGreaterThanOrEqualToWhenPresent(value: T?) =
292292
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanOrEqualToWhenPresent(value))
293293

294-
infix fun <T : Any> BindableColumn<T>.isLessThan(value: T) =
294+
infix fun <T> BindableColumn<T>.isLessThan(value: T & Any) =
295295
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThan(value))
296296

297297
infix fun BindableColumn<*>.isLessThan(subQuery: KotlinSubQueryBuilder.() -> Unit) =
@@ -300,10 +300,10 @@ class GroupingCriteriaCollector {
300300
infix fun BindableColumn<*>.isLessThan(column: BasicColumn) =
301301
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThan(column))
302302

303-
infix fun <T : Any> BindableColumn<T>.isLessThanWhenPresent(value: T?) =
303+
infix fun <T> BindableColumn<T>.isLessThanWhenPresent(value: T?) =
304304
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanWhenPresent(value))
305305

306-
infix fun <T : Any> BindableColumn<T>.isLessThanOrEqualTo(value: T) =
306+
infix fun <T> BindableColumn<T>.isLessThanOrEqualTo(value: T & Any) =
307307
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualTo(value))
308308

309309
infix fun BindableColumn<*>.isLessThanOrEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit) =
@@ -312,66 +312,66 @@ class GroupingCriteriaCollector {
312312
infix fun BindableColumn<*>.isLessThanOrEqualTo(column: BasicColumn) =
313313
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualTo(column))
314314

315-
infix fun <T : Any> BindableColumn<T>.isLessThanOrEqualToWhenPresent(value: T?) =
315+
infix fun <T> BindableColumn<T>.isLessThanOrEqualToWhenPresent(value: T?) =
316316
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualToWhenPresent(value))
317317

318-
fun <T : Any> BindableColumn<T>.isIn(vararg values: T) = isIn(values.asList())
318+
fun <T> BindableColumn<T>.isIn(vararg values: T & Any) = isIn(values.asList())
319319

320-
infix fun <T : Any> BindableColumn<T>.isIn(values: Collection<T>) =
320+
infix fun <T> BindableColumn<T>.isIn(values: Collection<T & Any>) =
321321
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isIn(values))
322322

323323
infix fun BindableColumn<*>.isIn(subQuery: KotlinSubQueryBuilder.() -> Unit) =
324324
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isIn(subQuery))
325325

326-
fun <T : Any> BindableColumn<T>.isInWhenPresent(vararg values: T?) = isInWhenPresent(values.asList())
326+
fun <T> BindableColumn<T>.isInWhenPresent(vararg values: T?) = isInWhenPresent(values.asList())
327327

328-
infix fun <T : Any> BindableColumn<T>.isInWhenPresent(values: Collection<T?>?) =
328+
infix fun <T> BindableColumn<T>.isInWhenPresent(values: Collection<T?>?) =
329329
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent(values))
330330

331-
fun <T : Any> BindableColumn<T>.isNotIn(vararg values: T) = isNotIn(values.asList())
331+
fun <T> BindableColumn<T>.isNotIn(vararg values: T & Any) = isNotIn(values.asList())
332332

333-
infix fun <T : Any> BindableColumn<T>.isNotIn(values: Collection<T>) =
333+
infix fun <T> BindableColumn<T>.isNotIn(values: Collection<T & Any>) =
334334
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotIn(values))
335335

336336
infix fun BindableColumn<*>.isNotIn(subQuery: KotlinSubQueryBuilder.() -> Unit) =
337337
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotIn(subQuery))
338338

339-
fun <T : Any> BindableColumn<T>.isNotInWhenPresent(vararg values: T?) = isNotInWhenPresent(values.asList())
339+
fun <T> BindableColumn<T>.isNotInWhenPresent(vararg values: T?) = isNotInWhenPresent(values.asList())
340340

341-
infix fun <T : Any> BindableColumn<T>.isNotInWhenPresent(values: Collection<T?>?) =
341+
infix fun <T> BindableColumn<T>.isNotInWhenPresent(values: Collection<T?>?) =
342342
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent(values))
343343

344-
infix fun <T : Any> BindableColumn<T>.isBetween(value1: T) =
345-
SecondValueCollector<T> {
344+
infix fun <T> BindableColumn<T>.isBetween(value1: T & Any) =
345+
SecondValueCollector<T & Any> {
346346
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isBetween(value1).and(it))
347347
}
348348

349-
infix fun <T : Any> BindableColumn<T>.isBetweenWhenPresent(value1: T?) =
349+
infix fun <T> BindableColumn<T>.isBetweenWhenPresent(value1: T?) =
350350
NullableSecondValueCollector<T> {
351351
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isBetweenWhenPresent(value1).and(it))
352352
}
353353

354-
infix fun <T : Any> BindableColumn<T>.isNotBetween(value1: T) =
355-
SecondValueCollector<T> {
354+
infix fun <T> BindableColumn<T>.isNotBetween(value1: T & Any) =
355+
SecondValueCollector<T & Any> {
356356
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetween(value1).and(it))
357357
}
358358

359-
infix fun <T : Any> BindableColumn<T>.isNotBetweenWhenPresent(value1: T?) =
359+
infix fun <T> BindableColumn<T>.isNotBetweenWhenPresent(value1: T?) =
360360
NullableSecondValueCollector<T> {
361361
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetweenWhenPresent(value1).and(it))
362362
}
363363

364364
// for string columns, but generic for columns with type handlers
365-
infix fun <T : Any> BindableColumn<T>.isLike(value: T) =
365+
infix fun <T> BindableColumn<T>.isLike(value: T & Any) =
366366
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLike(value))
367367

368-
infix fun <T : Any> BindableColumn<T>.isLikeWhenPresent(value: T?) =
368+
infix fun <T> BindableColumn<T>.isLikeWhenPresent(value: T?) =
369369
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLikeWhenPresent(value))
370370

371-
infix fun <T : Any> BindableColumn<T>.isNotLike(value: T) =
371+
infix fun <T> BindableColumn<T>.isNotLike(value: T & Any) =
372372
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotLike(value))
373373

374-
infix fun <T : Any> BindableColumn<T>.isNotLikeWhenPresent(value: T?) =
374+
infix fun <T> BindableColumn<T>.isNotLikeWhenPresent(value: T?) =
375375
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotLikeWhenPresent(value))
376376

377377
// shortcuts for booleans

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import org.mybatis.dynamic.sql.util.Buildable
2525
typealias KotlinBatchInsertCompleter<T> = KotlinBatchInsertBuilder<T>.() -> Unit
2626

2727
@MyBatisDslMarker
28-
class KotlinBatchInsertBuilder<T> (private val rows: Collection<T>): Buildable<BatchInsertModel<T>> {
28+
class KotlinBatchInsertBuilder<T : Any> (private val rows: Collection<T>): Buildable<BatchInsertModel<T>> {
2929
private var table: SqlTable? = null
3030
private val columnMappings = mutableListOf<AbstractColumnMapping>()
3131

3232
fun into(table: SqlTable) {
3333
this.table = table
3434
}
3535

36-
fun <C : Any> map(column: SqlColumn<C>) = MultiRowInsertColumnMapCompleter(column) {
36+
fun <C> map(column: SqlColumn<C>) = MultiRowInsertColumnMapCompleter(column) {
3737
columnMappings.add(it)
3838
}
3939

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class KotlinGeneralInsertBuilder(private val table: SqlTable) : Buildable<Genera
2929

3030
private val columnMappings = mutableListOf<AbstractColumnMapping>()
3131

32-
fun <T : Any> set(column: SqlColumn<T>) = GeneralInsertColumnSetCompleter(column) {
32+
fun <T> set(column: SqlColumn<T>) = GeneralInsertColumnSetCompleter(column) {
3333
columnMappings.add(it)
3434
}
3535

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import org.mybatis.dynamic.sql.util.Buildable
2525
typealias KotlinInsertCompleter<T> = KotlinInsertBuilder<T>.() -> Unit
2626

2727
@MyBatisDslMarker
28-
class KotlinInsertBuilder<T> (private val row: T): Buildable<InsertModel<T>> {
28+
class KotlinInsertBuilder<T : Any> (private val row: T): Buildable<InsertModel<T>> {
2929
private var table: SqlTable? = null
3030
private val columnMappings = mutableListOf<AbstractColumnMapping>()
3131

3232
fun into(table: SqlTable) {
3333
this.table = table
3434
}
3535

36-
fun <C : Any> map(column: SqlColumn<C>) = SingleRowInsertColumnMapCompleter(column) {
36+
fun <C> map(column: SqlColumn<C>) = SingleRowInsertColumnMapCompleter(column) {
3737
columnMappings.add(it)
3838
}
3939

0 commit comments

Comments
 (0)