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 all 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
Expand Up @@ -74,7 +74,7 @@ private void loadCustomerIfNotExists(
throws CrudException {
Optional<Customer> customer = Customer.get(transaction, id);
if (!customer.isPresent()) {
Customer.put(transaction, id, name, creditLimit, creditTotal);
Customer.insert(transaction, id, name, creditLimit, creditTotal);
}
}

Expand Down
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 All @@ -27,11 +28,11 @@ 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.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
Expand Up @@ -94,7 +94,7 @@ private void loadItemIfNotExists(
DistributedTransaction transaction, int id, String name, int price) throws CrudException {
Optional<Item> item = Item.get(transaction, id);
if (!item.isPresent()) {
Item.put(transaction, id, name, price);
Item.insert(transaction, id, name, price);
}
}

Expand All @@ -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 = Item.get(transaction, itemOrder.getItemId());
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.TransactionCrudOperable;
import com.scalar.db.exception.transaction.CrudException;
import com.scalar.db.io.Key;
Expand All @@ -25,10 +25,10 @@ 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.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 @@ -30,11 +30,11 @@ 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.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 All @@ -26,10 +26,10 @@ 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.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 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")
}

// 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 deleteGeneratedProto needs to depend on deleteGeneratedProto to avoid duplicate class error
tasks.named("compileJava").configure {
dependsOn deleteGeneratedProto
}

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
Loading