Skip to content

Commit

Permalink
Replace deprecated put with update and upsert in the Kotilin sample
Browse files Browse the repository at this point in the history
  • Loading branch information
KodaiD committed Nov 11, 2024
1 parent d686570 commit 17c6dfa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions scalardb-kotlin-sample/src/main/kotlin/sample/ElectronicMoney.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package sample

import com.scalar.db.api.DistributedTransactionManager
import com.scalar.db.api.Get
import com.scalar.db.api.Put
import com.scalar.db.api.Update
import com.scalar.db.api.Upsert
import com.scalar.db.exception.transaction.TransactionException
import com.scalar.db.io.Key
import com.scalar.db.service.TransactionFactory
Expand Down Expand Up @@ -43,13 +44,13 @@ class ElectronicMoney(scalarDBProperties: String) {
}

// Update the balance
val put = Put.newBuilder()
val upsert = Upsert.newBuilder()
.namespace(NAMESPACE)
.table(TABLENAME)
.partitionKey(Key.ofText(ID, id))
.intValue(BALANCE, balance)
.build()
tx.put(put)
tx.upsert(upsert)

// Commit the transaction (records are automatically recovered in case of failure)
tx.commit()
Expand Down Expand Up @@ -86,20 +87,20 @@ class ElectronicMoney(scalarDBProperties: String) {
}

// Update the balances
val fromPut = Put.newBuilder()
val fromUpdate = Update.newBuilder()
.namespace(NAMESPACE)
.table(TABLENAME)
.partitionKey(Key.ofText(ID, fromId))
.intValue(BALANCE, newFromBalance)
.build()
val toPut = Put.newBuilder()
val toUpdate = Update.newBuilder()
.namespace(NAMESPACE)
.table(TABLENAME)
.partitionKey(Key.ofText(ID, toId))
.intValue(BALANCE, newToBalance)
.build()
tx.put(fromPut)
tx.put(toPut)
tx.update(fromUpdate)
tx.update(toUpdate)

// Commit the transaction (records are automatically recovered in case of failure)
tx.commit()
Expand Down

0 comments on commit 17c6dfa

Please sign in to comment.