Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated Gradle/ScalarDB features #74

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions microservice-transaction-sample/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ dependencies {
}

application {
mainClassName = 'sample.client.Client'
mainClass = 'sample.client.Client'
}
Comment on lines 12 to 14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix suppress the following warning message:

The org.gradle.api.plugins.ApplicationPluginConvention type has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/8.5/userguide/upgrading_version_8.html#application_convention_deprecation


archivesBaseName = "sample-order-service"
base {
archivesName = "sample-order-service"
}
Comment on lines -16 to +18
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix suppress the following warning message:

The org.gradle.api.plugins.BasePluginConvention type has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/8.5/userguide/upgrading_version_8.html#base_convention_deprecation


sourceCompatibility = 1.8
targetCompatibility = 1.8
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
Comment on lines -18 to +24
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix suppress the following warning message:

The org.gradle.api.plugins.JavaPluginConvention type has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/8.5/userguide/upgrading_version_8.html#java_convention_deprecation

13 changes: 9 additions & 4 deletions microservice-transaction-sample/customer-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
}

application {
mainClassName = 'sample.customer.CustomerServiceServer'
mainClass = 'sample.customer.CustomerServiceServer'
}

task copyFilesToDockerBuildContextDir(type: Copy) {
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,8 +31,8 @@ public Customer(int id, String name, int creditLimit, int creditTotal) {
public static void put(
KodaiD marked this conversation as resolved.
Show resolved Hide resolved
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))
Expand All @@ -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))
Expand Down
13 changes: 9 additions & 4 deletions microservice-transaction-sample/order-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
}

application {
mainClassName = 'sample.order.OrderServiceServer'
mainClass = 'sample.order.OrderServiceServer'
}

task copyFilesToDockerBuildContextDir(type: Copy) {
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,8 +27,8 @@ public Item(int id, String name, int price) {

public static void put(TransactionCrudOperable transaction, int id, String name, int price)
KodaiD marked this conversation as resolved.
Show resolved Hide resolved
throws CrudException {
transaction.put(
Put.newBuilder()
transaction.insert(
Insert.newBuilder()
.namespace(NAMESPACE)
.table(TABLE)
.partitionKey(Key.ofInt(COL_ITEM_ID, id))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,8 +33,8 @@ public Order(String id, int customerId, long timestamp) {
public static void put(
KodaiD marked this conversation as resolved.
Show resolved Hide resolved
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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -28,8 +28,8 @@ public Statement(String orderId, int itemId, int count) {

public static void put(TransactionCrudOperable transaction, String orderId, int itemId, int count)
KodaiD marked this conversation as resolved.
Show resolved Hide resolved
throws CrudException {
transaction.put(
Put.newBuilder()
transaction.insert(
Insert.newBuilder()
.namespace(NAMESPACE)
.table(TABLE)
.partitionKey(Key.ofText(COL_ORDER_ID, orderId))
Expand Down
34 changes: 29 additions & 5 deletions microservice-transaction-sample/rpc/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To suppress the following warning message, com.google.protobuf must be upgraded.

The Provider.forUseAtConfigurationTime method has been deprecated. This is scheduled to be removed in Gradle 9.0. Simply remove the call. Consult the upgrading guide for further information: https://docs.gradle.org/8.5/userguide/upgrading_version_7.html#for_use_at_configuration_time_deprecation

}

dependencies {
Expand All @@ -20,16 +20,40 @@ protobuf {
generateProtoTasks {
all()*.plugins { grpc {} }
}
generatedFilesBaseDir = "$projectDir/src"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generatedFilesBaseDir is deprecated in com.google.protobuf v0.9.2- (ref. google/protobuf-gradle-plugin#636).

}

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
}
Comment on lines +29 to +36
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since generatedFilesBaseDir is deprecated, we need to implement a similar functionality using copy.


// 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")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before running the compileJava task, the files under src/main/java must be deleted, otherwise we will get duplicate class errors like:

xxx/scalardb-samples/microservice-transaction-sample/rpc/build/generated/source/proto/main/java/sample/rpc/CommitRequest.java:9: エラー: クラスsample.rpc.CommitRequestが重複しています
public final class CommitRequest extends

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task seems to delete only the generated protobuf files in the build directory, but the current task name might look to delete more. How about adding GeneratedProtobuf or something to the task name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@komamitsu Thanks for reviewing! I applied your suggestion in 8427a0d. PTAL!


// The processResources task needs to depend on the generateProto task because it uses the output
// of the the generateProto task
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)
}
}
13 changes: 9 additions & 4 deletions multi-storage-transaction-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
31 changes: 16 additions & 15 deletions multi-storage-transaction-sample/src/main/java/sample/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 3 additions & 8 deletions scalardb-kotlin-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -21,13 +21,8 @@ tasks.test {
useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Comment on lines -28 to -30
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is kotlin { jvmToolchain(8) }, this setting seems to be unnecessary.

kotlin {
jvmToolchain(8)
}

application {
Expand Down
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
Loading