Skip to content

Commit

Permalink
refactor!: EXPOSED-436 Replace onUpdate parameter with one that takes…
Browse files Browse the repository at this point in the history
… lambda

- Remove unecessary test changes
- Add missing deprecated class constructor parameter
- Add back deprecated property and move out of constructor
  • Loading branch information
bog-walk committed Aug 27, 2024
1 parent d7e86f3 commit 4736565
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
4 changes: 3 additions & 1 deletion exposed-core/api/exposed-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -3064,12 +3064,13 @@ public class org/jetbrains/exposed/sql/statements/BatchUpdateStatement : org/jet
}

public class org/jetbrains/exposed/sql/statements/BatchUpsertStatement : org/jetbrains/exposed/sql/statements/BaseBatchInsertStatement, org/jetbrains/exposed/sql/statements/UpsertBuilder {
public fun <init> (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;Lorg/jetbrains/exposed/sql/Op;)V
public fun <init> (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;Lorg/jetbrains/exposed/sql/Op;Z)V
public fun <init> (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Lorg/jetbrains/exposed/sql/Op;Z)V
public synthetic fun <init> (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Lorg/jetbrains/exposed/sql/Op;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun arguments ()Ljava/lang/Iterable;
public fun arguments ()Ljava/util/List;
public final fun getKeys ()[Lorg/jetbrains/exposed/sql/Column;
public final fun getOnUpdate ()Ljava/util/List;
public final fun getOnUpdateExclude ()Ljava/util/List;
public final fun getWhere ()Lorg/jetbrains/exposed/sql/Op;
public fun insertValue (Lorg/jetbrains/exposed/sql/Column;)Lorg/jetbrains/exposed/sql/ExpressionWithColumnType;
Expand Down Expand Up @@ -3411,6 +3412,7 @@ public class org/jetbrains/exposed/sql/statements/UpsertStatement : org/jetbrain
public synthetic fun arguments ()Ljava/lang/Iterable;
public fun arguments ()Ljava/util/List;
public final fun getKeys ()[Lorg/jetbrains/exposed/sql/Column;
public final fun getOnUpdate ()Ljava/util/List;
public final fun getOnUpdateExclude ()Ljava/util/List;
public final fun getWhere ()Lorg/jetbrains/exposed/sql/Op;
public fun insertValue (Lorg/jetbrains/exposed/sql/Column;)Lorg/jetbrains/exposed/sql/ExpressionWithColumnType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ open class BatchUpsertStatement(
vararg keys: Column<*>,
onUpdate: List<Pair<Column<*>, Expression<*>>>?,
onUpdateExclude: List<Column<*>>?,
where: Op<Boolean>?
) : this(table, keys = keys, onUpdateExclude, where) {
onUpdate?.let { updateValues.putAll(it) }
where: Op<Boolean>?,
shouldReturnGeneratedValues: Boolean
) : this(table, keys = keys, onUpdateExclude, where, shouldReturnGeneratedValues) {
onUpdate?.let {
this.onUpdate = it
updateValues.putAll(it)
}
}

@Deprecated("This property will be removed in future releases.", level = DeprecationLevel.WARNING)
var onUpdate: List<Pair<Column<*>, Expression<*>>>? = null
private set

internal val updateValues: MutableMap<Column<*>, Any?> = LinkedHashMap()

override fun prepareSQL(transaction: Transaction, prepared: Boolean): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ open class UpsertStatement<Key : Any>(
onUpdateExclude: List<Column<*>>?,
where: Op<Boolean>?
) : this(table, keys = keys, onUpdateExclude, where) {
onUpdate?.let { updateValues.putAll(it) }
onUpdate?.let {
this.onUpdate = it
updateValues.putAll(it)
}
}

@Deprecated("This property will be removed in future releases.", level = DeprecationLevel.WARNING)
var onUpdate: List<Pair<Column<*>, Expression<*>>>? = null
private set

internal val updateValues: MutableMap<Column<*>, Any?> = LinkedHashMap()

override fun prepareSQL(transaction: Transaction, prepared: Boolean): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ class JsonBColumnTests : DatabaseTestsBase() {

val newData2 = newData.copy(active = false)
tester.upsert {
it[id] = newId
it[jsonBColumn] = newData2
it[tester.id] = newId
it[tester.jsonBColumn] = newData2
}

val newResult = tester.selectAll().where { tester.id eq newId }.singleOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ class JsonColumnTests : DatabaseTestsBase() {

val newData2 = newData.copy(active = false)
tester.upsert {
it[id] = newId
it[jsonColumn] = newData2
it[tester.id] = newId
it[tester.jsonColumn] = newData2
}

val newResult = tester.selectAll().where { tester.id eq newId }.singleOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ class UpsertTests : DatabaseTestsBase() {
it[word] = "Word B"
it[count] = 9
}

val result = tester.selectAll().single()
assertEquals(900, result[tester.count])

Expand Down Expand Up @@ -438,9 +437,7 @@ class UpsertTests : DatabaseTestsBase() {
rollback()
}

tester.upsert(
onUpdateExclude = listOf(tester.code, tester.gains)
) {
tester.upsert(onUpdateExclude = listOf(tester.code, tester.gains)) {
it[item] = itemA
it[gains] = 200
it[losses] = 0
Expand Down

0 comments on commit 4736565

Please sign in to comment.