Skip to content

Commit d686570

Browse files
committed
Replace deprecated put with update and insert
1 parent bb44f06 commit d686570

File tree

6 files changed

+47
-44
lines changed

6 files changed

+47
-44
lines changed

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

Lines changed: 6 additions & 5 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;
@@ -30,8 +31,8 @@ public Customer(int id, String name, int creditLimit, int creditTotal) {
3031
public static void put(
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/src/main/java/sample/order/model/Item.java

Lines changed: 3 additions & 3 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;
@@ -27,8 +27,8 @@ public Item(int id, String name, int price) {
2727

2828
public static void put(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: 3 additions & 3 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;
@@ -33,8 +33,8 @@ public Order(String id, int customerId, long timestamp) {
3333
public static void put(
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: 3 additions & 3 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;
@@ -28,8 +28,8 @@ public Statement(String orderId, int itemId, int count) {
2828

2929
public static void put(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))

multi-storage-transaction-sample/src/main/java/sample/Sample.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import com.scalar.db.api.DistributedTransaction;
44
import com.scalar.db.api.DistributedTransactionManager;
55
import com.scalar.db.api.Get;
6-
import com.scalar.db.api.Put;
6+
import com.scalar.db.api.Insert;
77
import com.scalar.db.api.Result;
88
import com.scalar.db.api.Scan;
9+
import com.scalar.db.api.Update;
910
import com.scalar.db.exception.transaction.TransactionException;
1011
import com.scalar.db.io.Key;
1112
import com.scalar.db.service.TransactionFactory;
@@ -62,8 +63,8 @@ private void loadCustomerIfNotExists(
6263
.partitionKey(Key.ofInt("customer_id", customerId))
6364
.build());
6465
if (!customer.isPresent()) {
65-
transaction.put(
66-
Put.newBuilder()
66+
transaction.insert(
67+
Insert.newBuilder()
6768
.namespace("customer")
6869
.table("customers")
6970
.partitionKey(Key.ofInt("customer_id", customerId))
@@ -85,8 +86,8 @@ private void loadItemIfNotExists(
8586
.partitionKey(Key.ofInt("item_id", itemId))
8687
.build());
8788
if (!item.isPresent()) {
88-
transaction.put(
89-
Put.newBuilder()
89+
transaction.insert(
90+
Insert.newBuilder()
9091
.namespace("order")
9192
.table("items")
9293
.partitionKey(Key.ofInt("item_id", itemId))
@@ -146,9 +147,9 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts)
146147
// Start a transaction
147148
transaction = manager.start();
148149

149-
// Put the order info into the orders table
150-
transaction.put(
151-
Put.newBuilder()
150+
// Insert the order info into the orders table
151+
transaction.insert(
152+
Insert.newBuilder()
152153
.namespace("order")
153154
.table("orders")
154155
.partitionKey(Key.ofInt("customer_id", customerId))
@@ -161,9 +162,9 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts)
161162
int itemId = itemIds[i];
162163
int count = itemCounts[i];
163164

164-
// Put the order statement into the statements table
165-
transaction.put(
166-
Put.newBuilder()
165+
// Insert the order statement into the statements table
166+
transaction.insert(
167+
Insert.newBuilder()
167168
.namespace("order")
168169
.table("statements")
169170
.partitionKey(Key.ofText("order_id", orderId))
@@ -206,8 +207,8 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts)
206207
}
207208

208209
// Update credit_total for the customer
209-
transaction.put(
210-
Put.newBuilder()
210+
transaction.update(
211+
Update.newBuilder()
211212
.namespace("customer")
212213
.table("customers")
213214
.partitionKey(Key.ofInt("customer_id", customerId))
@@ -389,8 +390,8 @@ public void repayment(int customerId, int amount) throws TransactionException {
389390
}
390391

391392
// Reduce credit_total for the customer
392-
transaction.put(
393-
Put.newBuilder()
393+
transaction.update(
394+
Update.newBuilder()
394395
.namespace("customer")
395396
.table("customers")
396397
.partitionKey(Key.ofInt("customer_id", customerId))

scalardb-sample/src/main/java/sample/Sample.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import com.scalar.db.api.DistributedTransaction;
44
import com.scalar.db.api.DistributedTransactionManager;
55
import com.scalar.db.api.Get;
6-
import com.scalar.db.api.Put;
6+
import com.scalar.db.api.Insert;
77
import com.scalar.db.api.Result;
88
import com.scalar.db.api.Scan;
9+
import com.scalar.db.api.Update;
910
import com.scalar.db.exception.transaction.TransactionException;
1011
import com.scalar.db.io.Key;
1112
import com.scalar.db.service.TransactionFactory;
@@ -62,8 +63,8 @@ private void loadCustomerIfNotExists(
6263
.partitionKey(Key.ofInt("customer_id", customerId))
6364
.build());
6465
if (!customer.isPresent()) {
65-
transaction.put(
66-
Put.newBuilder()
66+
transaction.insert(
67+
Insert.newBuilder()
6768
.namespace("sample")
6869
.table("customers")
6970
.partitionKey(Key.ofInt("customer_id", customerId))
@@ -85,8 +86,8 @@ private void loadItemIfNotExists(
8586
.partitionKey(Key.ofInt("item_id", itemId))
8687
.build());
8788
if (!item.isPresent()) {
88-
transaction.put(
89-
Put.newBuilder()
89+
transaction.insert(
90+
Insert.newBuilder()
9091
.namespace("sample")
9192
.table("items")
9293
.partitionKey(Key.ofInt("item_id", itemId))
@@ -146,9 +147,9 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts)
146147
// Start a transaction
147148
transaction = manager.start();
148149

149-
// Put the order info into the orders table
150-
transaction.put(
151-
Put.newBuilder()
150+
// Insert the order info into the orders table
151+
transaction.insert(
152+
Insert.newBuilder()
152153
.namespace("sample")
153154
.table("orders")
154155
.partitionKey(Key.ofInt("customer_id", customerId))
@@ -161,9 +162,9 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts)
161162
int itemId = itemIds[i];
162163
int count = itemCounts[i];
163164

164-
// Put the order statement into the statements table
165-
transaction.put(
166-
Put.newBuilder()
165+
// Insert the order statement into the statements table
166+
transaction.insert(
167+
Insert.newBuilder()
167168
.namespace("sample")
168169
.table("statements")
169170
.partitionKey(Key.ofText("order_id", orderId))
@@ -205,8 +206,8 @@ public String placeOrder(int customerId, int[] itemIds, int[] itemCounts)
205206
}
206207

207208
// Update credit_total for the customer
208-
transaction.put(
209-
Put.newBuilder()
209+
transaction.update(
210+
Update.newBuilder()
210211
.namespace("sample")
211212
.table("customers")
212213
.partitionKey(Key.ofInt("customer_id", customerId))
@@ -388,8 +389,8 @@ public void repayment(int customerId, int amount) throws TransactionException {
388389
}
389390

390391
// Reduce credit_total for the customer
391-
transaction.put(
392-
Put.newBuilder()
392+
transaction.update(
393+
Update.newBuilder()
393394
.namespace("sample")
394395
.table("customers")
395396
.partitionKey(Key.ofInt("customer_id", customerId))

0 commit comments

Comments
 (0)