Skip to content

Commit 5242141

Browse files
brfrn169gemini-code-assist[bot]Copilot
committed
Remove deprecated API usages (Part 1) (#2947)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>
1 parent bf0123e commit 5242141

File tree

61 files changed

+1313
-1459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1313
-1459
lines changed

core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageIntegrationTest.java

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ public void whenPutDataIntoTable1_DataShouldBeWrittenIntoCassandra() throws Exec
172172
// Arrange
173173
String namespace = NAMESPACE1;
174174
String table = TABLE1;
175-
Key partitionKey = new Key(COL_NAME1, 1);
176-
Key clusteringKey = new Key(COL_NAME4, 4);
175+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
176+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
177177
Put put =
178178
new Put(partitionKey, clusteringKey)
179179
.withValue(COL_NAME2, "val2")
@@ -214,8 +214,8 @@ public void whenPutDataIntoTable2_DataShouldBeWrittenIntoJdbcDatabase()
214214
// Arrange
215215
String namespace = NAMESPACE1;
216216
String table = TABLE2;
217-
Key partitionKey = new Key(COL_NAME1, 1);
218-
Key clusteringKey = new Key(COL_NAME4, 4);
217+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
218+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
219219
Put put =
220220
new Put(partitionKey, clusteringKey)
221221
.withValue(COL_NAME2, "val2")
@@ -256,8 +256,8 @@ public void whenPutDataIntoTable3_DataShouldBeWrittenIntoDefaultStorage()
256256
// Arrange
257257
String namespace = NAMESPACE1;
258258
String table = TABLE3;
259-
Key partitionKey = new Key(COL_NAME1, 1);
260-
Key clusteringKey = new Key(COL_NAME4, 4);
259+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
260+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
261261

262262
Put put =
263263
new Put(partitionKey, clusteringKey)
@@ -299,10 +299,10 @@ public void whenScanDataFromTable1_DataShouldBeScannedFromCassandra()
299299
// Arrange
300300
String namespace = NAMESPACE1;
301301
String table = TABLE1;
302-
Key partitionKey = new Key(COL_NAME1, 1);
303-
Key clusteringKey1 = new Key(COL_NAME4, 0);
304-
Key clusteringKey2 = new Key(COL_NAME4, 1);
305-
Key clusteringKey3 = new Key(COL_NAME4, 2);
302+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
303+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 0);
304+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 1);
305+
Key clusteringKey3 = Key.ofInt(COL_NAME4, 2);
306306

307307
cassandra.mutate(
308308
Arrays.asList(
@@ -341,10 +341,10 @@ public void whenScanDataFromTable2_DataShouldBeScannedFromJdbcDatabase()
341341
// Arrange
342342
String namespace = NAMESPACE1;
343343
String table = TABLE2;
344-
Key partitionKey = new Key(COL_NAME1, 1);
345-
Key clusteringKey1 = new Key(COL_NAME4, 0);
346-
Key clusteringKey2 = new Key(COL_NAME4, 1);
347-
Key clusteringKey3 = new Key(COL_NAME4, 2);
344+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
345+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 0);
346+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 1);
347+
Key clusteringKey3 = Key.ofInt(COL_NAME4, 2);
348348

349349
jdbcDatabase.mutate(
350350
Arrays.asList(
@@ -383,10 +383,10 @@ public void whenScanDataFromTable3_DataShouldBeScannedFromDefaultStorage()
383383
// Arrange
384384
String namespace = NAMESPACE1;
385385
String table = TABLE3;
386-
Key partitionKey = new Key(COL_NAME1, 1);
387-
Key clusteringKey1 = new Key(COL_NAME4, 0);
388-
Key clusteringKey2 = new Key(COL_NAME4, 1);
389-
Key clusteringKey3 = new Key(COL_NAME4, 2);
386+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
387+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 0);
388+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 1);
389+
Key clusteringKey3 = Key.ofInt(COL_NAME4, 2);
390390

391391
cassandra.mutate(
392392
Arrays.asList(
@@ -431,8 +431,8 @@ public void whenDeleteDataFromTable1_DataShouldBeDeletedFromCassandra()
431431
// Arrange
432432
String namespace = NAMESPACE1;
433433
String table = TABLE1;
434-
Key partitionKey = new Key(COL_NAME1, 1);
435-
Key clusteringKey = new Key(COL_NAME4, 4);
434+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
435+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
436436
Put put =
437437
new Put(partitionKey, clusteringKey)
438438
.withValue(COL_NAME3, 3)
@@ -468,8 +468,8 @@ public void whenDeleteDataFromTable2_DataShouldBeDeletedFromJdbcDatabase()
468468
// Arrange
469469
String namespace = NAMESPACE1;
470470
String table = TABLE2;
471-
Key partitionKey = new Key(COL_NAME1, 1);
472-
Key clusteringKey = new Key(COL_NAME4, 4);
471+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
472+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
473473
Put put =
474474
new Put(partitionKey, clusteringKey)
475475
.withValue(COL_NAME3, 3)
@@ -505,8 +505,8 @@ public void whenDeleteDataFromTable3_DataShouldBeDeletedFromDefaultStorage()
505505
// Arrange
506506
String namespace = NAMESPACE1;
507507
String table = TABLE3;
508-
Key partitionKey = new Key(COL_NAME1, 1);
509-
Key clusteringKey = new Key(COL_NAME4, 4);
508+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
509+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
510510
Put put =
511511
new Put(partitionKey, clusteringKey)
512512
.withValue(COL_NAME3, 3)
@@ -541,9 +541,9 @@ public void whenMutateDataToTable1_ShouldExecuteForCassandra() throws ExecutionE
541541
// Arrange
542542
String namespace = NAMESPACE1;
543543
String table = TABLE1;
544-
Key partitionKey = new Key(COL_NAME1, 1);
545-
Key clusteringKey1 = new Key(COL_NAME4, 1);
546-
Key clusteringKey2 = new Key(COL_NAME4, 2);
544+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
545+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 1);
546+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 2);
547547
Put put =
548548
new Put(partitionKey, clusteringKey1)
549549
.withValue(COL_NAME3, 3)
@@ -596,9 +596,9 @@ public void whenMutateDataToTable2_ShouldExecuteForJdbcDatabase() throws Executi
596596
// Arrange
597597
String namespace = NAMESPACE1;
598598
String table = TABLE2;
599-
Key partitionKey = new Key(COL_NAME1, 1);
600-
Key clusteringKey1 = new Key(COL_NAME4, 1);
601-
Key clusteringKey2 = new Key(COL_NAME4, 2);
599+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
600+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 1);
601+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 2);
602602
Put put =
603603
new Put(partitionKey, clusteringKey1)
604604
.withValue(COL_NAME3, 3)
@@ -651,9 +651,9 @@ public void whenMutateDataToTable3_ShouldExecuteForDefaultStorage() throws Execu
651651
// Arrange
652652
String namespace = NAMESPACE1;
653653
String table = TABLE3;
654-
Key partitionKey = new Key(COL_NAME1, 1);
655-
Key clusteringKey1 = new Key(COL_NAME4, 1);
656-
Key clusteringKey2 = new Key(COL_NAME4, 2);
654+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
655+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 1);
656+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 2);
657657
Put put =
658658
new Put(partitionKey, clusteringKey1)
659659
.withValue(COL_NAME3, 3)
@@ -707,8 +707,8 @@ public void whenPutDataIntoTable1InNamespace2_DataShouldBeWrittenIntoJdbcDatabas
707707
// Arrange
708708
String namespace = NAMESPACE2;
709709
String table = TABLE1;
710-
Key partitionKey = new Key(COL_NAME1, 1);
711-
Key clusteringKey = new Key(COL_NAME4, 4);
710+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
711+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
712712
Put put =
713713
new Put(partitionKey, clusteringKey)
714714
.withValue(COL_NAME2, "val2")
@@ -749,10 +749,10 @@ public void whenScanDataFromTable1InNamespace2_DataShouldBeScannedFromJdbcDataba
749749
// Arrange
750750
String namespace = NAMESPACE2;
751751
String table = TABLE1;
752-
Key partitionKey = new Key(COL_NAME1, 1);
753-
Key clusteringKey1 = new Key(COL_NAME4, 0);
754-
Key clusteringKey2 = new Key(COL_NAME4, 1);
755-
Key clusteringKey3 = new Key(COL_NAME4, 2);
752+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
753+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 0);
754+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 1);
755+
Key clusteringKey3 = Key.ofInt(COL_NAME4, 2);
756756

757757
jdbcDatabase.mutate(
758758
Arrays.asList(
@@ -791,8 +791,8 @@ public void whenDeleteDataFromTable1InNamespace2_DataShouldBeDeletedFromJdbcData
791791
// Arrange
792792
String namespace = NAMESPACE2;
793793
String table = TABLE1;
794-
Key partitionKey = new Key(COL_NAME1, 1);
795-
Key clusteringKey = new Key(COL_NAME4, 4);
794+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
795+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
796796
Put put =
797797
new Put(partitionKey, clusteringKey)
798798
.withValue(COL_NAME3, 3)
@@ -828,9 +828,9 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForCassandra()
828828
// Arrange
829829
String namespace = NAMESPACE2;
830830
String table = TABLE1;
831-
Key partitionKey = new Key(COL_NAME1, 1);
832-
Key clusteringKey1 = new Key(COL_NAME4, 1);
833-
Key clusteringKey2 = new Key(COL_NAME4, 2);
831+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
832+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 1);
833+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 2);
834834
Put put =
835835
new Put(partitionKey, clusteringKey1)
836836
.withValue(COL_NAME3, 3)

core/src/main/java/com/scalar/db/storage/cassandra/ConditionSetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void visit(DeleteIfExists condition) {
111111
}
112112

113113
private Clause createClauseWith(ConditionalExpression e) {
114-
String name = quoteIfNecessary(e.getName());
114+
String name = quoteIfNecessary(e.getColumn().getName());
115115
switch (e.getOperator()) {
116116
case EQ:
117117
case IS_NULL:

core/src/main/java/com/scalar/db/storage/dynamo/DynamoMutation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public Map<String, String> getConditionColumnMap() {
132132
if (mutation.getCondition().isPresent()) {
133133
int index = 0;
134134
for (ConditionalExpression expression : mutation.getCondition().get().getExpressions()) {
135-
ret.put(CONDITION_COLUMN_NAME_ALIAS + index, expression.getName());
135+
ret.put(CONDITION_COLUMN_NAME_ALIAS + index, expression.getColumn().getName());
136136
index++;
137137
}
138138
}

core/src/main/java/com/scalar/db/storage/jdbc/query/SimpleSelectQuery.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ private String orderBySqlString() {
192192
order = Scan.Ordering.Order.ASC;
193193
}
194194
}
195-
orderingList.add(new Scan.Ordering(clusteringKeyName, order));
195+
orderingList.add(
196+
order == Scan.Ordering.Order.ASC
197+
? Scan.Ordering.asc(clusteringKeyName)
198+
: Scan.Ordering.desc(clusteringKeyName));
196199
}
197200
}
198201

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package com.scalar.db.transaction.consensuscommit;
22

3-
import com.scalar.db.api.TransactionState;
4-
import com.scalar.db.io.BigIntValue;
5-
import com.scalar.db.io.IntValue;
6-
import com.scalar.db.io.TextValue;
7-
83
public final class Attribute {
94
public static final String ID = "tx_id";
105
public static final String CHILD_IDS = "tx_child_ids";
@@ -19,52 +14,4 @@ public final class Attribute {
1914
public static final String BEFORE_VERSION = BEFORE_PREFIX + VERSION;
2015
public static final String BEFORE_PREPARED_AT = BEFORE_PREFIX + PREPARED_AT;
2116
public static final String BEFORE_COMMITTED_AT = BEFORE_PREFIX + COMMITTED_AT;
22-
23-
public static TextValue toIdValue(String transactionId) {
24-
return new TextValue(Attribute.ID, transactionId);
25-
}
26-
27-
public static TextValue toChildIdsValue(String childTransactionIds) {
28-
return new TextValue(Attribute.CHILD_IDS, childTransactionIds);
29-
}
30-
31-
public static IntValue toStateValue(TransactionState state) {
32-
return new IntValue(Attribute.STATE, state.get());
33-
}
34-
35-
public static IntValue toVersionValue(int version) {
36-
return new IntValue(Attribute.VERSION, version);
37-
}
38-
39-
public static BigIntValue toPreparedAtValue(long preparedAt) {
40-
return new BigIntValue(Attribute.PREPARED_AT, preparedAt);
41-
}
42-
43-
public static BigIntValue toCommittedAtValue(long committedAt) {
44-
return new BigIntValue(Attribute.COMMITTED_AT, committedAt);
45-
}
46-
47-
public static BigIntValue toCreatedAtValue(long createdAt) {
48-
return new BigIntValue(Attribute.CREATED_AT, createdAt);
49-
}
50-
51-
public static TextValue toBeforeIdValue(String transactionId) {
52-
return new TextValue(Attribute.BEFORE_ID, transactionId);
53-
}
54-
55-
public static IntValue toBeforeStateValue(TransactionState state) {
56-
return new IntValue(Attribute.BEFORE_STATE, state.get());
57-
}
58-
59-
public static IntValue toBeforeVersionValue(int version) {
60-
return new IntValue(Attribute.BEFORE_VERSION, version);
61-
}
62-
63-
public static BigIntValue toBeforePreparedAtValue(long preparedAt) {
64-
return new BigIntValue(Attribute.BEFORE_PREPARED_AT, preparedAt);
65-
}
66-
67-
public static BigIntValue toBeforeCommittedAtValue(long committedAt) {
68-
return new BigIntValue(Attribute.BEFORE_COMMITTED_AT, committedAt);
69-
}
7017
}

core/src/main/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposer.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
package com.scalar.db.transaction.consensuscommit;
22

3-
import static com.scalar.db.api.ConditionalExpression.Operator;
43
import static com.scalar.db.transaction.consensuscommit.Attribute.COMMITTED_AT;
54
import static com.scalar.db.transaction.consensuscommit.Attribute.ID;
65
import static com.scalar.db.transaction.consensuscommit.Attribute.STATE;
7-
import static com.scalar.db.transaction.consensuscommit.Attribute.toIdValue;
8-
import static com.scalar.db.transaction.consensuscommit.Attribute.toStateValue;
96
import static com.scalar.db.transaction.consensuscommit.ConsensusCommitUtils.getTransactionTableMetadata;
107

118
import com.google.common.annotations.VisibleForTesting;
129
import com.scalar.db.api.ConditionBuilder;
13-
import com.scalar.db.api.ConditionalExpression;
1410
import com.scalar.db.api.Consistency;
1511
import com.scalar.db.api.Delete;
16-
import com.scalar.db.api.DeleteIf;
1712
import com.scalar.db.api.Mutation;
1813
import com.scalar.db.api.Operation;
1914
import com.scalar.db.api.Put;
@@ -124,10 +119,9 @@ private Delete composeDelete(Operation base, @Nullable TransactionResult result)
124119
.forTable(base.forTable().get())
125120
.withConsistency(Consistency.LINEARIZABLE)
126121
.withCondition(
127-
new DeleteIf(
128-
new ConditionalExpression(ID, toIdValue(id), Operator.EQ),
129-
new ConditionalExpression(
130-
STATE, toStateValue(TransactionState.DELETED), Operator.EQ)));
122+
ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(id))
123+
.and(ConditionBuilder.column(STATE).isEqualToInt(TransactionState.DELETED.get()))
124+
.build());
131125
}
132126

133127
private Key getPartitionKey(Operation base, @Nullable TransactionResult result)

core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import com.google.common.base.Joiner;
77
import com.google.common.base.Splitter;
88
import com.google.common.util.concurrent.Uninterruptibles;
9+
import com.scalar.db.api.ConditionBuilder;
910
import com.scalar.db.api.Consistency;
1011
import com.scalar.db.api.DistributedStorage;
1112
import com.scalar.db.api.Get;
1213
import com.scalar.db.api.Put;
13-
import com.scalar.db.api.PutIfNotExists;
1414
import com.scalar.db.api.Result;
1515
import com.scalar.db.api.TableMetadata;
1616
import com.scalar.db.api.TransactionState;
@@ -293,7 +293,7 @@ private void putStateForLazyRecoveryRollbackForGroupCommit(String id)
293293

294294
@VisibleForTesting
295295
Get createGetWith(String id) {
296-
return new Get(new Key(Attribute.toIdValue(id)))
296+
return new Get(Key.ofText(Attribute.ID, id))
297297
.withConsistency(Consistency.LINEARIZABLE)
298298
.forNamespace(coordinatorNamespace)
299299
.forTable(TABLE);
@@ -334,15 +334,15 @@ private Optional<Coordinator.State> get(Get get, String id) throws CoordinatorEx
334334

335335
@VisibleForTesting
336336
Put createPutWith(Coordinator.State state) {
337-
Put put = new Put(new Key(Attribute.toIdValue(state.getId())));
337+
Put put = new Put(Key.ofText(Attribute.ID, state.getId()));
338338
String childIds = state.getChildIdsAsString();
339339
if (!childIds.isEmpty()) {
340-
put.withValue(Attribute.toChildIdsValue(childIds));
340+
put.withTextValue(Attribute.CHILD_IDS, childIds);
341341
}
342-
return put.withValue(Attribute.toStateValue(state.getState()))
343-
.withValue(Attribute.toCreatedAtValue(state.getCreatedAt()))
342+
return put.withIntValue(Attribute.STATE, state.getState().get())
343+
.withBigIntValue(Attribute.CREATED_AT, state.getCreatedAt())
344344
.withConsistency(Consistency.LINEARIZABLE)
345-
.withCondition(new PutIfNotExists())
345+
.withCondition(ConditionBuilder.putIfNotExists())
346346
.forNamespace(coordinatorNamespace)
347347
.forTable(TABLE);
348348
}

0 commit comments

Comments
 (0)