From bb44f0624a03462d7c6fc184643b9b61f99988fa Mon Sep 17 00:00:00 2001 From: Kodai Doki Date: Thu, 7 Nov 2024 19:05:27 +0900 Subject: [PATCH 1/5] Replace deprecated Gradle features --- .../client/build.gradle | 13 ++++--- .../customer-service/build.gradle | 13 ++++--- .../order-service/build.gradle | 13 ++++--- .../rpc/build.gradle | 34 ++++++++++++++++--- multi-storage-transaction-sample/build.gradle | 13 ++++--- scalardb-kotlin-sample/build.gradle.kts | 11 ++---- scalardb-sample/build.gradle | 13 ++++--- scalardb-sql-jdbc-sample/build.gradle | 13 ++++--- .../client/build.gradle | 13 ++++--- .../customer-service/build.gradle | 13 ++++--- .../order-service/build.gradle | 13 ++++--- .../rpc/build.gradle | 34 ++++++++++++++++--- .../build.gradle | 13 ++++--- spring-data-sample/build.gradle | 13 ++++--- 14 files changed, 160 insertions(+), 62 deletions(-) diff --git a/microservice-transaction-sample/client/build.gradle b/microservice-transaction-sample/client/build.gradle index d9e03945..99172ba1 100644 --- a/microservice-transaction-sample/client/build.gradle +++ b/microservice-transaction-sample/client/build.gradle @@ -10,10 +10,15 @@ dependencies { } application { - mainClassName = 'sample.client.Client' + mainClass = 'sample.client.Client' } -archivesBaseName = "sample-order-service" +base { + archivesName = "sample-order-service" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/microservice-transaction-sample/customer-service/build.gradle b/microservice-transaction-sample/customer-service/build.gradle index 06a2d678..6b09fb0b 100644 --- a/microservice-transaction-sample/customer-service/build.gradle +++ b/microservice-transaction-sample/customer-service/build.gradle @@ -14,7 +14,7 @@ dependencies { } application { - mainClassName = 'sample.customer.CustomerServiceServer' + mainClass = 'sample.customer.CustomerServiceServer' } task copyFilesToDockerBuildContextDir(type: Copy) { @@ -47,7 +47,12 @@ installDist { duplicatesStrategy DuplicatesStrategy.EXCLUDE } -archivesBaseName = "sample-customer-service" +base { + archivesName = "sample-customer-service" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/microservice-transaction-sample/order-service/build.gradle b/microservice-transaction-sample/order-service/build.gradle index 93474998..d6acded6 100644 --- a/microservice-transaction-sample/order-service/build.gradle +++ b/microservice-transaction-sample/order-service/build.gradle @@ -14,7 +14,7 @@ dependencies { } application { - mainClassName = 'sample.order.OrderServiceServer' + mainClass = 'sample.order.OrderServiceServer' } task copyFilesToDockerBuildContextDir(type: Copy) { @@ -47,7 +47,12 @@ installDist { duplicatesStrategy DuplicatesStrategy.EXCLUDE } -archivesBaseName = "sample-order-service" +base { + archivesName = "sample-order-service" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/microservice-transaction-sample/rpc/build.gradle b/microservice-transaction-sample/rpc/build.gradle index c8f3a3d8..02dd34f1 100644 --- a/microservice-transaction-sample/rpc/build.gradle +++ b/microservice-transaction-sample/rpc/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' id 'java-library-distribution' - id 'com.google.protobuf' version '0.9.1' + id 'com.google.protobuf' version '0.9.4' } dependencies { @@ -20,10 +20,26 @@ protobuf { generateProtoTasks { all()*.plugins { grpc {} } } - generatedFilesBaseDir = "$projectDir/src" } -archivesBaseName = "sample-rpc" +base { + archivesName = "sample-rpc" +} + +// Task copyGeneratedProtoToSrc copies the generated .java files into src directory +task copyGeneratedProtoToSrc(type: Copy) { + description 'Copies generated Protocol Buffer classes to src/main/java/sample/rpc' + dependsOn generateProto + from "$buildDir/generated/source/proto/main/java/sample/rpc" + into "$projectDir/src/main/java/sample/rpc" + duplicatesStrategy = DuplicatesStrategy.INCLUDE +} + +// Task deleteBuildMainJava deletes the generated .java files in build directory +task deleteBuildMainJava(type: Delete) { + dependsOn copyGeneratedProtoToSrc + delete fileTree(dir: "$buildDir/generated/source/proto/main/java/sample/rpc") +} // The processResources task needs to depend on the generateProto task because it uses the output // of the the generateProto task @@ -31,5 +47,13 @@ processResources { dependsOn generateProto } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +// Task deleteBuildMainJava needs to depend on deleteBuildMainJava to avoid duplicate class error +tasks.named("compileJava").configure { + dependsOn deleteBuildMainJava +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/multi-storage-transaction-sample/build.gradle b/multi-storage-transaction-sample/build.gradle index 11e06ee0..eedb249e 100644 --- a/multi-storage-transaction-sample/build.gradle +++ b/multi-storage-transaction-sample/build.gradle @@ -16,10 +16,15 @@ dependencies { } application { - mainClassName = 'sample.command.SampleCommand' + mainClass = 'sample.command.SampleCommand' } -archivesBaseName = "sample" +base { + archivesName = "sample" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/scalardb-kotlin-sample/build.gradle.kts b/scalardb-kotlin-sample/build.gradle.kts index 1bc59a68..eb35aabf 100644 --- a/scalardb-kotlin-sample/build.gradle.kts +++ b/scalardb-kotlin-sample/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.8.21" + kotlin("jvm") version "2.0.21" application } @@ -21,13 +21,8 @@ tasks.test { useJUnitPlatform() } -tasks.withType { - kotlinOptions.jvmTarget = "1.8" -} - -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 +kotlin { + jvmToolchain(8) } application { diff --git a/scalardb-sample/build.gradle b/scalardb-sample/build.gradle index 11e06ee0..eedb249e 100644 --- a/scalardb-sample/build.gradle +++ b/scalardb-sample/build.gradle @@ -16,10 +16,15 @@ dependencies { } application { - mainClassName = 'sample.command.SampleCommand' + mainClass = 'sample.command.SampleCommand' } -archivesBaseName = "sample" +base { + archivesName = "sample" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/scalardb-sql-jdbc-sample/build.gradle b/scalardb-sql-jdbc-sample/build.gradle index 42de9652..c8dc0cf8 100644 --- a/scalardb-sql-jdbc-sample/build.gradle +++ b/scalardb-sql-jdbc-sample/build.gradle @@ -17,10 +17,15 @@ dependencies { } application { - mainClassName = 'sample.command.SampleCommand' + mainClass = 'sample.command.SampleCommand' } -archivesBaseName = "sample" +base { + archivesName = "sample" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/spring-data-microservice-transaction-sample/client/build.gradle b/spring-data-microservice-transaction-sample/client/build.gradle index d9e03945..99172ba1 100644 --- a/spring-data-microservice-transaction-sample/client/build.gradle +++ b/spring-data-microservice-transaction-sample/client/build.gradle @@ -10,10 +10,15 @@ dependencies { } application { - mainClassName = 'sample.client.Client' + mainClass = 'sample.client.Client' } -archivesBaseName = "sample-order-service" +base { + archivesName = "sample-order-service" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/spring-data-microservice-transaction-sample/customer-service/build.gradle b/spring-data-microservice-transaction-sample/customer-service/build.gradle index 3262cd70..a530ca2c 100644 --- a/spring-data-microservice-transaction-sample/customer-service/build.gradle +++ b/spring-data-microservice-transaction-sample/customer-service/build.gradle @@ -16,7 +16,7 @@ dependencies { } application { - mainClassName = 'sample.customer.CustomerServiceServer' + mainClass = 'sample.customer.CustomerServiceServer' } task copyFilesToDockerBuildContextDir(type: Copy) { @@ -49,7 +49,12 @@ installDist { duplicatesStrategy DuplicatesStrategy.EXCLUDE } -archivesBaseName = "sample-customer-service" +base { + archivesName = "sample-customer-service" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/spring-data-microservice-transaction-sample/order-service/build.gradle b/spring-data-microservice-transaction-sample/order-service/build.gradle index 92ee5f2c..a6013204 100644 --- a/spring-data-microservice-transaction-sample/order-service/build.gradle +++ b/spring-data-microservice-transaction-sample/order-service/build.gradle @@ -16,7 +16,7 @@ dependencies { } application { - mainClassName = 'sample.order.OrderServiceServer' + mainClass = 'sample.order.OrderServiceServer' } task copyFilesToDockerBuildContextDir(type: Copy) { @@ -49,7 +49,12 @@ installDist { duplicatesStrategy DuplicatesStrategy.EXCLUDE } -archivesBaseName = "sample-order-service" +base { + archivesName = "sample-order-service" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/spring-data-microservice-transaction-sample/rpc/build.gradle b/spring-data-microservice-transaction-sample/rpc/build.gradle index 59b163a7..4c6a6862 100644 --- a/spring-data-microservice-transaction-sample/rpc/build.gradle +++ b/spring-data-microservice-transaction-sample/rpc/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' id 'java-library-distribution' - id 'com.google.protobuf' version '0.9.1' + id 'com.google.protobuf' version '0.9.4' } dependencies { @@ -20,10 +20,26 @@ protobuf { generateProtoTasks { all()*.plugins { grpc {} } } - generatedFilesBaseDir = "$projectDir/src" } -archivesBaseName = "sample-rpc" +base { + archivesName = "sample-rpc" +} + +// Task copyGeneratedProtoToSrc copies the generated .java files into src directory +task copyGeneratedProtoToSrc(type: Copy) { + description 'Copies generated Protocol Buffer classes to src/main/java/sample/rpc' + dependsOn generateProto + from "$buildDir/generated/source/proto/main/java/sample/rpc" + into "$projectDir/src/main/java/sample/rpc" + duplicatesStrategy = DuplicatesStrategy.INCLUDE +} + +// Task deleteBuildMainJava deletes the generated .java files in build directory +task deleteBuildMainJava(type: Delete) { + dependsOn copyGeneratedProtoToSrc + delete fileTree(dir: "$buildDir/generated/source/proto/main/java/sample/rpc") +} // The processResources task needs to depend on the generateProto task because it uses the output // of the the generateProto task @@ -31,5 +47,13 @@ processResources { dependsOn generateProto } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +// Task deleteBuildMainJava needs to depend on deleteBuildMainJava to avoid duplicate class error +tasks.named("compileJava").configure { + dependsOn deleteBuildMainJava +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/spring-data-multi-storage-transaction-sample/build.gradle b/spring-data-multi-storage-transaction-sample/build.gradle index 359e66ca..7788ccea 100644 --- a/spring-data-multi-storage-transaction-sample/build.gradle +++ b/spring-data-multi-storage-transaction-sample/build.gradle @@ -24,10 +24,15 @@ dependencies { } application { - mainClassName = 'sample.SampleApp' + mainClass = 'sample.SampleApp' } -archivesBaseName = "sample" +base { + archivesName = "sample" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} diff --git a/spring-data-sample/build.gradle b/spring-data-sample/build.gradle index 359e66ca..7788ccea 100644 --- a/spring-data-sample/build.gradle +++ b/spring-data-sample/build.gradle @@ -24,10 +24,15 @@ dependencies { } application { - mainClassName = 'sample.SampleApp' + mainClass = 'sample.SampleApp' } -archivesBaseName = "sample" +base { + archivesName = "sample" +} -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} From d686570b876ea20d436a326d43085c03a6e2be0f Mon Sep 17 00:00:00 2001 From: Kodai Doki Date: Mon, 11 Nov 2024 11:16:03 +0900 Subject: [PATCH 2/5] Replace deprecated put with update and insert --- .../java/sample/customer/model/Customer.java | 11 ++++--- .../main/java/sample/order/model/Item.java | 6 ++-- .../main/java/sample/order/model/Order.java | 6 ++-- .../java/sample/order/model/Statement.java | 6 ++-- .../src/main/java/sample/Sample.java | 31 ++++++++++--------- .../src/main/java/sample/Sample.java | 31 ++++++++++--------- 6 files changed, 47 insertions(+), 44 deletions(-) diff --git a/microservice-transaction-sample/customer-service/src/main/java/sample/customer/model/Customer.java b/microservice-transaction-sample/customer-service/src/main/java/sample/customer/model/Customer.java index e241f1a8..e3163639 100644 --- a/microservice-transaction-sample/customer-service/src/main/java/sample/customer/model/Customer.java +++ b/microservice-transaction-sample/customer-service/src/main/java/sample/customer/model/Customer.java @@ -1,8 +1,9 @@ package sample.customer.model; import com.scalar.db.api.Get; -import com.scalar.db.api.Put; +import com.scalar.db.api.Insert; import com.scalar.db.api.TransactionCrudOperable; +import com.scalar.db.api.Update; import com.scalar.db.exception.transaction.CrudException; import com.scalar.db.io.Key; import java.util.Optional; @@ -30,8 +31,8 @@ public Customer(int id, String name, int creditLimit, int creditTotal) { public static void put( TransactionCrudOperable transaction, int id, String name, int creditLimit, int creditTotal) throws CrudException { - transaction.put( - Put.newBuilder() + transaction.insert( + Insert.newBuilder() .namespace(NAMESPACE) .table(TABLE) .partitionKey(Key.ofInt(COL_CUSTOMER_ID, id)) @@ -43,8 +44,8 @@ public static void put( public static void updateCreditTotal(TransactionCrudOperable transaction, int id, int creditTotal) throws CrudException { - transaction.put( - Put.newBuilder() + transaction.update( + Update.newBuilder() .namespace(NAMESPACE) .table(TABLE) .partitionKey(Key.ofInt(COL_CUSTOMER_ID, id)) diff --git a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Item.java b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Item.java index 9ea86692..86cd647b 100644 --- a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Item.java +++ b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Item.java @@ -1,7 +1,7 @@ package sample.order.model; import com.scalar.db.api.Get; -import com.scalar.db.api.Put; +import com.scalar.db.api.Insert; import com.scalar.db.api.TransactionCrudOperable; import com.scalar.db.exception.transaction.CrudException; import com.scalar.db.io.Key; @@ -27,8 +27,8 @@ public Item(int id, String name, int price) { public static void put(TransactionCrudOperable transaction, int id, String name, int price) throws CrudException { - transaction.put( - Put.newBuilder() + transaction.insert( + Insert.newBuilder() .namespace(NAMESPACE) .table(TABLE) .partitionKey(Key.ofInt(COL_ITEM_ID, id)) diff --git a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Order.java b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Order.java index e0eb2d48..23fb6a51 100644 --- a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Order.java +++ b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Order.java @@ -1,7 +1,7 @@ package sample.order.model; import com.scalar.db.api.Get; -import com.scalar.db.api.Put; +import com.scalar.db.api.Insert; import com.scalar.db.api.Result; import com.scalar.db.api.Scan; import com.scalar.db.api.Scan.Ordering; @@ -33,8 +33,8 @@ public Order(String id, int customerId, long timestamp) { public static void put( TransactionCrudOperable transaction, String id, int customerId, long timestamp) throws CrudException { - transaction.put( - Put.newBuilder() + transaction.insert( + Insert.newBuilder() .namespace(NAMESPACE) .table(TABLE) .partitionKey(Key.ofInt(COL_CUSTOMER_ID, customerId)) diff --git a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Statement.java b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Statement.java index 5e8c8698..dc2efa20 100644 --- a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Statement.java +++ b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Statement.java @@ -1,6 +1,6 @@ package sample.order.model; -import com.scalar.db.api.Put; +import com.scalar.db.api.Insert; import com.scalar.db.api.Scan; import com.scalar.db.api.TransactionCrudOperable; import com.scalar.db.exception.transaction.CrudException; @@ -28,8 +28,8 @@ public Statement(String orderId, int itemId, int count) { public static void put(TransactionCrudOperable transaction, String orderId, int itemId, int count) throws CrudException { - transaction.put( - Put.newBuilder() + transaction.insert( + Insert.newBuilder() .namespace(NAMESPACE) .table(TABLE) .partitionKey(Key.ofText(COL_ORDER_ID, orderId)) diff --git a/multi-storage-transaction-sample/src/main/java/sample/Sample.java b/multi-storage-transaction-sample/src/main/java/sample/Sample.java index 9458347a..9f015a2d 100644 --- a/multi-storage-transaction-sample/src/main/java/sample/Sample.java +++ b/multi-storage-transaction-sample/src/main/java/sample/Sample.java @@ -3,9 +3,10 @@ import com.scalar.db.api.DistributedTransaction; import com.scalar.db.api.DistributedTransactionManager; import com.scalar.db.api.Get; -import com.scalar.db.api.Put; +import com.scalar.db.api.Insert; import com.scalar.db.api.Result; import com.scalar.db.api.Scan; +import com.scalar.db.api.Update; import com.scalar.db.exception.transaction.TransactionException; import com.scalar.db.io.Key; import com.scalar.db.service.TransactionFactory; @@ -62,8 +63,8 @@ private void loadCustomerIfNotExists( .partitionKey(Key.ofInt("customer_id", customerId)) .build()); if (!customer.isPresent()) { - transaction.put( - Put.newBuilder() + transaction.insert( + Insert.newBuilder() .namespace("customer") .table("customers") .partitionKey(Key.ofInt("customer_id", customerId)) @@ -85,8 +86,8 @@ private void loadItemIfNotExists( .partitionKey(Key.ofInt("item_id", itemId)) .build()); if (!item.isPresent()) { - transaction.put( - Put.newBuilder() + transaction.insert( + Insert.newBuilder() .namespace("order") .table("items") .partitionKey(Key.ofInt("item_id", itemId)) @@ -146,9 +147,9 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts) // Start a transaction transaction = manager.start(); - // Put the order info into the orders table - transaction.put( - Put.newBuilder() + // Insert the order info into the orders table + transaction.insert( + Insert.newBuilder() .namespace("order") .table("orders") .partitionKey(Key.ofInt("customer_id", customerId)) @@ -161,9 +162,9 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts) int itemId = itemIds[i]; int count = itemCounts[i]; - // Put the order statement into the statements table - transaction.put( - Put.newBuilder() + // Insert the order statement into the statements table + transaction.insert( + Insert.newBuilder() .namespace("order") .table("statements") .partitionKey(Key.ofText("order_id", orderId)) @@ -206,8 +207,8 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts) } // Update credit_total for the customer - transaction.put( - Put.newBuilder() + transaction.update( + Update.newBuilder() .namespace("customer") .table("customers") .partitionKey(Key.ofInt("customer_id", customerId)) @@ -389,8 +390,8 @@ public void repayment(int customerId, int amount) throws TransactionException { } // Reduce credit_total for the customer - transaction.put( - Put.newBuilder() + transaction.update( + Update.newBuilder() .namespace("customer") .table("customers") .partitionKey(Key.ofInt("customer_id", customerId)) diff --git a/scalardb-sample/src/main/java/sample/Sample.java b/scalardb-sample/src/main/java/sample/Sample.java index f0763433..5c40457e 100644 --- a/scalardb-sample/src/main/java/sample/Sample.java +++ b/scalardb-sample/src/main/java/sample/Sample.java @@ -3,9 +3,10 @@ import com.scalar.db.api.DistributedTransaction; import com.scalar.db.api.DistributedTransactionManager; import com.scalar.db.api.Get; -import com.scalar.db.api.Put; +import com.scalar.db.api.Insert; import com.scalar.db.api.Result; import com.scalar.db.api.Scan; +import com.scalar.db.api.Update; import com.scalar.db.exception.transaction.TransactionException; import com.scalar.db.io.Key; import com.scalar.db.service.TransactionFactory; @@ -62,8 +63,8 @@ private void loadCustomerIfNotExists( .partitionKey(Key.ofInt("customer_id", customerId)) .build()); if (!customer.isPresent()) { - transaction.put( - Put.newBuilder() + transaction.insert( + Insert.newBuilder() .namespace("sample") .table("customers") .partitionKey(Key.ofInt("customer_id", customerId)) @@ -85,8 +86,8 @@ private void loadItemIfNotExists( .partitionKey(Key.ofInt("item_id", itemId)) .build()); if (!item.isPresent()) { - transaction.put( - Put.newBuilder() + transaction.insert( + Insert.newBuilder() .namespace("sample") .table("items") .partitionKey(Key.ofInt("item_id", itemId)) @@ -146,9 +147,9 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts) // Start a transaction transaction = manager.start(); - // Put the order info into the orders table - transaction.put( - Put.newBuilder() + // Insert the order info into the orders table + transaction.insert( + Insert.newBuilder() .namespace("sample") .table("orders") .partitionKey(Key.ofInt("customer_id", customerId)) @@ -161,9 +162,9 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts) int itemId = itemIds[i]; int count = itemCounts[i]; - // Put the order statement into the statements table - transaction.put( - Put.newBuilder() + // Insert the order statement into the statements table + transaction.insert( + Insert.newBuilder() .namespace("sample") .table("statements") .partitionKey(Key.ofText("order_id", orderId)) @@ -205,8 +206,8 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts) } // Update credit_total for the customer - transaction.put( - Put.newBuilder() + transaction.update( + Update.newBuilder() .namespace("sample") .table("customers") .partitionKey(Key.ofInt("customer_id", customerId)) @@ -388,8 +389,8 @@ public void repayment(int customerId, int amount) throws TransactionException { } // Reduce credit_total for the customer - transaction.put( - Put.newBuilder() + transaction.update( + Update.newBuilder() .namespace("sample") .table("customers") .partitionKey(Key.ofInt("customer_id", customerId)) From 17c6dfa688105786187c792728463418e035dd29 Mon Sep 17 00:00:00 2001 From: Kodai Doki Date: Mon, 11 Nov 2024 13:25:53 +0900 Subject: [PATCH 3/5] Replace deprecated put with update and upsert in the Kotilin sample --- .../src/main/kotlin/sample/ElectronicMoney.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scalardb-kotlin-sample/src/main/kotlin/sample/ElectronicMoney.kt b/scalardb-kotlin-sample/src/main/kotlin/sample/ElectronicMoney.kt index 15cefaa5..43a7de13 100644 --- a/scalardb-kotlin-sample/src/main/kotlin/sample/ElectronicMoney.kt +++ b/scalardb-kotlin-sample/src/main/kotlin/sample/ElectronicMoney.kt @@ -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 @@ -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() @@ -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() From 789b3c21aa09be5452f88338e8d655bb8ad27a54 Mon Sep 17 00:00:00 2001 From: Kodai Doki Date: Tue, 12 Nov 2024 13:09:52 +0900 Subject: [PATCH 4/5] Change function names from put to insert --- .../src/main/java/sample/customer/CustomerService.java | 2 +- .../src/main/java/sample/customer/model/Customer.java | 2 +- .../src/main/java/sample/order/OrderService.java | 10 +++++----- .../src/main/java/sample/order/model/Item.java | 2 +- .../src/main/java/sample/order/model/Order.java | 2 +- .../src/main/java/sample/order/model/Statement.java | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/microservice-transaction-sample/customer-service/src/main/java/sample/customer/CustomerService.java b/microservice-transaction-sample/customer-service/src/main/java/sample/customer/CustomerService.java index c3bb5a89..c797e3d3 100644 --- a/microservice-transaction-sample/customer-service/src/main/java/sample/customer/CustomerService.java +++ b/microservice-transaction-sample/customer-service/src/main/java/sample/customer/CustomerService.java @@ -74,7 +74,7 @@ private void loadCustomerIfNotExists( throws CrudException { Optional customer = Customer.get(transaction, id); if (!customer.isPresent()) { - Customer.put(transaction, id, name, creditLimit, creditTotal); + Customer.insert(transaction, id, name, creditLimit, creditTotal); } } diff --git a/microservice-transaction-sample/customer-service/src/main/java/sample/customer/model/Customer.java b/microservice-transaction-sample/customer-service/src/main/java/sample/customer/model/Customer.java index e3163639..ea39dd8f 100644 --- a/microservice-transaction-sample/customer-service/src/main/java/sample/customer/model/Customer.java +++ b/microservice-transaction-sample/customer-service/src/main/java/sample/customer/model/Customer.java @@ -28,7 +28,7 @@ public Customer(int id, String name, int creditLimit, int creditTotal) { this.creditTotal = creditTotal; } - public static void put( + public static void insert( TransactionCrudOperable transaction, int id, String name, int creditLimit, int creditTotal) throws CrudException { transaction.insert( diff --git a/microservice-transaction-sample/order-service/src/main/java/sample/order/OrderService.java b/microservice-transaction-sample/order-service/src/main/java/sample/order/OrderService.java index 60fcd5e8..7b206d8d 100644 --- a/microservice-transaction-sample/order-service/src/main/java/sample/order/OrderService.java +++ b/microservice-transaction-sample/order-service/src/main/java/sample/order/OrderService.java @@ -94,7 +94,7 @@ private void loadItemIfNotExists( DistributedTransaction transaction, int id, String name, int price) throws CrudException { Optional item = Item.get(transaction, id); if (!item.isPresent()) { - Item.put(transaction, id, name, price); + Item.insert(transaction, id, name, price); } } @@ -106,13 +106,13 @@ public void placeOrder( transaction -> { String orderId = UUID.randomUUID().toString(); - // Put the order info into the orders table - Order.put(transaction, orderId, request.getCustomerId(), System.currentTimeMillis()); + // Insert the order info into the orders table + Order.insert(transaction, orderId, request.getCustomerId(), System.currentTimeMillis()); int amount = 0; for (ItemOrder itemOrder : request.getItemOrderList()) { - // Put the order statement into the statements table - Statement.put(transaction, orderId, itemOrder.getItemId(), itemOrder.getCount()); + // Insert the order statement into the statements table + Statement.insert(transaction, orderId, itemOrder.getItemId(), itemOrder.getCount()); // Retrieve the item info from the items table Optional item = Item.get(transaction, itemOrder.getItemId()); diff --git a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Item.java b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Item.java index 86cd647b..390c8452 100644 --- a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Item.java +++ b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Item.java @@ -25,7 +25,7 @@ public Item(int id, String name, int price) { this.price = price; } - public static void put(TransactionCrudOperable transaction, int id, String name, int price) + public static void insert(TransactionCrudOperable transaction, int id, String name, int price) throws CrudException { transaction.insert( Insert.newBuilder() diff --git a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Order.java b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Order.java index 23fb6a51..1f8318c4 100644 --- a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Order.java +++ b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Order.java @@ -30,7 +30,7 @@ public Order(String id, int customerId, long timestamp) { this.timestamp = timestamp; } - public static void put( + public static void insert( TransactionCrudOperable transaction, String id, int customerId, long timestamp) throws CrudException { transaction.insert( diff --git a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Statement.java b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Statement.java index dc2efa20..9dbe846f 100644 --- a/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Statement.java +++ b/microservice-transaction-sample/order-service/src/main/java/sample/order/model/Statement.java @@ -26,7 +26,7 @@ public Statement(String orderId, int itemId, int count) { this.count = count; } - public static void put(TransactionCrudOperable transaction, String orderId, int itemId, int count) + public static void insert(TransactionCrudOperable transaction, String orderId, int itemId, int count) throws CrudException { transaction.insert( Insert.newBuilder() From 8427a0ddbca87e9ba513e07c4bfe34436066e624 Mon Sep 17 00:00:00 2001 From: Kodai Doki Date: Wed, 13 Nov 2024 13:32:16 +0900 Subject: [PATCH 5/5] Renamed the delete task --- microservice-transaction-sample/rpc/build.gradle | 8 ++++---- .../rpc/build.gradle | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/microservice-transaction-sample/rpc/build.gradle b/microservice-transaction-sample/rpc/build.gradle index 02dd34f1..9b77d636 100644 --- a/microservice-transaction-sample/rpc/build.gradle +++ b/microservice-transaction-sample/rpc/build.gradle @@ -35,8 +35,8 @@ task copyGeneratedProtoToSrc(type: Copy) { duplicatesStrategy = DuplicatesStrategy.INCLUDE } -// Task deleteBuildMainJava deletes the generated .java files in build directory -task deleteBuildMainJava(type: Delete) { +// Task deleteGeneratedProto deletes the generated .java files in build directory +task deleteGeneratedProto(type: Delete) { dependsOn copyGeneratedProtoToSrc delete fileTree(dir: "$buildDir/generated/source/proto/main/java/sample/rpc") } @@ -47,9 +47,9 @@ processResources { dependsOn generateProto } -// Task deleteBuildMainJava needs to depend on deleteBuildMainJava to avoid duplicate class error +// Task deleteGeneratedProto needs to depend on deleteGeneratedProto to avoid duplicate class error tasks.named("compileJava").configure { - dependsOn deleteBuildMainJava + dependsOn deleteGeneratedProto } java { diff --git a/spring-data-microservice-transaction-sample/rpc/build.gradle b/spring-data-microservice-transaction-sample/rpc/build.gradle index 4c6a6862..d8a59ccc 100644 --- a/spring-data-microservice-transaction-sample/rpc/build.gradle +++ b/spring-data-microservice-transaction-sample/rpc/build.gradle @@ -35,8 +35,8 @@ task copyGeneratedProtoToSrc(type: Copy) { duplicatesStrategy = DuplicatesStrategy.INCLUDE } -// Task deleteBuildMainJava deletes the generated .java files in build directory -task deleteBuildMainJava(type: Delete) { +// Task deleteGeneratedProto deletes the generated .java files in build directory +task deleteGeneratedProto(type: Delete) { dependsOn copyGeneratedProtoToSrc delete fileTree(dir: "$buildDir/generated/source/proto/main/java/sample/rpc") } @@ -47,9 +47,9 @@ processResources { dependsOn generateProto } -// Task deleteBuildMainJava needs to depend on deleteBuildMainJava to avoid duplicate class error +// Task deleteGeneratedProto needs to depend on deleteGeneratedProto to avoid duplicate class error tasks.named("compileJava").configure { - dependsOn deleteBuildMainJava + dependsOn deleteGeneratedProto } java {