Skip to content

Commit 70e6d3b

Browse files
committed
Remove Deprecated Kotlin Insert DSL
1 parent ca967c9 commit 70e6d3b

File tree

10 files changed

+14
-623
lines changed

10 files changed

+14
-623
lines changed

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/InsertStatements.kt

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

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ import org.mybatis.dynamic.sql.BasicColumn
2020
import org.mybatis.dynamic.sql.SqlBuilder
2121
import org.mybatis.dynamic.sql.SqlTable
2222
import org.mybatis.dynamic.sql.delete.DeleteModel
23-
import org.mybatis.dynamic.sql.insert.BatchInsertDSL
2423
import org.mybatis.dynamic.sql.insert.BatchInsertModel
2524
import org.mybatis.dynamic.sql.insert.GeneralInsertModel
26-
import org.mybatis.dynamic.sql.insert.InsertDSL
2725
import org.mybatis.dynamic.sql.insert.InsertModel
2826
import org.mybatis.dynamic.sql.insert.InsertSelectModel
29-
import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL
3027
import org.mybatis.dynamic.sql.insert.MultiRowInsertModel
3128
import org.mybatis.dynamic.sql.select.SelectModel
3229
import org.mybatis.dynamic.sql.update.UpdateModel
@@ -88,24 +85,6 @@ fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): InsertSelec
8885
fun insertSelect(completer: InsertSelectCompleter): InsertSelectModel =
8986
KotlinInsertSelectSubQueryBuilder().apply(completer).build()
9087

91-
@Deprecated("Please switch to the insertBatch statement in the model package")
92-
fun <T> BatchInsertDSL.IntoGatherer<T>.into(
93-
table: SqlTable,
94-
completer: BatchInsertDSL<T>.() -> Unit
95-
): BatchInsertModel<T> =
96-
into(table).apply(completer).build()
97-
98-
@Deprecated("Please switch to the insert statement in the model package")
99-
fun <T> InsertDSL.IntoGatherer<T>.into(table: SqlTable, completer: InsertDSL<T>.() -> Unit): InsertModel<T> =
100-
into(table).apply(completer).build()
101-
102-
@Deprecated("Please switch to the insertMultiple statement in the model package")
103-
fun <T> MultiRowInsertDSL.IntoGatherer<T>.into(
104-
table: SqlTable,
105-
completer: MultiRowInsertDSL<T>.() -> Unit
106-
): MultiRowInsertModel<T> =
107-
into(table).apply(completer).build()
108-
10988
fun select(vararg columns: BasicColumn, completer: SelectCompleter): SelectModel =
11089
select(columns.asList(), completer)
11190

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ package org.mybatis.dynamic.sql.util.kotlin.mybatis3
1919
import org.mybatis.dynamic.sql.BasicColumn
2020
import org.mybatis.dynamic.sql.SqlTable
2121
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider
22-
import org.mybatis.dynamic.sql.insert.BatchInsertDSL
23-
import org.mybatis.dynamic.sql.insert.InsertDSL
24-
import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL
2522
import org.mybatis.dynamic.sql.insert.render.BatchInsert
2623
import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider
2724
import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider
@@ -48,7 +45,6 @@ import org.mybatis.dynamic.sql.util.kotlin.model.insertBatch
4845
import org.mybatis.dynamic.sql.util.kotlin.model.insertInto
4946
import org.mybatis.dynamic.sql.util.kotlin.model.insertMultiple
5047
import org.mybatis.dynamic.sql.util.kotlin.model.insertSelect
51-
import org.mybatis.dynamic.sql.util.kotlin.model.into
5248
import org.mybatis.dynamic.sql.util.kotlin.model.select
5349
import org.mybatis.dynamic.sql.util.kotlin.model.selectDistinct
5450
import org.mybatis.dynamic.sql.util.kotlin.model.update
@@ -83,31 +79,9 @@ fun <T : Any> insertMultiple(
8379
): MultiRowInsertStatementProvider<T> =
8480
insertMultiple(rows, completer).render(RenderingStrategies.MYBATIS3)
8581

86-
@Deprecated("Please use the new form - move the table into the lambda with into(table)")
87-
fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): InsertSelectStatementProvider =
88-
insertSelect(table, completer).render(RenderingStrategies.MYBATIS3)
89-
9082
fun insertSelect(completer: InsertSelectCompleter): InsertSelectStatementProvider =
9183
insertSelect(completer).render(RenderingStrategies.MYBATIS3)
9284

93-
@Deprecated("Please switch to the insertBatch statement in the mybatis3 package")
94-
fun <T> BatchInsertDSL.IntoGatherer<T>.into(table: SqlTable, completer: BatchInsertDSL<T>.() -> Unit): BatchInsert<T> =
95-
into(table, completer).render(RenderingStrategies.MYBATIS3)
96-
97-
@Deprecated("Please switch to the insert statement in the mybatis3 package")
98-
fun <T> InsertDSL.IntoGatherer<T>.into(
99-
table: SqlTable,
100-
completer: InsertDSL<T>.() -> Unit
101-
): InsertStatementProvider<T> =
102-
into(table, completer).render(RenderingStrategies.MYBATIS3)
103-
104-
@Deprecated("Please switch to the insertMultiple statement in the mybatis3 package")
105-
fun <T> MultiRowInsertDSL.IntoGatherer<T>.into(
106-
table: SqlTable,
107-
completer: MultiRowInsertDSL<T>.() -> Unit
108-
): MultiRowInsertStatementProvider<T> =
109-
into(table, completer).render(RenderingStrategies.MYBATIS3)
110-
11185
fun select(vararg columns: BasicColumn, completer: SelectCompleter): SelectStatementProvider =
11286
select(columns.asList(), completer).render(RenderingStrategies.MYBATIS3)
11387

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ fun <T : Any> NamedParameterJdbcTemplate.insertBatch(
8080
): IntArray =
8181
insertBatch(org.mybatis.dynamic.sql.util.kotlin.spring.insertBatch(records, completer))
8282

83-
@Deprecated("Please move the into phrase inside the lambda")
84-
fun <T : Any> NamedParameterJdbcTemplate.insertBatch(vararg records: T): BatchInsertHelper<T> =
85-
insertBatch(records.asList())
86-
87-
@Deprecated("Please move the into phrase inside the lambda")
88-
fun <T : Any> NamedParameterJdbcTemplate.insertBatch(records: List<T>): BatchInsertHelper<T> =
89-
BatchInsertHelper(records, this)
90-
9183
// single row insert
9284
fun <T> NamedParameterJdbcTemplate.insert(insertStatement: InsertStatementProvider<T>): Int =
9385
update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement.row))
@@ -101,10 +93,6 @@ fun <T> NamedParameterJdbcTemplate.insert(
10193
fun <T : Any> NamedParameterJdbcTemplate.insert(row: T, completer: KotlinInsertCompleter<T>): Int =
10294
insert(org.mybatis.dynamic.sql.util.kotlin.spring.insert(row, completer))
10395

104-
@Deprecated("Please move the into phrase inside the lambda")
105-
fun <T : Any> NamedParameterJdbcTemplate.insert(row: T): SingleRowInsertHelper<T> =
106-
SingleRowInsertHelper(row, this)
107-
10896
// general insert
10997
fun NamedParameterJdbcTemplate.generalInsert(insertStatement: GeneralInsertStatementProvider): Int =
11098
update(insertStatement.insertStatement, insertStatement.parameters)
@@ -131,14 +119,6 @@ fun <T : Any> NamedParameterJdbcTemplate.insertMultiple(
131119
): Int =
132120
insertMultiple(org.mybatis.dynamic.sql.util.kotlin.spring.insertMultiple(records, completer))
133121

134-
@Deprecated("Please move the into phrase inside the lambda")
135-
fun <T : Any> NamedParameterJdbcTemplate.insertMultiple(vararg records: T): MultiRowInsertHelper<T> =
136-
insertMultiple(records.asList())
137-
138-
@Deprecated("Please move the into phrase inside the lambda")
139-
fun <T : Any> NamedParameterJdbcTemplate.insertMultiple(records: List<T>): MultiRowInsertHelper<T> =
140-
MultiRowInsertHelper(records, this)
141-
142122
fun <T> NamedParameterJdbcTemplate.insertMultiple(insertStatement: MultiRowInsertStatementProvider<T>): Int =
143123
update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement))
144124

@@ -148,10 +128,6 @@ fun <T> NamedParameterJdbcTemplate.insertMultiple(
148128
): Int =
149129
update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement), keyHolder)
150130

151-
@Deprecated("Please use the new form - move the table into the lambda with into(table)")
152-
fun NamedParameterJdbcTemplate.insertSelect(table: SqlTable, completer: InsertSelectCompleter): Int =
153-
insertSelect(org.mybatis.dynamic.sql.util.kotlin.spring.insertSelect(table, completer))
154-
155131
fun NamedParameterJdbcTemplate.insertSelect(completer: InsertSelectCompleter): Int =
156132
insertSelect(org.mybatis.dynamic.sql.util.kotlin.spring.insertSelect(completer))
157133

@@ -291,102 +267,13 @@ class KeyHolderHelper(private val keyHolder: KeyHolder, private val template: Na
291267
fun <T : Any> insert(row: T, completer: KotlinInsertCompleter<T>): Int =
292268
template.insert(org.mybatis.dynamic.sql.util.kotlin.spring.insert(row, completer), keyHolder)
293269

294-
@Deprecated("Please move the into phrase inside the lambda")
295-
fun <T : Any> insert(row: T): SingleRowInsertWithKeyHolderHelper<T> =
296-
SingleRowInsertWithKeyHolderHelper(row, template, keyHolder)
297-
298270
fun <T : Any> insertMultiple(vararg records: T, completer: KotlinMultiRowInsertCompleter<T>): Int =
299271
insertMultiple(records.asList(), completer)
300272

301273
fun <T : Any> insertMultiple(records: List<T>, completer: KotlinMultiRowInsertCompleter<T>): Int =
302274
template.insertMultiple(org.mybatis.dynamic.sql.util.kotlin.spring.insertMultiple(records, completer),
303275
keyHolder)
304276

305-
@Deprecated("Please move the into phrase inside the lambda")
306-
fun <T : Any> insertMultiple(vararg records: T): MultiRowInsertWithKeyHolderHelper<T> =
307-
insertMultiple(records.asList())
308-
309-
@Deprecated("Please move the into phrase inside the lambda")
310-
fun <T : Any> insertMultiple(records: List<T>): MultiRowInsertWithKeyHolderHelper<T> =
311-
MultiRowInsertWithKeyHolderHelper(records, template, keyHolder)
312-
313-
fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): Int =
314-
template.insertSelect(org.mybatis.dynamic.sql.util.kotlin.spring.insertSelect(table, completer), keyHolder)
315-
}
316-
317-
@MyBatisDslMarker
318-
class BatchInsertHelper<T : Any>(private val records: List<T>, private val template: NamedParameterJdbcTemplate) {
319-
fun into(table: SqlTable, completer: KotlinBatchInsertCompleter<T>): IntArray =
320-
template.insertBatch(
321-
insertBatch(records) {
322-
into(table)
323-
run(completer)
324-
}
325-
)
326-
}
327-
328-
@MyBatisDslMarker
329-
class MultiRowInsertHelper<T : Any>(
330-
private val records: List<T>,
331-
private val template: NamedParameterJdbcTemplate
332-
) {
333-
fun into(table: SqlTable, completer: KotlinMultiRowInsertCompleter<T>): Int =
334-
with(
335-
insertMultiple(records) {
336-
into(table)
337-
run(completer)
338-
}
339-
) {
340-
template.insertMultiple(this)
341-
}
342-
}
343-
344-
@MyBatisDslMarker
345-
class MultiRowInsertWithKeyHolderHelper<T : Any>(
346-
private val records: List<T>,
347-
private val template: NamedParameterJdbcTemplate,
348-
private val keyHolder: KeyHolder
349-
) {
350-
fun into(table: SqlTable, completer: KotlinMultiRowInsertCompleter<T>): Int =
351-
with(
352-
insertMultiple(records) {
353-
into(table)
354-
run(completer)
355-
}
356-
) {
357-
template.insertMultiple(this, keyHolder)
358-
}
359-
}
360-
361-
@MyBatisDslMarker
362-
class SingleRowInsertHelper<T : Any>(
363-
private val row: T,
364-
private val template: NamedParameterJdbcTemplate
365-
) {
366-
fun into(table: SqlTable, completer: KotlinInsertCompleter<T>): Int =
367-
with(
368-
insert(row) {
369-
into(table)
370-
run(completer)
371-
}
372-
) {
373-
template.insert(this)
374-
}
375-
}
376-
377-
@MyBatisDslMarker
378-
class SingleRowInsertWithKeyHolderHelper<T : Any>(
379-
private val row: T,
380-
private val template: NamedParameterJdbcTemplate,
381-
private val keyHolder: KeyHolder
382-
) {
383-
fun into(table: SqlTable, completer: KotlinInsertCompleter<T>): Int =
384-
with(
385-
insert(row) {
386-
into(table)
387-
run(completer)
388-
}
389-
) {
390-
template.insert(this, keyHolder)
391-
}
277+
fun insertSelect(completer: InsertSelectCompleter): Int =
278+
template.insertSelect(org.mybatis.dynamic.sql.util.kotlin.spring.insertSelect(completer), keyHolder)
392279
}

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ package org.mybatis.dynamic.sql.util.kotlin.spring
1919
import org.mybatis.dynamic.sql.BasicColumn
2020
import org.mybatis.dynamic.sql.SqlTable
2121
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider
22-
import org.mybatis.dynamic.sql.insert.BatchInsertDSL
23-
import org.mybatis.dynamic.sql.insert.InsertDSL
24-
import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL
2522
import org.mybatis.dynamic.sql.insert.render.BatchInsert
2623
import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider
2724
import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider
@@ -48,7 +45,6 @@ import org.mybatis.dynamic.sql.util.kotlin.model.insertBatch
4845
import org.mybatis.dynamic.sql.util.kotlin.model.insertInto
4946
import org.mybatis.dynamic.sql.util.kotlin.model.insertMultiple
5047
import org.mybatis.dynamic.sql.util.kotlin.model.insertSelect
51-
import org.mybatis.dynamic.sql.util.kotlin.model.into
5248
import org.mybatis.dynamic.sql.util.kotlin.model.select
5349
import org.mybatis.dynamic.sql.util.kotlin.model.selectDistinct
5450
import org.mybatis.dynamic.sql.util.kotlin.model.update
@@ -83,31 +79,9 @@ fun <T : Any> insertMultiple(
8379
): MultiRowInsertStatementProvider<T> =
8480
insertMultiple(rows, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER)
8581

86-
@Deprecated("Please use the new form - move the table into the lambda with into(table)")
87-
fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): InsertSelectStatementProvider =
88-
insertSelect(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER)
89-
9082
fun insertSelect(completer: InsertSelectCompleter): InsertSelectStatementProvider =
9183
insertSelect(completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER)
9284

93-
@Deprecated("Please switch to the insertBatch statement in the spring package")
94-
fun <T> BatchInsertDSL.IntoGatherer<T>.into(table: SqlTable, completer: BatchInsertDSL<T>.() -> Unit): BatchInsert<T> =
95-
into(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER)
96-
97-
@Deprecated("Please switch to the insert statement in the spring package")
98-
fun <T> InsertDSL.IntoGatherer<T>.into(
99-
table: SqlTable,
100-
completer: InsertDSL<T>.() -> Unit
101-
): InsertStatementProvider<T> =
102-
into(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER)
103-
104-
@Deprecated("Please switch to the insertMultiple statement in the spring package")
105-
fun <T> MultiRowInsertDSL.IntoGatherer<T>.into(
106-
table: SqlTable,
107-
completer: MultiRowInsertDSL<T>.() -> Unit
108-
): MultiRowInsertStatementProvider<T> =
109-
into(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER)
110-
11185
fun select(vararg columns: BasicColumn, completer: SelectCompleter): SelectStatementProvider =
11286
select(columns.asList(), completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER)
11387

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import org.apache.ibatis.session.ExecutorType
2323
import org.apache.ibatis.session.SqlSession
2424
import org.assertj.core.api.Assertions.assertThat
2525
import org.junit.jupiter.api.Test
26-
import org.mybatis.dynamic.sql.util.kotlin.elements.insertBatch
2726
import org.mybatis.dynamic.sql.util.kotlin.mybatis3.insertInto
28-
import org.mybatis.dynamic.sql.util.kotlin.mybatis3.into
2927

3028
class GeneratedAlwaysTest {
3129
private fun newSession(executorType: ExecutorType = ExecutorType.REUSE): SqlSession {
@@ -110,40 +108,6 @@ class GeneratedAlwaysTest {
110108
}
111109
}
112110

113-
@Test
114-
fun testDeprecatedInsertBatch() {
115-
newSession(ExecutorType.BATCH).use { session ->
116-
val mapper = session.getMapper(GeneratedAlwaysMapper::class.java)
117-
118-
val record1 = GeneratedAlwaysRecord(
119-
firstName = "Fred",
120-
lastName = "Flintstone"
121-
)
122-
123-
val record2 = GeneratedAlwaysRecord(
124-
firstName = "Barney",
125-
lastName = "Rubble"
126-
)
127-
128-
insertBatch(record1, record2).into(generatedAlways) {
129-
map(firstName).toProperty("firstName")
130-
map(lastName).toProperty("lastName")
131-
}.insertStatements().map(mapper::insert)
132-
133-
val batchResults = mapper.flush()
134-
135-
assertThat(batchResults).hasSize(1)
136-
assertThat(batchResults[0].updateCounts).hasSize(2)
137-
assertThat(batchResults[0].updateCounts[0]).isEqualTo(1)
138-
assertThat(batchResults[0].updateCounts[1]).isEqualTo(1)
139-
140-
assertThat(record1.id).isEqualTo(22)
141-
assertThat(record1.fullName).isEqualTo("Fred Flintstone")
142-
assertThat(record2.id).isEqualTo(23)
143-
assertThat(record2.fullName).isEqualTo("Barney Rubble")
144-
}
145-
}
146-
147111
@Test
148112
fun testGeneralInsert() {
149113
newSession().use { session ->

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ class PersonMapperTest {
255255
sqlSessionFactory.openSession().use { session ->
256256
val mapper = session.getMapper(PersonMapper::class.java)
257257

258-
val insertStatement = insertSelect(person) {
258+
val insertStatement = insertSelect {
259+
into(person)
259260
columns(id, firstName, lastName, employed, occupation, addressId, birthDate)
260261
select(add(id, constant<Int>("100")), firstName, lastName, employed, occupation, addressId, birthDate) {
261262
from(person)

0 commit comments

Comments
 (0)