Skip to content

Commit a09a04a

Browse files
brfrn169gemini-code-assist[bot]Copilot
authored
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 bbed1ba commit a09a04a

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
@@ -183,8 +183,8 @@ public void whenPutDataIntoTable1_DataShouldBeWrittenIntoCassandra() throws Exec
183183
// Arrange
184184
String namespace = NAMESPACE1;
185185
String table = TABLE1;
186-
Key partitionKey = new Key(COL_NAME1, 1);
187-
Key clusteringKey = new Key(COL_NAME4, 4);
186+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
187+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
188188
Put put =
189189
new Put(partitionKey, clusteringKey)
190190
.withValue(COL_NAME2, "val2")
@@ -225,8 +225,8 @@ public void whenPutDataIntoTable2_DataShouldBeWrittenIntoJdbcDatabase()
225225
// Arrange
226226
String namespace = NAMESPACE1;
227227
String table = TABLE2;
228-
Key partitionKey = new Key(COL_NAME1, 1);
229-
Key clusteringKey = new Key(COL_NAME4, 4);
228+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
229+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
230230
Put put =
231231
new Put(partitionKey, clusteringKey)
232232
.withValue(COL_NAME2, "val2")
@@ -267,8 +267,8 @@ public void whenPutDataIntoTable3_DataShouldBeWrittenIntoDefaultStorage()
267267
// Arrange
268268
String namespace = NAMESPACE1;
269269
String table = TABLE3;
270-
Key partitionKey = new Key(COL_NAME1, 1);
271-
Key clusteringKey = new Key(COL_NAME4, 4);
270+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
271+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
272272

273273
Put put =
274274
new Put(partitionKey, clusteringKey)
@@ -310,10 +310,10 @@ public void whenScanDataFromTable1_DataShouldBeScannedFromCassandra()
310310
// Arrange
311311
String namespace = NAMESPACE1;
312312
String table = TABLE1;
313-
Key partitionKey = new Key(COL_NAME1, 1);
314-
Key clusteringKey1 = new Key(COL_NAME4, 0);
315-
Key clusteringKey2 = new Key(COL_NAME4, 1);
316-
Key clusteringKey3 = new Key(COL_NAME4, 2);
313+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
314+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 0);
315+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 1);
316+
Key clusteringKey3 = Key.ofInt(COL_NAME4, 2);
317317

318318
cassandra.mutate(
319319
Arrays.asList(
@@ -352,10 +352,10 @@ public void whenScanDataFromTable2_DataShouldBeScannedFromJdbcDatabase()
352352
// Arrange
353353
String namespace = NAMESPACE1;
354354
String table = TABLE2;
355-
Key partitionKey = new Key(COL_NAME1, 1);
356-
Key clusteringKey1 = new Key(COL_NAME4, 0);
357-
Key clusteringKey2 = new Key(COL_NAME4, 1);
358-
Key clusteringKey3 = new Key(COL_NAME4, 2);
355+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
356+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 0);
357+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 1);
358+
Key clusteringKey3 = Key.ofInt(COL_NAME4, 2);
359359

360360
jdbcDatabase.mutate(
361361
Arrays.asList(
@@ -394,10 +394,10 @@ public void whenScanDataFromTable3_DataShouldBeScannedFromDefaultStorage()
394394
// Arrange
395395
String namespace = NAMESPACE1;
396396
String table = TABLE3;
397-
Key partitionKey = new Key(COL_NAME1, 1);
398-
Key clusteringKey1 = new Key(COL_NAME4, 0);
399-
Key clusteringKey2 = new Key(COL_NAME4, 1);
400-
Key clusteringKey3 = new Key(COL_NAME4, 2);
397+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
398+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 0);
399+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 1);
400+
Key clusteringKey3 = Key.ofInt(COL_NAME4, 2);
401401

402402
cassandra.mutate(
403403
Arrays.asList(
@@ -442,8 +442,8 @@ public void whenDeleteDataFromTable1_DataShouldBeDeletedFromCassandra()
442442
// Arrange
443443
String namespace = NAMESPACE1;
444444
String table = TABLE1;
445-
Key partitionKey = new Key(COL_NAME1, 1);
446-
Key clusteringKey = new Key(COL_NAME4, 4);
445+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
446+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
447447
Put put =
448448
new Put(partitionKey, clusteringKey)
449449
.withValue(COL_NAME3, 3)
@@ -479,8 +479,8 @@ public void whenDeleteDataFromTable2_DataShouldBeDeletedFromJdbcDatabase()
479479
// Arrange
480480
String namespace = NAMESPACE1;
481481
String table = TABLE2;
482-
Key partitionKey = new Key(COL_NAME1, 1);
483-
Key clusteringKey = new Key(COL_NAME4, 4);
482+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
483+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
484484
Put put =
485485
new Put(partitionKey, clusteringKey)
486486
.withValue(COL_NAME3, 3)
@@ -516,8 +516,8 @@ public void whenDeleteDataFromTable3_DataShouldBeDeletedFromDefaultStorage()
516516
// Arrange
517517
String namespace = NAMESPACE1;
518518
String table = TABLE3;
519-
Key partitionKey = new Key(COL_NAME1, 1);
520-
Key clusteringKey = new Key(COL_NAME4, 4);
519+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
520+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
521521
Put put =
522522
new Put(partitionKey, clusteringKey)
523523
.withValue(COL_NAME3, 3)
@@ -552,9 +552,9 @@ public void whenMutateDataToTable1_ShouldExecuteForCassandra() throws ExecutionE
552552
// Arrange
553553
String namespace = NAMESPACE1;
554554
String table = TABLE1;
555-
Key partitionKey = new Key(COL_NAME1, 1);
556-
Key clusteringKey1 = new Key(COL_NAME4, 1);
557-
Key clusteringKey2 = new Key(COL_NAME4, 2);
555+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
556+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 1);
557+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 2);
558558
Put put =
559559
new Put(partitionKey, clusteringKey1)
560560
.withValue(COL_NAME3, 3)
@@ -607,9 +607,9 @@ public void whenMutateDataToTable2_ShouldExecuteForJdbcDatabase() throws Executi
607607
// Arrange
608608
String namespace = NAMESPACE1;
609609
String table = TABLE2;
610-
Key partitionKey = new Key(COL_NAME1, 1);
611-
Key clusteringKey1 = new Key(COL_NAME4, 1);
612-
Key clusteringKey2 = new Key(COL_NAME4, 2);
610+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
611+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 1);
612+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 2);
613613
Put put =
614614
new Put(partitionKey, clusteringKey1)
615615
.withValue(COL_NAME3, 3)
@@ -662,9 +662,9 @@ public void whenMutateDataToTable3_ShouldExecuteForDefaultStorage() throws Execu
662662
// Arrange
663663
String namespace = NAMESPACE1;
664664
String table = TABLE3;
665-
Key partitionKey = new Key(COL_NAME1, 1);
666-
Key clusteringKey1 = new Key(COL_NAME4, 1);
667-
Key clusteringKey2 = new Key(COL_NAME4, 2);
665+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
666+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 1);
667+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 2);
668668
Put put =
669669
new Put(partitionKey, clusteringKey1)
670670
.withValue(COL_NAME3, 3)
@@ -718,8 +718,8 @@ public void whenPutDataIntoTable1InNamespace2_DataShouldBeWrittenIntoJdbcDatabas
718718
// Arrange
719719
String namespace = NAMESPACE2;
720720
String table = TABLE1;
721-
Key partitionKey = new Key(COL_NAME1, 1);
722-
Key clusteringKey = new Key(COL_NAME4, 4);
721+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
722+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
723723
Put put =
724724
new Put(partitionKey, clusteringKey)
725725
.withValue(COL_NAME2, "val2")
@@ -760,10 +760,10 @@ public void whenScanDataFromTable1InNamespace2_DataShouldBeScannedFromJdbcDataba
760760
// Arrange
761761
String namespace = NAMESPACE2;
762762
String table = TABLE1;
763-
Key partitionKey = new Key(COL_NAME1, 1);
764-
Key clusteringKey1 = new Key(COL_NAME4, 0);
765-
Key clusteringKey2 = new Key(COL_NAME4, 1);
766-
Key clusteringKey3 = new Key(COL_NAME4, 2);
763+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
764+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 0);
765+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 1);
766+
Key clusteringKey3 = Key.ofInt(COL_NAME4, 2);
767767

768768
jdbcDatabase.mutate(
769769
Arrays.asList(
@@ -802,8 +802,8 @@ public void whenDeleteDataFromTable1InNamespace2_DataShouldBeDeletedFromJdbcData
802802
// Arrange
803803
String namespace = NAMESPACE2;
804804
String table = TABLE1;
805-
Key partitionKey = new Key(COL_NAME1, 1);
806-
Key clusteringKey = new Key(COL_NAME4, 4);
805+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
806+
Key clusteringKey = Key.ofInt(COL_NAME4, 4);
807807
Put put =
808808
new Put(partitionKey, clusteringKey)
809809
.withValue(COL_NAME3, 3)
@@ -839,9 +839,9 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForCassandra()
839839
// Arrange
840840
String namespace = NAMESPACE2;
841841
String table = TABLE1;
842-
Key partitionKey = new Key(COL_NAME1, 1);
843-
Key clusteringKey1 = new Key(COL_NAME4, 1);
844-
Key clusteringKey2 = new Key(COL_NAME4, 2);
842+
Key partitionKey = Key.ofInt(COL_NAME1, 1);
843+
Key clusteringKey1 = Key.ofInt(COL_NAME4, 1);
844+
Key clusteringKey2 = Key.ofInt(COL_NAME4, 2);
845845
Put put =
846846
new Put(partitionKey, clusteringKey1)
847847
.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;
@@ -286,7 +286,7 @@ private void putStateForLazyRecoveryRollbackForGroupCommit(String id)
286286

287287
@VisibleForTesting
288288
Get createGetWith(String id) {
289-
return new Get(new Key(Attribute.toIdValue(id)))
289+
return new Get(Key.ofText(Attribute.ID, id))
290290
.withConsistency(Consistency.LINEARIZABLE)
291291
.forNamespace(coordinatorNamespace)
292292
.forTable(TABLE);
@@ -327,15 +327,15 @@ private Optional<Coordinator.State> get(Get get, String id) throws CoordinatorEx
327327

328328
@VisibleForTesting
329329
Put createPutWith(Coordinator.State state) {
330-
Put put = new Put(new Key(Attribute.toIdValue(state.getId())));
330+
Put put = new Put(Key.ofText(Attribute.ID, state.getId()));
331331
String childIds = state.getChildIdsAsString();
332332
if (!childIds.isEmpty()) {
333-
put.withValue(Attribute.toChildIdsValue(childIds));
333+
put.withTextValue(Attribute.CHILD_IDS, childIds);
334334
}
335-
return put.withValue(Attribute.toStateValue(state.getState()))
336-
.withValue(Attribute.toCreatedAtValue(state.getCreatedAt()))
335+
return put.withIntValue(Attribute.STATE, state.getState().get())
336+
.withBigIntValue(Attribute.CREATED_AT, state.getCreatedAt())
337337
.withConsistency(Consistency.LINEARIZABLE)
338-
.withCondition(new PutIfNotExists())
338+
.withCondition(ConditionBuilder.putIfNotExists())
339339
.forNamespace(coordinatorNamespace)
340340
.forTable(TABLE);
341341
}

0 commit comments

Comments
 (0)