Skip to content

Commit bdedc82

Browse files
authored
Replace deprecated Gradle/ScalarDB features (#74)
* Replace deprecated Gradle features * Replace deprecated put with update and insert * Replace deprecated put with update and upsert in the Kotilin sample * Change function names from put to insert * Renamed the delete task
1 parent 2f63061 commit bdedc82

File tree

23 files changed

+225
-123
lines changed

23 files changed

+225
-123
lines changed

microservice-transaction-sample/client/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ dependencies {
1010
}
1111

1212
application {
13-
mainClassName = 'sample.client.Client'
13+
mainClass = 'sample.client.Client'
1414
}
1515

16-
archivesBaseName = "sample-order-service"
16+
base {
17+
archivesName = "sample-order-service"
18+
}
1719

18-
sourceCompatibility = 1.8
19-
targetCompatibility = 1.8
20+
java {
21+
toolchain {
22+
languageVersion = JavaLanguageVersion.of(8)
23+
}
24+
}

microservice-transaction-sample/customer-service/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414
}
1515

1616
application {
17-
mainClassName = 'sample.customer.CustomerServiceServer'
17+
mainClass = 'sample.customer.CustomerServiceServer'
1818
}
1919

2020
task copyFilesToDockerBuildContextDir(type: Copy) {
@@ -47,7 +47,12 @@ installDist {
4747
duplicatesStrategy DuplicatesStrategy.EXCLUDE
4848
}
4949

50-
archivesBaseName = "sample-customer-service"
50+
base {
51+
archivesName = "sample-customer-service"
52+
}
5153

52-
sourceCompatibility = 1.8
53-
targetCompatibility = 1.8
54+
java {
55+
toolchain {
56+
languageVersion = JavaLanguageVersion.of(8)
57+
}
58+
}

microservice-transaction-sample/customer-service/src/main/java/sample/customer/CustomerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private void loadCustomerIfNotExists(
7474
throws CrudException {
7575
Optional<Customer> customer = Customer.get(transaction, id);
7676
if (!customer.isPresent()) {
77-
Customer.put(transaction, id, name, creditLimit, creditTotal);
77+
Customer.insert(transaction, id, name, creditLimit, creditTotal);
7878
}
7979
}
8080

microservice-transaction-sample/customer-service/src/main/java/sample/customer/model/Customer.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package sample.customer.model;
22

33
import com.scalar.db.api.Get;
4-
import com.scalar.db.api.Put;
4+
import com.scalar.db.api.Insert;
55
import com.scalar.db.api.TransactionCrudOperable;
6+
import com.scalar.db.api.Update;
67
import com.scalar.db.exception.transaction.CrudException;
78
import com.scalar.db.io.Key;
89
import java.util.Optional;
@@ -27,11 +28,11 @@ public Customer(int id, String name, int creditLimit, int creditTotal) {
2728
this.creditTotal = creditTotal;
2829
}
2930

30-
public static void put(
31+
public static void insert(
3132
TransactionCrudOperable transaction, int id, String name, int creditLimit, int creditTotal)
3233
throws CrudException {
33-
transaction.put(
34-
Put.newBuilder()
34+
transaction.insert(
35+
Insert.newBuilder()
3536
.namespace(NAMESPACE)
3637
.table(TABLE)
3738
.partitionKey(Key.ofInt(COL_CUSTOMER_ID, id))
@@ -43,8 +44,8 @@ public static void put(
4344

4445
public static void updateCreditTotal(TransactionCrudOperable transaction, int id, int creditTotal)
4546
throws CrudException {
46-
transaction.put(
47-
Put.newBuilder()
47+
transaction.update(
48+
Update.newBuilder()
4849
.namespace(NAMESPACE)
4950
.table(TABLE)
5051
.partitionKey(Key.ofInt(COL_CUSTOMER_ID, id))

microservice-transaction-sample/order-service/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414
}
1515

1616
application {
17-
mainClassName = 'sample.order.OrderServiceServer'
17+
mainClass = 'sample.order.OrderServiceServer'
1818
}
1919

2020
task copyFilesToDockerBuildContextDir(type: Copy) {
@@ -47,7 +47,12 @@ installDist {
4747
duplicatesStrategy DuplicatesStrategy.EXCLUDE
4848
}
4949

50-
archivesBaseName = "sample-order-service"
50+
base {
51+
archivesName = "sample-order-service"
52+
}
5153

52-
sourceCompatibility = 1.8
53-
targetCompatibility = 1.8
54+
java {
55+
toolchain {
56+
languageVersion = JavaLanguageVersion.of(8)
57+
}
58+
}

microservice-transaction-sample/order-service/src/main/java/sample/order/OrderService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void loadItemIfNotExists(
9494
DistributedTransaction transaction, int id, String name, int price) throws CrudException {
9595
Optional<Item> item = Item.get(transaction, id);
9696
if (!item.isPresent()) {
97-
Item.put(transaction, id, name, price);
97+
Item.insert(transaction, id, name, price);
9898
}
9999
}
100100

@@ -106,13 +106,13 @@ public void placeOrder(
106106
transaction -> {
107107
String orderId = UUID.randomUUID().toString();
108108

109-
// Put the order info into the orders table
110-
Order.put(transaction, orderId, request.getCustomerId(), System.currentTimeMillis());
109+
// Insert the order info into the orders table
110+
Order.insert(transaction, orderId, request.getCustomerId(), System.currentTimeMillis());
111111

112112
int amount = 0;
113113
for (ItemOrder itemOrder : request.getItemOrderList()) {
114-
// Put the order statement into the statements table
115-
Statement.put(transaction, orderId, itemOrder.getItemId(), itemOrder.getCount());
114+
// Insert the order statement into the statements table
115+
Statement.insert(transaction, orderId, itemOrder.getItemId(), itemOrder.getCount());
116116

117117
// Retrieve the item info from the items table
118118
Optional<Item> item = Item.get(transaction, itemOrder.getItemId());

microservice-transaction-sample/order-service/src/main/java/sample/order/model/Item.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package sample.order.model;
22

33
import com.scalar.db.api.Get;
4-
import com.scalar.db.api.Put;
4+
import com.scalar.db.api.Insert;
55
import com.scalar.db.api.TransactionCrudOperable;
66
import com.scalar.db.exception.transaction.CrudException;
77
import com.scalar.db.io.Key;
@@ -25,10 +25,10 @@ public Item(int id, String name, int price) {
2525
this.price = price;
2626
}
2727

28-
public static void put(TransactionCrudOperable transaction, int id, String name, int price)
28+
public static void insert(TransactionCrudOperable transaction, int id, String name, int price)
2929
throws CrudException {
30-
transaction.put(
31-
Put.newBuilder()
30+
transaction.insert(
31+
Insert.newBuilder()
3232
.namespace(NAMESPACE)
3333
.table(TABLE)
3434
.partitionKey(Key.ofInt(COL_ITEM_ID, id))

microservice-transaction-sample/order-service/src/main/java/sample/order/model/Order.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package sample.order.model;
22

33
import com.scalar.db.api.Get;
4-
import com.scalar.db.api.Put;
4+
import com.scalar.db.api.Insert;
55
import com.scalar.db.api.Result;
66
import com.scalar.db.api.Scan;
77
import com.scalar.db.api.Scan.Ordering;
@@ -30,11 +30,11 @@ public Order(String id, int customerId, long timestamp) {
3030
this.timestamp = timestamp;
3131
}
3232

33-
public static void put(
33+
public static void insert(
3434
TransactionCrudOperable transaction, String id, int customerId, long timestamp)
3535
throws CrudException {
36-
transaction.put(
37-
Put.newBuilder()
36+
transaction.insert(
37+
Insert.newBuilder()
3838
.namespace(NAMESPACE)
3939
.table(TABLE)
4040
.partitionKey(Key.ofInt(COL_CUSTOMER_ID, customerId))

microservice-transaction-sample/order-service/src/main/java/sample/order/model/Statement.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package sample.order.model;
22

3-
import com.scalar.db.api.Put;
3+
import com.scalar.db.api.Insert;
44
import com.scalar.db.api.Scan;
55
import com.scalar.db.api.TransactionCrudOperable;
66
import com.scalar.db.exception.transaction.CrudException;
@@ -26,10 +26,10 @@ public Statement(String orderId, int itemId, int count) {
2626
this.count = count;
2727
}
2828

29-
public static void put(TransactionCrudOperable transaction, String orderId, int itemId, int count)
29+
public static void insert(TransactionCrudOperable transaction, String orderId, int itemId, int count)
3030
throws CrudException {
31-
transaction.put(
32-
Put.newBuilder()
31+
transaction.insert(
32+
Insert.newBuilder()
3333
.namespace(NAMESPACE)
3434
.table(TABLE)
3535
.partitionKey(Key.ofText(COL_ORDER_ID, orderId))

microservice-transaction-sample/rpc/build.gradle

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java'
33
id 'java-library-distribution'
4-
id 'com.google.protobuf' version '0.9.1'
4+
id 'com.google.protobuf' version '0.9.4'
55
}
66

77
dependencies {
@@ -20,16 +20,40 @@ protobuf {
2020
generateProtoTasks {
2121
all()*.plugins { grpc {} }
2222
}
23-
generatedFilesBaseDir = "$projectDir/src"
2423
}
2524

26-
archivesBaseName = "sample-rpc"
25+
base {
26+
archivesName = "sample-rpc"
27+
}
28+
29+
// Task copyGeneratedProtoToSrc copies the generated .java files into src directory
30+
task copyGeneratedProtoToSrc(type: Copy) {
31+
description 'Copies generated Protocol Buffer classes to src/main/java/sample/rpc'
32+
dependsOn generateProto
33+
from "$buildDir/generated/source/proto/main/java/sample/rpc"
34+
into "$projectDir/src/main/java/sample/rpc"
35+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
36+
}
37+
38+
// Task deleteGeneratedProto deletes the generated .java files in build directory
39+
task deleteGeneratedProto(type: Delete) {
40+
dependsOn copyGeneratedProtoToSrc
41+
delete fileTree(dir: "$buildDir/generated/source/proto/main/java/sample/rpc")
42+
}
2743

2844
// The processResources task needs to depend on the generateProto task because it uses the output
2945
// of the the generateProto task
3046
processResources {
3147
dependsOn generateProto
3248
}
3349

34-
sourceCompatibility = 1.8
35-
targetCompatibility = 1.8
50+
// Task deleteGeneratedProto needs to depend on deleteGeneratedProto to avoid duplicate class error
51+
tasks.named("compileJava").configure {
52+
dependsOn deleteGeneratedProto
53+
}
54+
55+
java {
56+
toolchain {
57+
languageVersion = JavaLanguageVersion.of(8)
58+
}
59+
}

0 commit comments

Comments
 (0)