Skip to content

Commit 1281a6b

Browse files
committed
Remove deprecated API usages (Part 3) (#2974)
1 parent a3eef34 commit 1281a6b

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
@@ -50,7 +50,7 @@ public void beforeAll() throws ExecutionException {
5050
private void initCassandraAdmin() throws ExecutionException {
5151
Properties properties = MultiStorageEnv.getPropertiesForCassandra(TEST_NAME);
5252
StorageFactory factory = StorageFactory.create(properties);
53-
cassandraAdmin = factory.getAdmin();
53+
cassandraAdmin = factory.getStorageAdmin();
5454

5555
// create tables
5656
cassandraAdmin.createNamespace(NAMESPACE1, true);
@@ -79,7 +79,7 @@ private void initCassandraAdmin() throws ExecutionException {
7979

8080
private void initJdbcAdmin() throws ExecutionException {
8181
StorageFactory factory = StorageFactory.create(MultiStorageEnv.getPropertiesForJdbc(TEST_NAME));
82-
jdbcAdmin = factory.getAdmin();
82+
jdbcAdmin = factory.getStorageAdmin();
8383

8484
// create tables
8585
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
@@ -74,14 +74,14 @@ public void beforeAll() throws ExecutionException {
7474
private void initCassandraAndCassandraAdmin() throws ExecutionException {
7575
StorageFactory factory =
7676
StorageFactory.create(MultiStorageEnv.getPropertiesForCassandra(TEST_NAME));
77-
cassandraAdmin = factory.getAdmin();
77+
cassandraAdmin = factory.getStorageAdmin();
7878
createTables(cassandraAdmin);
7979
cassandra = factory.getStorage();
8080
}
8181

8282
private void initJdbcDatabaseAndJdbcAdmin() throws ExecutionException {
8383
StorageFactory factory = StorageFactory.create(MultiStorageEnv.getPropertiesForJdbc(TEST_NAME));
84-
jdbcAdmin = factory.getAdmin();
84+
jdbcAdmin = factory.getStorageAdmin();
8585
createTables(jdbcAdmin);
8686
jdbcDatabase = factory.getStorage();
8787
}
@@ -1178,28 +1178,32 @@ public void operation_WhenDefaultNamespaceGiven_ShouldWorkProperly() {
11781178
}
11791179

11801180
private int getCol1Value(Result result) {
1181-
assertThat(result.getValue(COL_NAME1).isPresent()).isTrue();
1182-
return result.getValue(COL_NAME1).get().getAsInt();
1181+
assertThat(result.contains(COL_NAME1)).isTrue();
1182+
assertThat(result.isNull(COL_NAME1)).isFalse();
1183+
return result.getInt(COL_NAME1);
11831184
}
11841185

11851186
private String getCol2Value(Result result) {
1186-
assertThat(result.getValue(COL_NAME2).isPresent()).isTrue();
1187-
assertThat(result.getValue(COL_NAME2).get().getAsString().isPresent()).isTrue();
1188-
return result.getValue(COL_NAME2).get().getAsString().get();
1187+
assertThat(result.contains(COL_NAME2)).isTrue();
1188+
assertThat(result.isNull(COL_NAME2)).isFalse();
1189+
return result.getText(COL_NAME2);
11891190
}
11901191

11911192
private int getCol3Value(Result result) {
1192-
assertThat(result.getValue(COL_NAME3).isPresent()).isTrue();
1193-
return result.getValue(COL_NAME3).get().getAsInt();
1193+
assertThat(result.contains(COL_NAME3)).isTrue();
1194+
assertThat(result.isNull(COL_NAME3)).isFalse();
1195+
return result.getInt(COL_NAME3);
11941196
}
11951197

11961198
private int getCol4Value(Result result) {
1197-
assertThat(result.getValue(COL_NAME4).isPresent()).isTrue();
1198-
return result.getValue(COL_NAME4).get().getAsInt();
1199+
assertThat(result.contains(COL_NAME4)).isTrue();
1200+
assertThat(result.isNull(COL_NAME4)).isFalse();
1201+
return result.getInt(COL_NAME4);
11991202
}
12001203

12011204
private boolean getCol5Value(Result result) {
1202-
assertThat(result.getValue(COL_NAME5).isPresent()).isTrue();
1203-
return result.getValue(COL_NAME5).get().getAsBoolean();
1205+
assertThat(result.contains(COL_NAME5)).isTrue();
1206+
assertThat(result.isNull(COL_NAME5)).isFalse();
1207+
return result.getBoolean(COL_NAME5);
12041208
}
12051209
}

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;
@@ -401,20 +400,15 @@ public static class State {
401400

402401
public State(Result result) throws CoordinatorException {
403402
checkNotMissingRequired(result);
404-
id = result.getValue(Attribute.ID).get().getAsString().get();
405-
state = TransactionState.getInstance(result.getValue(Attribute.STATE).get().getAsInt());
406-
createdAt = result.getValue(Attribute.CREATED_AT).get().getAsLong();
407-
Optional<Value<?>> childIdsOpt = result.getValue(Attribute.CHILD_IDS);
408-
Optional<String> childIdsStrOpt;
409-
if (childIdsOpt.isPresent()) {
410-
childIdsStrOpt = childIdsOpt.get().getAsString();
403+
id = result.getText(Attribute.ID);
404+
state = TransactionState.getInstance(result.getInt(Attribute.STATE));
405+
createdAt = result.getBigInt(Attribute.CREATED_AT);
406+
String childIdsStr = result.getText(Attribute.CHILD_IDS);
407+
if (childIdsStr != null) {
408+
childIds = Splitter.on(CHILD_IDS_DELIMITER).omitEmptyStrings().splitToList(childIdsStr);
411409
} else {
412-
childIdsStrOpt = Optional.empty();
410+
childIds = EMPTY_CHILD_IDS;
413411
}
414-
childIds =
415-
childIdsStrOpt
416-
.map(s -> Splitter.on(CHILD_IDS_DELIMITER).omitEmptyStrings().splitToList(s))
417-
.orElse(EMPTY_CHILD_IDS);
418412
}
419413

420414
public State(String id, TransactionState state) {
@@ -493,16 +487,13 @@ public int hashCode() {
493487
}
494488

495489
private void checkNotMissingRequired(Result result) throws CoordinatorException {
496-
if (!result.getValue(Attribute.ID).isPresent()
497-
|| !result.getValue(Attribute.ID).get().getAsString().isPresent()) {
490+
if (result.isNull(Attribute.ID) || result.getText(Attribute.ID) == null) {
498491
throw new CoordinatorException("id is missing in the coordinator state");
499492
}
500-
if (!result.getValue(Attribute.STATE).isPresent()
501-
|| result.getValue(Attribute.STATE).get().getAsInt() == 0) {
493+
if (result.isNull(Attribute.STATE) || result.getInt(Attribute.STATE) == 0) {
502494
throw new CoordinatorException("state is missing in the coordinator state");
503495
}
504-
if (!result.getValue(Attribute.CREATED_AT).isPresent()
505-
|| result.getValue(Attribute.CREATED_AT).get().getAsLong() == 0) {
496+
if (result.isNull(Attribute.CREATED_AT) || result.getBigInt(Attribute.CREATED_AT) == 0) {
506497
throw new CoordinatorException("created_at is missing in the coordinator state");
507498
}
508499
}

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)