Skip to content

Commit 9f3a31b

Browse files
authored
Remove deprecated API usages (Part 3) (#2974)
1 parent 47b8d43 commit 9f3a31b

File tree

40 files changed

+631
-698
lines changed

40 files changed

+631
-698
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private Map<String, String> getCreationOptions() {
5757
private void initCassandraAdmin() throws ExecutionException {
5858
StorageFactory factory =
5959
StorageFactory.create(MultiStorageEnv.getPropertiesForCassandra(TEST_NAME));
60-
cassandraAdmin = factory.getAdmin();
60+
cassandraAdmin = factory.getStorageAdmin();
6161

6262
// create tables
6363
cassandraAdmin.createNamespace(NAMESPACE1, true, getCreationOptions());
@@ -81,7 +81,7 @@ private void initCassandraAdmin() throws ExecutionException {
8181

8282
private void initJdbcAdmin() throws ExecutionException {
8383
StorageFactory factory = StorageFactory.create(MultiStorageEnv.getPropertiesForJdbc(TEST_NAME));
84-
jdbcAdmin = factory.getAdmin();
84+
jdbcAdmin = factory.getStorageAdmin();
8585

8686
// create tables
8787
jdbcAdmin.createNamespace(NAMESPACE1, true);

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ public void beforeAll() throws ExecutionException {
7676
private void initCassandraAndCassandraAdmin() throws ExecutionException {
7777
StorageFactory factory =
7878
StorageFactory.create(MultiStorageEnv.getPropertiesForCassandra(TEST_NAME));
79-
cassandraAdmin = factory.getAdmin();
79+
cassandraAdmin = factory.getStorageAdmin();
8080
createTables(cassandraAdmin);
8181
cassandra = factory.getStorage();
8282
}
8383

8484
private void initJdbcDatabaseAndJdbcAdmin() throws ExecutionException {
8585
StorageFactory factory = StorageFactory.create(MultiStorageEnv.getPropertiesForJdbc(TEST_NAME));
86-
jdbcAdmin = factory.getAdmin();
86+
jdbcAdmin = factory.getStorageAdmin();
8787
createTables(jdbcAdmin);
8888
jdbcDatabase = factory.getStorage();
8989
}
@@ -1189,28 +1189,32 @@ public void operation_WhenDefaultNamespaceGiven_ShouldWorkProperly() {
11891189
}
11901190

11911191
private int getCol1Value(Result result) {
1192-
assertThat(result.getValue(COL_NAME1).isPresent()).isTrue();
1193-
return result.getValue(COL_NAME1).get().getAsInt();
1192+
assertThat(result.contains(COL_NAME1)).isTrue();
1193+
assertThat(result.isNull(COL_NAME1)).isFalse();
1194+
return result.getInt(COL_NAME1);
11941195
}
11951196

11961197
private String getCol2Value(Result result) {
1197-
assertThat(result.getValue(COL_NAME2).isPresent()).isTrue();
1198-
assertThat(result.getValue(COL_NAME2).get().getAsString().isPresent()).isTrue();
1199-
return result.getValue(COL_NAME2).get().getAsString().get();
1198+
assertThat(result.contains(COL_NAME2)).isTrue();
1199+
assertThat(result.isNull(COL_NAME2)).isFalse();
1200+
return result.getText(COL_NAME2);
12001201
}
12011202

12021203
private int getCol3Value(Result result) {
1203-
assertThat(result.getValue(COL_NAME3).isPresent()).isTrue();
1204-
return result.getValue(COL_NAME3).get().getAsInt();
1204+
assertThat(result.contains(COL_NAME3)).isTrue();
1205+
assertThat(result.isNull(COL_NAME3)).isFalse();
1206+
return result.getInt(COL_NAME3);
12051207
}
12061208

12071209
private int getCol4Value(Result result) {
1208-
assertThat(result.getValue(COL_NAME4).isPresent()).isTrue();
1209-
return result.getValue(COL_NAME4).get().getAsInt();
1210+
assertThat(result.contains(COL_NAME4)).isTrue();
1211+
assertThat(result.isNull(COL_NAME4)).isFalse();
1212+
return result.getInt(COL_NAME4);
12101213
}
12111214

12121215
private boolean getCol5Value(Result result) {
1213-
assertThat(result.getValue(COL_NAME5).isPresent()).isTrue();
1214-
return result.getValue(COL_NAME5).get().getAsBoolean();
1216+
assertThat(result.contains(COL_NAME5)).isTrue();
1217+
assertThat(result.isNull(COL_NAME5)).isFalse();
1218+
return result.getBoolean(COL_NAME5);
12151219
}
12161220
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ private boolean setConditions(
326326

327327
private Key getKeyWithoutLastValue(Key originalKey) {
328328
Key.Builder keyBuilder = Key.newBuilder();
329-
for (int i = 0; i < originalKey.getColumns().size() - 1; i++) {
330-
keyBuilder.add(originalKey.getColumns().get(i));
329+
List<Column<?>> columns = originalKey.getColumns();
330+
for (int i = 0; i < columns.size() - 1; i++) {
331+
keyBuilder.add(columns.get(i));
331332
}
332333
return keyBuilder.build();
333334
}

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.scalar.db.exception.storage.NoMutationException;
1919
import com.scalar.db.io.DataType;
2020
import com.scalar.db.io.Key;
21-
import com.scalar.db.io.Value;
2221
import com.scalar.db.transaction.consensuscommit.CoordinatorGroupCommitter.CoordinatorGroupCommitKeyManipulator;
2322
import com.scalar.db.util.groupcommit.GroupCommitKeyManipulator.Keys;
2423
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -394,20 +393,15 @@ public static class State {
394393

395394
public State(Result result) throws CoordinatorException {
396395
checkNotMissingRequired(result);
397-
id = result.getValue(Attribute.ID).get().getAsString().get();
398-
state = TransactionState.getInstance(result.getValue(Attribute.STATE).get().getAsInt());
399-
createdAt = result.getValue(Attribute.CREATED_AT).get().getAsLong();
400-
Optional<Value<?>> childIdsOpt = result.getValue(Attribute.CHILD_IDS);
401-
Optional<String> childIdsStrOpt;
402-
if (childIdsOpt.isPresent()) {
403-
childIdsStrOpt = childIdsOpt.get().getAsString();
396+
id = result.getText(Attribute.ID);
397+
state = TransactionState.getInstance(result.getInt(Attribute.STATE));
398+
createdAt = result.getBigInt(Attribute.CREATED_AT);
399+
String childIdsStr = result.getText(Attribute.CHILD_IDS);
400+
if (childIdsStr != null) {
401+
childIds = Splitter.on(CHILD_IDS_DELIMITER).omitEmptyStrings().splitToList(childIdsStr);
404402
} else {
405-
childIdsStrOpt = Optional.empty();
403+
childIds = EMPTY_CHILD_IDS;
406404
}
407-
childIds =
408-
childIdsStrOpt
409-
.map(s -> Splitter.on(CHILD_IDS_DELIMITER).omitEmptyStrings().splitToList(s))
410-
.orElse(EMPTY_CHILD_IDS);
411405
}
412406

413407
public State(String id, TransactionState state) {
@@ -486,16 +480,13 @@ public int hashCode() {
486480
}
487481

488482
private void checkNotMissingRequired(Result result) throws CoordinatorException {
489-
if (!result.getValue(Attribute.ID).isPresent()
490-
|| !result.getValue(Attribute.ID).get().getAsString().isPresent()) {
483+
if (result.isNull(Attribute.ID) || result.getText(Attribute.ID) == null) {
491484
throw new CoordinatorException("id is missing in the coordinator state");
492485
}
493-
if (!result.getValue(Attribute.STATE).isPresent()
494-
|| result.getValue(Attribute.STATE).get().getAsInt() == 0) {
486+
if (result.isNull(Attribute.STATE) || result.getInt(Attribute.STATE) == 0) {
495487
throw new CoordinatorException("state is missing in the coordinator state");
496488
}
497-
if (!result.getValue(Attribute.CREATED_AT).isPresent()
498-
|| result.getValue(Attribute.CREATED_AT).get().getAsLong() == 0) {
489+
if (result.isNull(Attribute.CREATED_AT) || result.getBigInt(Attribute.CREATED_AT) == 0) {
499490
throw new CoordinatorException("created_at is missing in the coordinator state");
500491
}
501492
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ Optional<TransactionResult> read(@Nullable Snapshot.Key key, Get get) throws Cru
157157
if (key == null) {
158158
// Only for a Get with index, the argument `key` is null. In that case, create a key from
159159
// the result
160-
key = new Snapshot.Key(get, result.get());
160+
TableMetadata tableMetadata = getTableMetadata(get);
161+
key = new Snapshot.Key(get, result.get(), tableMetadata);
161162
}
162163

163164
result = executeRecovery(key, get, result.get());
@@ -186,7 +187,8 @@ Optional<TransactionResult> read(@Nullable Snapshot.Key key, Get get) throws Cru
186187
if (result.isPresent()) {
187188
// Only when we can get the record with the Get with index, we can put it into the read
188189
// set
189-
key = new Snapshot.Key(get, result.get());
190+
TableMetadata tableMetadata = getTableMetadata(get);
191+
key = new Snapshot.Key(get, result.get(), tableMetadata);
190192
putIntoReadSetInSnapshot(key, result);
191193
}
192194
}
@@ -255,7 +257,8 @@ private LinkedHashMap<Snapshot.Key, TransactionResult> scanInternal(Scan scan)
255257

256258
for (Result r : scanner) {
257259
TransactionResult result = new TransactionResult(r);
258-
Snapshot.Key key = new Snapshot.Key(scan, r);
260+
TableMetadata tableMetadata = getTableMetadata(scan);
261+
Snapshot.Key key = new Snapshot.Key(scan, r, tableMetadata);
259262
Optional<TransactionResult> processedScanResult = processScanResult(key, scan, result);
260263
processedScanResult.ifPresent(res -> results.put(key, res));
261264

@@ -810,7 +813,8 @@ public Optional<Result> one() throws CrudException {
810813
return Optional.empty();
811814
}
812815

813-
Snapshot.Key key = new Snapshot.Key(scan, r.get());
816+
TableMetadata tableMetadata = getTableMetadata(scan);
817+
Snapshot.Key key = new Snapshot.Key(scan, r.get(), tableMetadata);
814818
TransactionResult result = new TransactionResult(r.get());
815819

816820
Optional<TransactionResult> processedScanResult = processScanResult(key, scan, result);

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.scalar.db.api.Result;
1919
import com.scalar.db.api.Scan;
2020
import com.scalar.db.api.ScanAll;
21-
import com.scalar.db.api.ScanBuilder;
2221
import com.scalar.db.api.ScanWithIndex;
2322
import com.scalar.db.api.Scanner;
2423
import com.scalar.db.api.Selection.Conjunction;
@@ -596,16 +595,14 @@ private void validateScanResults(
596595
Scanner scanner = null;
597596
try {
598597
// Only get tx_id and primary key columns because we use only them to compare
599-
ScanBuilder.BuildableScanOrScanAllFromExisting builder =
600-
Scan.newBuilder(scan).clearProjections().projection(Attribute.ID);
601598
TableMetadata tableMetadata = getTableMetadata(scan);
602-
for (String partitionKeyName : tableMetadata.getPartitionKeyNames()) {
603-
builder = builder.projection(partitionKeyName);
604-
}
605-
for (String clusteringKeyName : tableMetadata.getClusteringKeyNames()) {
606-
builder = builder.projection(clusteringKeyName);
607-
}
608-
scan = builder.build();
599+
scan =
600+
Scan.newBuilder(scan)
601+
.clearProjections()
602+
.projection(Attribute.ID)
603+
.projections(tableMetadata.getPartitionKeyNames())
604+
.projections(tableMetadata.getClusteringKeyNames())
605+
.build();
609606

610607
if (scan.getLimit() == 0) {
611608
scanner = storage.scan(scan);
@@ -626,7 +623,7 @@ private void validateScanResults(
626623
// Compare the records of the iterators
627624
while (latestResult.isPresent() && originalResultEntry != null) {
628625
TransactionResult latestTxResult = new TransactionResult(latestResult.get());
629-
Key key = new Key(scan, latestTxResult);
626+
Key key = new Key(scan, latestTxResult, tableMetadata);
630627

631628
if (latestTxResult.getId() != null && latestTxResult.getId().equals(id)) {
632629
// The record is inserted/deleted/updated by this transaction
@@ -744,7 +741,9 @@ private void validateGetWithIndexResult(
744741
.build();
745742

746743
LinkedHashMap<Key, TransactionResult> results = new LinkedHashMap<>(1);
747-
originalResult.ifPresent(r -> results.put(new Snapshot.Key(scanWithIndex, r), r));
744+
TableMetadata tableMetadata = getTableMetadata(scanWithIndex);
745+
originalResult.ifPresent(
746+
r -> results.put(new Snapshot.Key(scanWithIndex, r, tableMetadata), r));
748747

749748
// Validate the result to check if there is no anti-dependency
750749
validateScanResults(storage, scanWithIndex, results, false);
@@ -812,11 +811,11 @@ public Key(Get get) {
812811
this((Operation) get);
813812
}
814813

815-
public Key(Get get, Result result) {
814+
public Key(Get get, Result result, TableMetadata tableMetadata) {
816815
this.namespace = get.forNamespace().get();
817816
this.table = get.forTable().get();
818-
this.partitionKey = result.getPartitionKey().get();
819-
this.clusteringKey = result.getClusteringKey();
817+
this.partitionKey = ScalarDbUtils.getPartitionKey(result, tableMetadata);
818+
this.clusteringKey = ScalarDbUtils.getClusteringKey(result, tableMetadata);
820819
}
821820

822821
public Key(Put put) {
@@ -827,11 +826,11 @@ public Key(Delete delete) {
827826
this((Operation) delete);
828827
}
829828

830-
public Key(Scan scan, Result result) {
829+
public Key(Scan scan, Result result, TableMetadata tableMetadata) {
831830
this.namespace = scan.forNamespace().get();
832831
this.table = scan.forTable().get();
833-
this.partitionKey = result.getPartitionKey().get();
834-
this.clusteringKey = result.getClusteringKey();
832+
this.partitionKey = ScalarDbUtils.getPartitionKey(result, tableMetadata);
833+
this.clusteringKey = ScalarDbUtils.getClusteringKey(result, tableMetadata);
835834
}
836835

837836
private Key(Operation operation) {

core/src/test/java/com/scalar/db/api/DeleteTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import com.google.common.collect.ImmutableMap;
77
import com.scalar.db.io.Key;
8-
import com.scalar.db.io.Value;
98
import java.util.Optional;
9+
import org.assertj.core.api.Assertions;
1010
import org.junit.jupiter.api.Test;
1111

1212
public class DeleteTest {
@@ -32,7 +32,7 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() {
3232
Key actual = del.getPartitionKey();
3333

3434
// Assert
35-
assertThat((Iterable<? extends Value<?>>) expected).isEqualTo(actual);
35+
Assertions.<Key>assertThat(expected).isEqualTo(actual);
3636
}
3737

3838
@Test

core/src/test/java/com/scalar/db/api/GetTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import com.google.common.collect.ImmutableMap;
77
import com.scalar.db.io.Key;
8-
import com.scalar.db.io.Value;
98
import java.util.Arrays;
109
import java.util.List;
1110
import java.util.Optional;
11+
import org.assertj.core.api.Assertions;
1212
import org.junit.jupiter.api.Test;
1313

1414
public class GetTest {
@@ -48,7 +48,7 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() {
4848
Key actual = get.getPartitionKey();
4949

5050
// Assert
51-
assertThat((Iterable<? extends Value<?>>) expected).isEqualTo(actual);
51+
Assertions.<Key>assertThat(expected).isEqualTo(actual);
5252
}
5353

5454
@Test

core/src/test/java/com/scalar/db/api/PutTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Arrays;
3737
import java.util.Map;
3838
import java.util.Optional;
39+
import org.assertj.core.api.Assertions;
3940
import org.junit.jupiter.api.Test;
4041

4142
public class PutTest {
@@ -64,7 +65,7 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() {
6465
Key actual = put.getPartitionKey();
6566

6667
// Assert
67-
assertThat((Iterable<? extends Value<?>>) expected).isEqualTo(actual);
68+
Assertions.<Key>assertThat(expected).isEqualTo(actual);
6869
}
6970

7071
@Test

core/src/test/java/com/scalar/db/api/ScanTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import com.google.common.collect.ImmutableMap;
77
import com.scalar.db.api.Selection.Conjunction;
88
import com.scalar.db.io.Key;
9-
import com.scalar.db.io.Value;
109
import java.util.Collections;
1110
import java.util.Optional;
11+
import org.assertj.core.api.Assertions;
1212
import org.junit.jupiter.api.Test;
1313

1414
public class ScanTest {
@@ -96,7 +96,7 @@ public void constructorAndSetters_AllSet_ShouldGetWhatsSet() {
9696
.withLimit(100);
9797

9898
// Assert
99-
assertThat((Iterable<? extends Value<?>>) scan.getPartitionKey()).isEqualTo(partitionKey);
99+
Assertions.<Key>assertThat(scan.getPartitionKey()).isEqualTo(partitionKey);
100100
assertThat(scan.getStartClusteringKey()).isEqualTo(Optional.of(startClusteringKey));
101101
assertThat(scan.getEndClusteringKey()).isEqualTo(Optional.of(endClusteringKey));
102102
assertThat(scan.getProjections()).isEqualTo(Collections.singletonList(ANY_NAME_1));

0 commit comments

Comments
 (0)