diff --git a/src/integration-test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java b/src/integration-test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java index fe48d6c90a..8cf96e6708 100644 --- a/src/integration-test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java +++ b/src/integration-test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java @@ -34,7 +34,6 @@ import com.scalar.db.exception.transaction.UnknownTransactionStatusException; import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.Value; import com.scalar.db.transaction.consensuscommit.Coordinator.State; import java.util.ArrayList; import java.util.Arrays; @@ -868,7 +867,7 @@ public void getAndScan_CommitHappenedInBetween_ShouldReadRepeatably() public void putAndCommit_PutGivenForNonExisting_ShouldCreateRecord() throws CommitException, UnknownTransactionStatusException, CrudException { // Arrange - Value expected = new IntValue(BALANCE, INITIAL_BALANCE); + IntValue expected = new IntValue(BALANCE, INITIAL_BALANCE); Put put = preparePut(0, 0, TABLE_1).withValue(expected); transaction = manager.start(); @@ -896,7 +895,7 @@ public void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord() // Act Optional result = transaction.get(get); int afterBalance = ((IntValue) result.get().getValue(BALANCE).get()).get() + 100; - Value expected = new IntValue(BALANCE, afterBalance); + IntValue expected = new IntValue(BALANCE, afterBalance); Put put = preparePut(0, 0, TABLE_1).withValue(expected); transaction.put(put); transaction.commit(); @@ -929,7 +928,7 @@ public void putAndCommit_PutGivenForExistingAndNeverRead_ShouldThrowCommitExcept throws CommitException, UnknownTransactionStatusException, ExecutionException, CoordinatorException { // Arrange - Value balance = new IntValue(BALANCE, INITIAL_BALANCE); + IntValue balance = new IntValue(BALANCE, INITIAL_BALANCE); List puts = preparePuts(TABLE_1); puts.get(0).withValue(balance); puts.get(1).withValue(balance); @@ -951,7 +950,7 @@ public void putAndCommit_TwoPartitionsMutationsGiven_ShouldAccessStorageTwiceFor throws CommitException, UnknownTransactionStatusException, ExecutionException, CoordinatorException { // Arrange - Value balance = new IntValue(BALANCE, INITIAL_BALANCE); + IntValue balance = new IntValue(BALANCE, INITIAL_BALANCE); List puts = preparePuts(TABLE_1); puts.get(0).withValue(balance); puts.get(NUM_TYPES).withValue(balance); // next account @@ -1015,7 +1014,7 @@ private void commit_ConflictingPutsGivenForNonExisting_ShouldCommitOneAndAbortTh // Arrange boolean differentTables = !table1.equals(table2); - Value expected = new IntValue(BALANCE, INITIAL_BALANCE); + IntValue expected = new IntValue(BALANCE, INITIAL_BALANCE); List puts1 = preparePuts(table1); List puts2 = differentTables ? preparePuts(table2) : puts1; @@ -1246,7 +1245,7 @@ public void commit_NonConflictingPutsForDifferentTablesGivenForExisting_ShouldCo public void putAndCommit_GetsAndPutsForSameKeyButDifferentTablesGiven_ShouldCommitBoth() throws CrudException { // Arrange - Value expected = new IntValue(BALANCE, INITIAL_BALANCE); + IntValue expected = new IntValue(BALANCE, INITIAL_BALANCE); List puts1 = preparePuts(TABLE_1); List puts2 = preparePuts(TABLE_2); diff --git a/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java b/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java index 044364ffd8..7855d84536 100644 --- a/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java +++ b/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java @@ -13,7 +13,6 @@ import com.scalar.db.exception.transaction.TransactionException; import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.Value; import com.scalar.db.storage.common.metadata.DataType; import com.scalar.db.storage.jdbc.test.TestEnv; import java.util.ArrayList; @@ -109,7 +108,7 @@ public void scan_ScanGivenForNonExisting_ShouldReturnEmpty() throws TransactionE @Test public void putAndCommit_PutGivenForNonExisting_ShouldCreateRecord() throws TransactionException { // Arrange - Value expected = new IntValue(BALANCE, INITIAL_BALANCE); + IntValue expected = new IntValue(BALANCE, INITIAL_BALANCE); Put put = preparePut(0, 0, NAMESPACE, TABLE).withValue(expected); DistributedTransaction transaction = manager.start(); @@ -136,7 +135,7 @@ public void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord() // Act Optional result = transaction.get(get); int afterBalance = ((IntValue) result.get().getValue(BALANCE).get()).get() + 100; - Value expected = new IntValue(BALANCE, afterBalance); + IntValue expected = new IntValue(BALANCE, afterBalance); Put put = preparePut(0, 0, NAMESPACE, TABLE).withValue(expected); transaction.put(put); transaction.commit(); diff --git a/src/main/java/com/scalar/db/api/ConditionalExpression.java b/src/main/java/com/scalar/db/api/ConditionalExpression.java index 6ae8dd0fe2..abd4468b9b 100644 --- a/src/main/java/com/scalar/db/api/ConditionalExpression.java +++ b/src/main/java/com/scalar/db/api/ConditionalExpression.java @@ -10,7 +10,7 @@ */ public class ConditionalExpression { private final String name; - private final Value value; + private final Value value; private final Operator operator; /** @@ -23,7 +23,7 @@ public class ConditionalExpression { * @param value value used to compare with the target value * @param operator operator used to compare the target value specified with the name and the value */ - public ConditionalExpression(String name, Value value, Operator operator) { + public ConditionalExpression(String name, Value value, Operator operator) { this.name = name; this.value = value; this.operator = operator; @@ -44,7 +44,7 @@ public String getName() { * * @return the value used to compare with the target value */ - public Value getValue() { + public Value getValue() { return value; } diff --git a/src/main/java/com/scalar/db/api/Put.java b/src/main/java/com/scalar/db/api/Put.java index 4a43814fd3..5baf894bf9 100644 --- a/src/main/java/com/scalar/db/api/Put.java +++ b/src/main/java/com/scalar/db/api/Put.java @@ -17,7 +17,7 @@ */ @NotThreadSafe public class Put extends Mutation { - private final Map values; + private final Map> values; /** * Constructs a {@code Put} with the specified partition {@link Key}. @@ -46,7 +46,7 @@ public Put(Key partitionKey, Key clusteringKey) { * @param value a {@code Value} to put * @return this object */ - public Put withValue(Value value) { + public Put withValue(Value value) { values.put(value.getName(), value); return this; } @@ -57,7 +57,7 @@ public Put withValue(Value value) { * @param values a collection of {@code Value}s to put * @return this object */ - public Put withValues(Collection values) { + public Put withValues(Collection> values) { values.forEach(v -> this.values.put(v.getName(), v)); return this; } @@ -67,7 +67,7 @@ public Put withValues(Collection values) { * * @return a map of {@code Value}s */ - public Map getValues() { + public Map> getValues() { return ImmutableMap.copyOf(values); } diff --git a/src/main/java/com/scalar/db/api/Result.java b/src/main/java/com/scalar/db/api/Result.java index b141a248bb..4525ead861 100644 --- a/src/main/java/com/scalar/db/api/Result.java +++ b/src/main/java/com/scalar/db/api/Result.java @@ -32,12 +32,12 @@ public interface Result { * @param name name of the {@code Value} * @return an {@code Optional} with the {@code Value} */ - Optional getValue(String name); + Optional> getValue(String name); /** * Returns a map of {@link Value}s * * @return a map of {@code Value}s */ - Map getValues(); + Map> getValues(); } diff --git a/src/main/java/com/scalar/db/io/Key.java b/src/main/java/com/scalar/db/io/Key.java index 3b32384b7a..aaef55a07b 100644 --- a/src/main/java/com/scalar/db/io/Key.java +++ b/src/main/java/com/scalar/db/io/Key.java @@ -19,15 +19,15 @@ * @author Hiroyuki Yamada */ @Immutable -public final class Key implements Comparable, Iterable { - private final List values; +public final class Key implements Comparable, Iterable> { + private final List> values; /** * Constructs a {@code Key} with the specified {@link Value}s * * @param values one or more {@link Value}s which this key is composed of */ - public Key(Value... values) { + public Key(Value... values) { checkNotNull(values); this.values = new ArrayList<>(values.length); Arrays.stream(values).forEach(v -> this.values.add(v)); @@ -38,7 +38,7 @@ public Key(Value... values) { * * @param values a list of {@link Value}s which this key is composed of */ - public Key(List values) { + public Key(List> values) { checkNotNull(values); this.values = new ArrayList<>(values.size()); values.forEach(v -> this.values.add(v)); @@ -50,7 +50,7 @@ public Key(List values) { * @return list of {@code Value} which this key is composed of */ @Nonnull - public List get() { + public List> get() { return Collections.unmodifiableList(values); } @@ -104,14 +104,14 @@ public String toString() { } @Override - public Iterator iterator() { + public Iterator> iterator() { return values.iterator(); } @Override public int compareTo(Key o) { return ComparisonChain.start() - .compare(values, o.values, Ordering.natural().lexicographical()) + .compare(values, o.values, Ordering.>natural().lexicographical()) .result(); } } diff --git a/src/main/java/com/scalar/db/io/Value.java b/src/main/java/com/scalar/db/io/Value.java index 5be1eba720..8cfa05ffc1 100644 --- a/src/main/java/com/scalar/db/io/Value.java +++ b/src/main/java/com/scalar/db/io/Value.java @@ -20,7 +20,7 @@ public interface Value extends Comparable { * @param name name of a {@code Value} * @return a {@code Value} which has the same content of this value */ - Value copyWith(String name); + Value copyWith(String name); /** * Accepts a {@link ValueVisitor} to be able to be traversed diff --git a/src/main/java/com/scalar/db/storage/cassandra/ResultImpl.java b/src/main/java/com/scalar/db/storage/cassandra/ResultImpl.java index 6e79ce35ea..cd2738e702 100644 --- a/src/main/java/com/scalar/db/storage/cassandra/ResultImpl.java +++ b/src/main/java/com/scalar/db/storage/cassandra/ResultImpl.java @@ -1,5 +1,7 @@ package com.scalar.db.storage.cassandra; +import static com.google.common.base.Preconditions.checkNotNull; + import com.datastax.driver.core.ColumnDefinitions.Definition; import com.datastax.driver.core.DataType; import com.datastax.driver.core.Row; @@ -16,11 +18,6 @@ import com.scalar.db.io.Key; import com.scalar.db.io.TextValue; import com.scalar.db.io.Value; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nonnull; -import javax.annotation.concurrent.Immutable; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; @@ -32,14 +29,16 @@ import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Immutable public class ResultImpl implements Result { private static final Logger LOGGER = LoggerFactory.getLogger(ResultImpl.class); private final CassandraTableMetadata metadata; - private Map values; + private Map> values; public ResultImpl(Row row, CassandraTableMetadata metadata) { checkNotNull(row); @@ -53,7 +52,7 @@ public ResultImpl(Row row, CassandraTableMetadata metadata) { * @param values */ @VisibleForTesting - ResultImpl(Collection values, CassandraTableMetadata metadata) { + ResultImpl(Collection> values, CassandraTableMetadata metadata) { this.metadata = metadata; this.values = new HashMap<>(); values.forEach(v -> this.values.put(v.getName(), v)); @@ -70,13 +69,13 @@ public Optional getClusteringKey() { } @Override - public Optional getValue(String name) { + public Optional> getValue(String name) { return Optional.ofNullable(values.get(name)); } @Override @Nonnull - public Map getValues() { + public Map> getValues() { return Collections.unmodifiableMap(values); } @@ -111,7 +110,7 @@ void interpret(Row row) { getColumnDefinitions(row) .forEach( (name, type) -> { - Value value = convert(row, name, type.getName()); + Value value = convert(row, name, type.getName()); values.put(name, value); }); } @@ -129,9 +128,9 @@ Map getColumnDefinitions(Row row) { } private Optional getKey(LinkedHashSet names) { - List list = new ArrayList<>(); + List> list = new ArrayList<>(); for (String name : names) { - Value value = values.get(name); + Value value = values.get(name); if (value == null) { LOGGER.warn("full key doesn't seem to be projected into the result"); return Optional.empty(); @@ -141,7 +140,7 @@ private Optional getKey(LinkedHashSet names) { return Optional.of(new Key(list)); } - private static Value convert(Row row, String name, DataType.Name type) + private static Value convert(Row row, String name, DataType.Name type) throws UnsupportedTypeException { switch (type) { case BOOLEAN: diff --git a/src/main/java/com/scalar/db/storage/cassandra/SelectStatementHandler.java b/src/main/java/com/scalar/db/storage/cassandra/SelectStatementHandler.java index df2649753f..cfb8e7df2e 100644 --- a/src/main/java/com/scalar/db/storage/cassandra/SelectStatementHandler.java +++ b/src/main/java/com/scalar/db/storage/cassandra/SelectStatementHandler.java @@ -153,7 +153,7 @@ private void setStart(Select.Where statement, Scan scan) { scan.getStartClusteringKey() .ifPresent( k -> { - List start = k.get(); + List> start = k.get(); IntStream.range(0, start.size()) .forEach( i -> { @@ -178,7 +178,7 @@ private void setEnd(Select.Where statement, Scan scan) { scan.getEndClusteringKey() .ifPresent( k -> { - List end = k.get(); + List> end = k.get(); IntStream.range(0, end.size()) .forEach( i -> { diff --git a/src/main/java/com/scalar/db/storage/common/checker/ColumnChecker.java b/src/main/java/com/scalar/db/storage/common/checker/ColumnChecker.java index 2b71f0793c..793ce6fb07 100644 --- a/src/main/java/com/scalar/db/storage/common/checker/ColumnChecker.java +++ b/src/main/java/com/scalar/db/storage/common/checker/ColumnChecker.java @@ -11,7 +11,6 @@ import com.scalar.db.io.ValueVisitor; import com.scalar.db.storage.common.metadata.DataType; import com.scalar.db.storage.common.metadata.TableMetadata; - import javax.annotation.concurrent.NotThreadSafe; @NotThreadSafe @@ -24,7 +23,7 @@ public ColumnChecker(TableMetadata tableMetadata) { this.tableMetadata = tableMetadata; } - public boolean check(Value value) { + public boolean check(Value value) { // Check if the column exists if (!tableMetadata.getColumnNames().contains(getName(value))) { return false; @@ -35,12 +34,12 @@ public boolean check(Value value) { return isValid; } - public boolean check(String name, Value value) { + public boolean check(String name, Value value) { this.name = name; return check(value); } - private String getName(Value value) { + private String getName(Value value) { return name != null ? name : value.getName(); } diff --git a/src/main/java/com/scalar/db/storage/common/checker/OperationChecker.java b/src/main/java/com/scalar/db/storage/common/checker/OperationChecker.java index bc01a18635..d9f8bb9521 100644 --- a/src/main/java/com/scalar/db/storage/common/checker/OperationChecker.java +++ b/src/main/java/com/scalar/db/storage/common/checker/OperationChecker.java @@ -108,8 +108,8 @@ private void checkClusteringKeys(Scan scan, TableMetadata metadata) { } for (int i = 0; i < startClusteringKey.size() - 1; i++) { - Value startValue = startClusteringKey.get().get(i); - Value endValue = endClusteringKey.get().get(i); + Value startValue = startClusteringKey.get().get(i); + Value endValue = endClusteringKey.get().get(i); if (!startValue.equals(endValue)) { throw new IllegalArgumentException(message.get()); } @@ -201,7 +201,7 @@ private TableMetadata getMetadata(Operation operation) { } private void checkValues(Put put, TableMetadata metadata) { - for (Map.Entry entry : put.getValues().entrySet()) { + for (Map.Entry> entry : put.getValues().entrySet()) { if (!new ColumnChecker(metadata).check(entry.getValue())) { throw new IllegalArgumentException( "The values are not properly specified. Operation: " + put); @@ -269,7 +269,7 @@ private void checkClusteringKey(Operation operation, TableMetadata metadata) { private boolean checkKey( Key key, LinkedHashSet keyNames, boolean allowPartial, TableMetadata metadata) { - List values = new ArrayList<>(key.get()); + List> values = new ArrayList<>(key.get()); if (!allowPartial) { if (values.size() != keyNames.size()) { @@ -282,7 +282,7 @@ private boolean checkKey( } Iterator iterator = keyNames.iterator(); - for (Value value : values) { + for (Value value : values) { String keyName = iterator.next(); if (!keyName.equals(value.getName())) { diff --git a/src/main/java/com/scalar/db/storage/common/util/Utility.java b/src/main/java/com/scalar/db/storage/common/util/Utility.java index 94472c8d53..594ec5627b 100644 --- a/src/main/java/com/scalar/db/storage/common/util/Utility.java +++ b/src/main/java/com/scalar/db/storage/common/util/Utility.java @@ -3,7 +3,6 @@ import com.scalar.db.api.Operation; import com.scalar.db.io.Value; import com.scalar.db.storage.common.metadata.TableMetadata; - import java.util.List; import java.util.Optional; @@ -42,7 +41,7 @@ public static void setTargetToIfNot( } public static boolean isSecondaryIndexSpecified(Operation operation, TableMetadata metadata) { - List keyValues = operation.getPartitionKey().get(); + List> keyValues = operation.getPartitionKey().get(); if (keyValues.size() == 1) { String name = keyValues.get(0).getName(); return metadata.getSecondaryIndexNames().contains(name); diff --git a/src/main/java/com/scalar/db/storage/cosmos/CosmosMutation.java b/src/main/java/com/scalar/db/storage/cosmos/CosmosMutation.java index 7a34e3e37f..7b6f3113c0 100644 --- a/src/main/java/com/scalar/db/storage/cosmos/CosmosMutation.java +++ b/src/main/java/com/scalar/db/storage/cosmos/CosmosMutation.java @@ -114,7 +114,7 @@ public CosmosStoredProcedureRequestOptions getStoredProcedureOptions() { return new CosmosStoredProcedureRequestOptions().setPartitionKey(getCosmosPartitionKey()); } - private Map toMap(Collection values) { + private Map toMap(Collection> values) { MapVisitor visitor = new MapVisitor(); values.forEach(v -> v.accept(visitor)); diff --git a/src/main/java/com/scalar/db/storage/cosmos/CosmosOperation.java b/src/main/java/com/scalar/db/storage/cosmos/CosmosOperation.java index 8791de06ff..656e52915c 100644 --- a/src/main/java/com/scalar/db/storage/cosmos/CosmosOperation.java +++ b/src/main/java/com/scalar/db/storage/cosmos/CosmosOperation.java @@ -42,7 +42,7 @@ public Operation getOperation() { @Nonnull public String getConcatenatedPartitionKey() { - Map keyMap = new HashMap<>(); + Map> keyMap = new HashMap<>(); operation .getPartitionKey() .get() @@ -64,7 +64,7 @@ public PartitionKey getCosmosPartitionKey() { @Nonnull public String getId() { - Map keyMap = new HashMap<>(); + Map> keyMap = new HashMap<>(); operation .getPartitionKey() .get() diff --git a/src/main/java/com/scalar/db/storage/cosmos/ResultImpl.java b/src/main/java/com/scalar/db/storage/cosmos/ResultImpl.java index 2b3cd7c935..261f2c755b 100644 --- a/src/main/java/com/scalar/db/storage/cosmos/ResultImpl.java +++ b/src/main/java/com/scalar/db/storage/cosmos/ResultImpl.java @@ -1,5 +1,7 @@ package com.scalar.db.storage.cosmos; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; @@ -16,11 +18,6 @@ import com.scalar.db.io.TextValue; import com.scalar.db.io.Value; import com.scalar.db.storage.common.metadata.DataType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nonnull; -import javax.annotation.concurrent.Immutable; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; @@ -30,14 +27,16 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; - -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Immutable public class ResultImpl implements Result { private static final Logger LOGGER = LoggerFactory.getLogger(ResultImpl.class); private final CosmosTableMetadata metadata; - private final Map values; + private final Map> values; public ResultImpl(Record record, Selection selection, CosmosTableMetadata metadata) { checkNotNull(record); @@ -57,13 +56,13 @@ public Optional getClusteringKey() { } @Override - public Optional getValue(String name) { + public Optional> getValue(String name) { return Optional.ofNullable(values.get(name)); } @Override @Nonnull - public Map getValues() { + public Map> getValues() { return ImmutableMap.copyOf(values); } @@ -123,15 +122,15 @@ private void add(String name, Object value) { } private Optional getKey(LinkedHashSet names) { - List list = new ArrayList<>(); + List> list = new ArrayList<>(); for (String name : names) { - Value value = values.get(name); + Value value = values.get(name); list.add(value); } return Optional.of(new Key(list)); } - private Value convert(Object recordValue, String name, DataType dataType) + private Value convert(Object recordValue, String name, DataType dataType) throws UnsupportedTypeException { // When recordValue is NULL, the value will be the default value. // It is the same behavior as the datastax C* driver diff --git a/src/main/java/com/scalar/db/storage/cosmos/SelectStatementHandler.java b/src/main/java/com/scalar/db/storage/cosmos/SelectStatementHandler.java index 3fb5c988c8..49a1ed18a4 100644 --- a/src/main/java/com/scalar/db/storage/cosmos/SelectStatementHandler.java +++ b/src/main/java/com/scalar/db/storage/cosmos/SelectStatementHandler.java @@ -120,11 +120,11 @@ private void setStart(SelectConditionStep select, Scan scan) { .ifPresent( k -> { ValueBinder binder = new ValueBinder(); - List start = k.get(); + List> start = k.get(); IntStream.range(0, start.size()) .forEach( i -> { - Value value = start.get(i); + Value value = start.get(i); Field field = DSL.field("r.clusteringKey." + value.getName()); if (i == (start.size() - 1)) { if (scan.getStartInclusive()) { @@ -149,11 +149,11 @@ private void setEnd(SelectConditionStep select, Scan scan) { .ifPresent( k -> { ValueBinder binder = new ValueBinder(); - List end = k.get(); + List> end = k.get(); IntStream.range(0, end.size()) .forEach( i -> { - Value value = end.get(i); + Value value = end.get(i); Field field = DSL.field("r.clusteringKey." + value.getName()); if (i == (end.size() - 1)) { if (scan.getEndInclusive()) { @@ -186,7 +186,7 @@ private void setOrderings( private String makeQueryWithIndex(Operation operation) { SelectWhereStep select = DSL.using(SQLDialect.DEFAULT).selectFrom("Record r"); - Value keyValue = operation.getPartitionKey().get().get(0); + Value keyValue = operation.getPartitionKey().get().get(0); CosmosTableMetadata metadata = metadataManager.getTableMetadata(operation); String fieldName; if (metadata.getClusteringKeyNames().contains(keyValue.getName())) { diff --git a/src/main/java/com/scalar/db/storage/dynamo/DynamoMutation.java b/src/main/java/com/scalar/db/storage/dynamo/DynamoMutation.java index 1f0f1594b4..02a3f4337f 100644 --- a/src/main/java/com/scalar/db/storage/dynamo/DynamoMutation.java +++ b/src/main/java/com/scalar/db/storage/dynamo/DynamoMutation.java @@ -84,12 +84,12 @@ private String getUpdateExpression(boolean withKey) { int i = 0; if (withKey) { - for (Value key : put.getPartitionKey().get()) { + for (Value key : put.getPartitionKey().get()) { expressions.add(COLUMN_NAME_ALIAS + i + " = " + VALUE_ALIAS + i); i++; } if (put.getClusteringKey().isPresent()) { - for (Value key : put.getClusteringKey().get().get()) { + for (Value key : put.getClusteringKey().get().get()) { expressions.add(COLUMN_NAME_ALIAS + i + " = " + VALUE_ALIAS + i); i++; } @@ -120,12 +120,12 @@ private Map getColumnMap(boolean withKey) { int i = 0; if (withKey) { - for (Value key : put.getPartitionKey().get()) { + for (Value key : put.getPartitionKey().get()) { columnMap.put(COLUMN_NAME_ALIAS + i, key.getName()); i++; } if (put.getClusteringKey().isPresent()) { - for (Value key : put.getClusteringKey().get().get()) { + for (Value key : put.getClusteringKey().get().get()) { columnMap.put(COLUMN_NAME_ALIAS + i, key.getName()); i++; } diff --git a/src/main/java/com/scalar/db/storage/dynamo/DynamoOperation.java b/src/main/java/com/scalar/db/storage/dynamo/DynamoOperation.java index a7f00b1ac1..c23fe3d7e8 100644 --- a/src/main/java/com/scalar/db/storage/dynamo/DynamoOperation.java +++ b/src/main/java/com/scalar/db/storage/dynamo/DynamoOperation.java @@ -85,7 +85,7 @@ public Map getKeyMap() { } String getConcatenatedPartitionKey() { - Map keyMap = new HashMap<>(); + Map> keyMap = new HashMap<>(); operation .getPartitionKey() .get() @@ -105,7 +105,7 @@ Optional getConcatenatedClusteringKey() { return Optional.empty(); } - Map keyMap = new HashMap<>(); + Map> keyMap = new HashMap<>(); operation .getClusteringKey() .ifPresent( @@ -123,7 +123,7 @@ Optional getConcatenatedClusteringKey() { return Optional.of(visitor.build()); } - Map toMap(Collection values) { + Map toMap(Collection> values) { MapVisitor visitor = new MapVisitor(); values.forEach(v -> v.accept(visitor)); diff --git a/src/main/java/com/scalar/db/storage/dynamo/ResultImpl.java b/src/main/java/com/scalar/db/storage/dynamo/ResultImpl.java index 7ab4bea665..41d18df60e 100644 --- a/src/main/java/com/scalar/db/storage/dynamo/ResultImpl.java +++ b/src/main/java/com/scalar/db/storage/dynamo/ResultImpl.java @@ -1,5 +1,7 @@ package com.scalar.db.storage.dynamo; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; @@ -16,12 +18,6 @@ import com.scalar.db.io.TextValue; import com.scalar.db.io.Value; import com.scalar.db.storage.common.metadata.DataType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import software.amazon.awssdk.services.dynamodb.model.AttributeValue; - -import javax.annotation.Nonnull; -import javax.annotation.concurrent.Immutable; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashSet; @@ -29,15 +25,18 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; - -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.services.dynamodb.model.AttributeValue; @Immutable public class ResultImpl implements Result { private static final Logger LOGGER = LoggerFactory.getLogger(ResultImpl.class); private final Selection selection; private final DynamoTableMetadata metadata; - private final Map values; + private final Map> values; public ResultImpl( Map item, Selection selection, DynamoTableMetadata metadata) { @@ -59,13 +58,13 @@ public Optional getClusteringKey() { } @Override - public Optional getValue(String name) { + public Optional> getValue(String name) { return Optional.ofNullable(values.get(name)); } @Override @Nonnull - public Map getValues() { + public Map> getValues() { return ImmutableMap.copyOf(values); } @@ -121,15 +120,15 @@ private void add(String name, AttributeValue itemValue) { } private Optional getKey(LinkedHashSet names) { - List list = new ArrayList<>(); + List> list = new ArrayList<>(); for (String name : names) { - Value value = values.get(name); + Value value = values.get(name); list.add(value); } return Optional.of(new Key(list)); } - private Value convert(AttributeValue itemValue, String name, DataType dataType) + private Value convert(AttributeValue itemValue, String name, DataType dataType) throws UnsupportedTypeException { // When itemValue is NULL, the value will be the default value. // It is the same behavior as the datastax C* driver diff --git a/src/main/java/com/scalar/db/storage/dynamo/SelectStatementHandler.java b/src/main/java/com/scalar/db/storage/dynamo/SelectStatementHandler.java index 8997fe822a..91ae224d1a 100644 --- a/src/main/java/com/scalar/db/storage/dynamo/SelectStatementHandler.java +++ b/src/main/java/com/scalar/db/storage/dynamo/SelectStatementHandler.java @@ -95,7 +95,7 @@ private GetItemResponse executeGet(Get get) { private QueryResponse executeQueryWithIndex(Selection selection) { DynamoOperation dynamoOperation = new DynamoOperation(selection, metadataManager); - Value keyValue = selection.getPartitionKey().get().get(0); + Value keyValue = selection.getPartitionKey().get().get(0); String column = keyValue.getName(); String indexTable = dynamoOperation.getGlobalIndexName(column); QueryRequest.Builder builder = @@ -163,12 +163,12 @@ private QueryResponse executeQuery(Scan scan) { private Optional getIndexName(Scan scan) { if (scan.getStartClusteringKey().isPresent()) { - List start = scan.getStartClusteringKey().get().get(); + List> start = scan.getStartClusteringKey().get().get(); return Optional.of(start.get(start.size() - 1).getName()); } if (scan.getEndClusteringKey().isPresent()) { - List end = scan.getEndClusteringKey().get().get(); + List> end = scan.getEndClusteringKey().get().get(); return Optional.of(end.get(end.size() - 1).getName()); } @@ -221,8 +221,8 @@ private boolean setRangeCondition(Scan scan, List conditions) { return false; } - List start = scan.getStartClusteringKey().get().get(); - List end = scan.getEndClusteringKey().get().get(); + List> start = scan.getStartClusteringKey().get().get(); + List> end = scan.getEndClusteringKey().get().get(); String startKeyName = start.get(start.size() - 1).getName(); String endKeyName = end.get(end.size() - 1).getName(); @@ -243,9 +243,9 @@ private void setStartCondition( scan.getStartClusteringKey() .ifPresent( k -> { - List start = k.get(); + List> start = k.get(); for (int i = 0; i < start.size(); i++) { - Value value = start.get(i); + Value value = start.get(i); List elements = new ArrayList<>(); elements.add(value.getName()); if (i < start.size() - 1) { @@ -271,9 +271,9 @@ private void setEndCondition( scan.getEndClusteringKey() .ifPresent( k -> { - List end = k.get(); + List> end = k.get(); for (int i = 0; i < end.size(); i++) { - Value value = end.get(i); + Value value = end.get(i); List elements = new ArrayList<>(); elements.add(value.getName()); if (i < end.size() - 1) { @@ -295,8 +295,8 @@ private void setEndCondition( private Map getRangeBindMap(Scan scan) { ValueBinder binder = new ValueBinder(DynamoOperation.RANGE_KEY_ALIAS); - List start = scan.getStartClusteringKey().get().get(); - List end = scan.getEndClusteringKey().get().get(); + List> start = scan.getStartClusteringKey().get().get(); + List> end = scan.getEndClusteringKey().get().get(); start.get(start.size() - 1).accept(binder); end.get(end.size() - 1).accept(binder); @@ -308,7 +308,7 @@ private Map getStartBindMap(Scan scan, boolean isRangeEn scan.getStartClusteringKey() .ifPresent( k -> { - List start = k.get(); + List> start = k.get(); int size = isRangeEnabled ? start.size() - 1 : start.size(); IntStream.range(0, size) .forEach( @@ -325,7 +325,7 @@ private Map getEndBindMap(Scan scan, boolean isRangeEnab scan.getEndClusteringKey() .ifPresent( k -> { - List end = k.get(); + List> end = k.get(); int size = isRangeEnabled ? end.size() - 1 : end.size(); IntStream.range(0, size) .forEach( diff --git a/src/main/java/com/scalar/db/storage/jdbc/ResultImpl.java b/src/main/java/com/scalar/db/storage/jdbc/ResultImpl.java index 6136bc32de..5272479f35 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/ResultImpl.java +++ b/src/main/java/com/scalar/db/storage/jdbc/ResultImpl.java @@ -13,8 +13,6 @@ import com.scalar.db.io.Value; import com.scalar.db.storage.common.metadata.DataType; import com.scalar.db.storage.jdbc.metadata.JdbcTableMetadata; - -import javax.annotation.concurrent.Immutable; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; @@ -25,12 +23,13 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import javax.annotation.concurrent.Immutable; @Immutable public class ResultImpl implements Result { private final JdbcTableMetadata tableMetadata; - private final Map values; + private final Map> values; public ResultImpl(JdbcTableMetadata tableMetadata, List projections, ResultSet resultSet) throws SQLException { @@ -48,7 +47,7 @@ public ResultImpl(JdbcTableMetadata tableMetadata, List projections, Res } } - private Value getValue(JdbcTableMetadata tableMetadata, String name, ResultSet resultSet) + private Value getValue(JdbcTableMetadata tableMetadata, String name, ResultSet resultSet) throws SQLException { DataType dataType = tableMetadata.getColumnDataType(name); switch (dataType) { @@ -82,9 +81,9 @@ public Optional getClusteringKey() { } private Optional getKey(LinkedHashSet names) { - List list = new ArrayList<>(); + List> list = new ArrayList<>(); for (String name : names) { - Value value = values.get(name); + Value value = values.get(name); if (value == null) { return Optional.empty(); } @@ -94,12 +93,12 @@ private Optional getKey(LinkedHashSet names) { } @Override - public Optional getValue(String name) { + public Optional> getValue(String name) { return Optional.ofNullable(values.get(name)); } @Override - public Map getValues() { + public Map> getValues() { return Collections.unmodifiableMap(values); } diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/DeleteQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/DeleteQuery.java index 7a1be6f6d9..56e1733095 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/DeleteQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/DeleteQuery.java @@ -1,10 +1,13 @@ package com.scalar.db.storage.jdbc.query; +import static com.scalar.db.storage.jdbc.query.QueryUtils.enclose; +import static com.scalar.db.storage.jdbc.query.QueryUtils.enclosedFullTableName; +import static com.scalar.db.storage.jdbc.query.QueryUtils.getOperatorString; + import com.scalar.db.api.ConditionalExpression; import com.scalar.db.io.Key; import com.scalar.db.io.Value; import com.scalar.db.storage.jdbc.RdbEngine; - import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; @@ -12,10 +15,6 @@ import java.util.List; import java.util.Optional; -import static com.scalar.db.storage.jdbc.query.QueryUtils.enclose; -import static com.scalar.db.storage.jdbc.query.QueryUtils.enclosedFullTableName; -import static com.scalar.db.storage.jdbc.query.QueryUtils.getOperatorString; - public class DeleteQuery extends AbstractQuery { private final RdbEngine rdbEngine; @@ -57,13 +56,13 @@ private String conditionSqlString() { protected void bind(PreparedStatement preparedStatement) throws SQLException { PreparedStatementBinder binder = new PreparedStatementBinder(preparedStatement); - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/InsertOnConflictDoUpdateQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/InsertOnConflictDoUpdateQuery.java index 49dfa59a83..3ac180623e 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/InsertOnConflictDoUpdateQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/InsertOnConflictDoUpdateQuery.java @@ -21,7 +21,7 @@ public class InsertOnConflictDoUpdateQuery extends AbstractQuery implements Upse private final String table; private final Key partitionKey; private final Optional clusteringKey; - private final Map values; + private final Map> values; InsertOnConflictDoUpdateQuery(Builder builder) { rdbEngine = builder.rdbEngine; @@ -80,25 +80,25 @@ private String makeOnConflictDoUpdateSqlString() { protected void bind(PreparedStatement preparedStatement) throws SQLException { PreparedStatementBinder binder = new PreparedStatementBinder(preparedStatement); - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } } - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } // For ON DUPLICATE KEY UPDATE - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/InsertOnDuplicateKeyUpdateQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/InsertOnDuplicateKeyUpdateQuery.java index 4a0f242dfc..8d9989e500 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/InsertOnDuplicateKeyUpdateQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/InsertOnDuplicateKeyUpdateQuery.java @@ -21,7 +21,7 @@ public class InsertOnDuplicateKeyUpdateQuery extends AbstractQuery implements Up private final String table; private final Key partitionKey; private final Optional clusteringKey; - private final Map values; + private final Map> values; InsertOnDuplicateKeyUpdateQuery(Builder builder) { rdbEngine = builder.rdbEngine; @@ -71,25 +71,25 @@ private String makeOnDuplicateKeyUpdateSqlString() { protected void bind(PreparedStatement preparedStatement) throws SQLException { PreparedStatementBinder binder = new PreparedStatementBinder(preparedStatement); - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } } - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } // For ON DUPLICATE KEY UPDATE - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/InsertQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/InsertQuery.java index 652ea9bc3f..cb673558fd 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/InsertQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/InsertQuery.java @@ -1,9 +1,11 @@ package com.scalar.db.storage.jdbc.query; +import static com.scalar.db.storage.jdbc.query.QueryUtils.enclose; +import static com.scalar.db.storage.jdbc.query.QueryUtils.enclosedFullTableName; + import com.scalar.db.io.Key; import com.scalar.db.io.Value; import com.scalar.db.storage.jdbc.RdbEngine; - import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; @@ -12,9 +14,6 @@ import java.util.Optional; import java.util.stream.Collectors; -import static com.scalar.db.storage.jdbc.query.QueryUtils.enclose; -import static com.scalar.db.storage.jdbc.query.QueryUtils.enclosedFullTableName; - public class InsertQuery extends AbstractQuery { private final RdbEngine rdbEngine; @@ -22,7 +21,7 @@ public class InsertQuery extends AbstractQuery { private final String table; private final Key partitionKey; private final Optional clusteringKey; - private final Map values; + private final Map> values; private InsertQuery(Builder builder) { rdbEngine = builder.rdbEngine; @@ -56,19 +55,19 @@ private String makeValuesSqlString() { protected void bind(PreparedStatement preparedStatement) throws SQLException { PreparedStatementBinder binder = new PreparedStatementBinder(preparedStatement); - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } } - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } @@ -80,7 +79,7 @@ public static class Builder { private final String table; private Key partitionKey; private Optional clusteringKey; - private Map values; + private Map> values; Builder(RdbEngine rdbEngine, String schema, String table) { this.rdbEngine = rdbEngine; @@ -89,7 +88,7 @@ public static class Builder { } public Builder values( - Key partitionKey, Optional clusteringKey, Map values) { + Key partitionKey, Optional clusteringKey, Map> values) { this.partitionKey = partitionKey; this.clusteringKey = clusteringKey; this.values = values; diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/MergeIntoQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/MergeIntoQuery.java index 2365418fcd..638146986f 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/MergeIntoQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/MergeIntoQuery.java @@ -21,7 +21,7 @@ public class MergeIntoQuery extends AbstractQuery implements UpsertQuery { private final String table; private final Key partitionKey; private final Optional clusteringKey; - private final Map values; + private final Map> values; public MergeIntoQuery(Builder builder) { rdbEngine = builder.rdbEngine; @@ -89,35 +89,35 @@ protected void bind(PreparedStatement preparedStatement) throws SQLException { PreparedStatementBinder binder = new PreparedStatementBinder(preparedStatement); // For the USING SELECT statement - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } } // For the UPDATE statement - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } // For the INSERT statement - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } } - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/MergeQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/MergeQuery.java index 43db5b444e..f405655200 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/MergeQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/MergeQuery.java @@ -21,7 +21,7 @@ public class MergeQuery extends AbstractQuery implements UpsertQuery { private final String table; private final Key partitionKey; private final Optional clusteringKey; - private final Map values; + private final Map> values; public MergeQuery(Builder builder) { rdbEngine = builder.rdbEngine; @@ -90,35 +90,35 @@ protected void bind(PreparedStatement preparedStatement) throws SQLException { PreparedStatementBinder binder = new PreparedStatementBinder(preparedStatement); // For the USING SELECT statement - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } } // For the UPDATE statement - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } // For the INSERT statement - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } } - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/SelectQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/SelectQuery.java index 051cd7f6c8..49df7cd6ce 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/SelectQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/SelectQuery.java @@ -27,9 +27,9 @@ class Builder { Key partitionKey; Optional clusteringKey = Optional.empty(); Optional commonClusteringKey = Optional.empty(); - Optional startValue = Optional.empty(); + Optional> startValue = Optional.empty(); boolean startInclusive; - Optional endValue = Optional.empty(); + Optional> endValue = Optional.empty(); boolean endInclusive; List orderings = Collections.emptyList(); private int limit; diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/SimpleSelectQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/SimpleSelectQuery.java index 84f35230eb..be2073413d 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/SimpleSelectQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/SimpleSelectQuery.java @@ -28,9 +28,9 @@ public class SimpleSelectQuery extends AbstractQuery implements SelectQuery { private final Key partitionKey; private final Optional clusteringKey; private final Optional commonClusteringKey; - private final Optional startValue; + private final Optional> startValue; private final boolean startInclusive; - private final Optional endValue; + private final Optional> endValue; private final boolean endInclusive; private final List orderings; private final boolean isRangeQuery; @@ -124,20 +124,20 @@ private String orderBySqlString() { protected void bind(PreparedStatement preparedStatement) throws SQLException { PreparedStatementBinder binder = new PreparedStatementBinder(preparedStatement); - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } } if (commonClusteringKey.isPresent()) { - for (Value value : commonClusteringKey.get()) { + for (Value value : commonClusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/UpdateQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/UpdateQuery.java index 054a2c84f2..1dc74f07b0 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/UpdateQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/UpdateQuery.java @@ -1,10 +1,13 @@ package com.scalar.db.storage.jdbc.query; +import static com.scalar.db.storage.jdbc.query.QueryUtils.enclose; +import static com.scalar.db.storage.jdbc.query.QueryUtils.enclosedFullTableName; +import static com.scalar.db.storage.jdbc.query.QueryUtils.getOperatorString; + import com.scalar.db.api.ConditionalExpression; import com.scalar.db.io.Key; import com.scalar.db.io.Value; import com.scalar.db.storage.jdbc.RdbEngine; - import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; @@ -14,10 +17,6 @@ import java.util.Optional; import java.util.stream.Collectors; -import static com.scalar.db.storage.jdbc.query.QueryUtils.enclose; -import static com.scalar.db.storage.jdbc.query.QueryUtils.enclosedFullTableName; -import static com.scalar.db.storage.jdbc.query.QueryUtils.getOperatorString; - public class UpdateQuery extends AbstractQuery { private final RdbEngine rdbEngine; @@ -25,7 +24,7 @@ public class UpdateQuery extends AbstractQuery { private final String table; private final Key partitionKey; private final Optional clusteringKey; - private final Map values; + private final Map> values; private final List otherConditions; private UpdateQuery(Builder builder) { @@ -70,18 +69,18 @@ private String makeConditionSqlString() { protected void bind(PreparedStatement preparedStatement) throws SQLException { PreparedStatementBinder binder = new PreparedStatementBinder(preparedStatement); - for (Value value : values.values()) { + for (Value value : values.values()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } - for (Value value : partitionKey) { + for (Value value : partitionKey) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } if (clusteringKey.isPresent()) { - for (Value value : clusteringKey.get()) { + for (Value value : clusteringKey.get()) { value.accept(binder); binder.throwSQLExceptionIfOccurred(); } @@ -100,7 +99,7 @@ public static class Builder { List otherConditions; private Key partitionKey; private Optional clusteringKey; - private Map values; + private Map> values; Builder(RdbEngine rdbEngine, String schema, String table) { this.rdbEngine = rdbEngine; @@ -108,7 +107,7 @@ public static class Builder { this.table = table; } - public Builder set(Map values) { + public Builder set(Map> values) { this.values = values; return this; } diff --git a/src/main/java/com/scalar/db/storage/jdbc/query/UpsertQuery.java b/src/main/java/com/scalar/db/storage/jdbc/query/UpsertQuery.java index 6f1b9e1060..6217ce6486 100644 --- a/src/main/java/com/scalar/db/storage/jdbc/query/UpsertQuery.java +++ b/src/main/java/com/scalar/db/storage/jdbc/query/UpsertQuery.java @@ -15,7 +15,7 @@ class Builder { final String table; Key partitionKey; Optional clusteringKey; - Map values; + Map> values; Builder(RdbEngine rdbEngine, String schema, String table) { this.rdbEngine = rdbEngine; @@ -24,7 +24,7 @@ class Builder { } public Builder values( - Key partitionKey, Optional clusteringKey, Map values) { + Key partitionKey, Optional clusteringKey, Map> values) { this.partitionKey = partitionKey; this.clusteringKey = clusteringKey; this.values = values; diff --git a/src/main/java/com/scalar/db/transaction/consensuscommit/Attribute.java b/src/main/java/com/scalar/db/transaction/consensuscommit/Attribute.java index f74fdc2196..3b0acb02da 100644 --- a/src/main/java/com/scalar/db/transaction/consensuscommit/Attribute.java +++ b/src/main/java/com/scalar/db/transaction/consensuscommit/Attribute.java @@ -4,7 +4,6 @@ import com.scalar.db.io.BigIntValue; import com.scalar.db.io.IntValue; import com.scalar.db.io.TextValue; -import com.scalar.db.io.Value; /** */ public final class Attribute { @@ -22,51 +21,51 @@ public final class Attribute { public static final String BEFORE_PREPARED_AT = BEFORE_PREFIX + PREPARED_AT; public static final String BEFORE_COMMITTED_AT = BEFORE_PREFIX + COMMITTED_AT; - public static Value toIdValue(String transactionId) { + public static TextValue toIdValue(String transactionId) { return new TextValue(Attribute.ID, transactionId); } - public static Value toStateValue(TransactionState state) { + public static IntValue toStateValue(TransactionState state) { return new IntValue(Attribute.STATE, state.get()); } - public static Value toVersionValue(int version) { + public static IntValue toVersionValue(int version) { return new IntValue(Attribute.VERSION, version); } - public static Value toPreparedAtValue(long preparedAt) { + public static BigIntValue toPreparedAtValue(long preparedAt) { return new BigIntValue(Attribute.PREPARED_AT, preparedAt); } - public static Value toCommittedAtValue(long committedAt) { + public static BigIntValue toCommittedAtValue(long committedAt) { return new BigIntValue(Attribute.COMMITTED_AT, committedAt); } - public static Value toCreatedAtValue(long createdAt) { + public static BigIntValue toCreatedAtValue(long createdAt) { return new BigIntValue(Attribute.CREATED_AT, createdAt); } - public static Value toMetadataValue(String metadata) { + public static TextValue toMetadataValue(String metadata) { return new TextValue(Attribute.METADATA, metadata); } - public static Value toBeforeIdValue(String transactionId) { + public static TextValue toBeforeIdValue(String transactionId) { return new TextValue(Attribute.BEFORE_ID, transactionId); } - public static Value toBeforeStateValue(TransactionState state) { + public static IntValue toBeforeStateValue(TransactionState state) { return new IntValue(Attribute.BEFORE_STATE, state.get()); } - public static Value toBeforeVersionValue(int version) { + public static IntValue toBeforeVersionValue(int version) { return new IntValue(Attribute.BEFORE_VERSION, version); } - public static Value toBeforePreparedAtValue(long preparedAt) { + public static BigIntValue toBeforePreparedAtValue(long preparedAt) { return new BigIntValue(Attribute.BEFORE_PREPARED_AT, preparedAt); } - public static Value toBeforeCommittedAtValue(long committedAt) { + public static BigIntValue toBeforeCommittedAtValue(long committedAt) { return new BigIntValue(Attribute.BEFORE_COMMITTED_AT, committedAt); } } diff --git a/src/main/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposer.java b/src/main/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposer.java index a983d40ffd..758da90f76 100644 --- a/src/main/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposer.java +++ b/src/main/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposer.java @@ -57,7 +57,7 @@ private void add(Put base, TransactionResult result) { .forTable(base.forTable().get()) .withConsistency(Consistency.LINEARIZABLE); - List values = new ArrayList<>(); + List> values = new ArrayList<>(); values.add(Attribute.toIdValue(id)); values.add(Attribute.toStateValue(TransactionState.PREPARED)); values.add(Attribute.toPreparedAtValue(current)); @@ -96,7 +96,7 @@ private void add(Delete base, TransactionResult result) { .forTable(base.forTable().get()) .withConsistency(Consistency.LINEARIZABLE); - List values = new ArrayList<>(); + List> values = new ArrayList<>(); values.add(Attribute.toIdValue(id)); values.add(Attribute.toStateValue(TransactionState.DELETED)); values.add(Attribute.toPreparedAtValue(current)); @@ -123,7 +123,7 @@ private void add(Get base) { .forTable(base.forTable().get()) .withConsistency(Consistency.LINEARIZABLE); - List values = new ArrayList<>(); + List> values = new ArrayList<>(); values.add(Attribute.toIdValue(id)); values.add(Attribute.toStateValue(TransactionState.DELETED)); values.add(Attribute.toPreparedAtValue(current)); @@ -136,11 +136,11 @@ private void add(Get base) { mutations.add(put); } - private List createBeforeValues(Mutation base, TransactionResult result) { + private List> createBeforeValues(Mutation base, TransactionResult result) { Key partitionKey = base.getPartitionKey(); Optional clusteringKey = getClusteringKey(base, result); - List values = new ArrayList<>(); + List> values = new ArrayList<>(); result .getValues() .values() @@ -153,7 +153,7 @@ private List createBeforeValues(Mutation base, TransactionResult result) return values; } - private boolean isBeforeRequired(Value value, Key primary, Optional clustering) { + private boolean isBeforeRequired(Value value, Key primary, Optional clustering) { if (!value.getName().startsWith(Attribute.BEFORE_PREFIX) && !isValueInKeys(value, primary, clustering)) { return true; @@ -161,8 +161,8 @@ private boolean isBeforeRequired(Value value, Key primary, Optional cluster return false; } - private boolean isValueInKeys(Value value, Key primary, Optional clustering) { - for (Value v : primary) { + private boolean isValueInKeys(Value value, Key primary, Optional clustering) { + for (Value v : primary) { if (v.equals(value)) { return true; } @@ -172,7 +172,7 @@ private boolean isValueInKeys(Value value, Key primary, Optional clustering return false; } - for (Value v : clustering.get()) { + for (Value v : clustering.get()) { if (v.equals(value)) { return true; } diff --git a/src/main/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposer.java b/src/main/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposer.java index 2a720b7d0c..5de879492b 100644 --- a/src/main/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposer.java +++ b/src/main/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposer.java @@ -90,7 +90,7 @@ private Put composePut(Operation base, TransactionResult result) { && !result.getState().equals(TransactionState.DELETED)) { throw new TransactionRuntimeException("rollback is toward non-prepared record"); } - Map map = new HashMap<>(); + Map> map = new HashMap<>(); result .getValues() .forEach( diff --git a/src/main/java/com/scalar/db/transaction/consensuscommit/TransactionResult.java b/src/main/java/com/scalar/db/transaction/consensuscommit/TransactionResult.java index 2f8348fa37..29d8671f9a 100644 --- a/src/main/java/com/scalar/db/transaction/consensuscommit/TransactionResult.java +++ b/src/main/java/com/scalar/db/transaction/consensuscommit/TransactionResult.java @@ -21,7 +21,7 @@ @Immutable public class TransactionResult implements Result { private final Result result; - private final Map values; + private final Map> values; public TransactionResult(Result result) { // assume that all the values are projected to the result @@ -46,13 +46,13 @@ public Optional getClusteringKey() { } @Override - public Optional getValue(String name) { + public Optional> getValue(String name) { return Optional.ofNullable(values.get(name)); } @Override @Nonnull - public ImmutableMap getValues() { + public ImmutableMap> getValues() { return ImmutableMap.copyOf(values); } diff --git a/src/test/java/com/scalar/db/api/DeleteTest.java b/src/test/java/com/scalar/db/api/DeleteTest.java index 24a22e9b34..7d5777e5be 100644 --- a/src/test/java/com/scalar/db/api/DeleteTest.java +++ b/src/test/java/com/scalar/db/api/DeleteTest.java @@ -33,7 +33,7 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { Key actual = del.getPartitionKey(); // Assert - assertThat((Iterable) expected).isEqualTo(actual); + assertThat((Iterable>) expected).isEqualTo(actual); } @Test diff --git a/src/test/java/com/scalar/db/api/GetTest.java b/src/test/java/com/scalar/db/api/GetTest.java index 5e35cb280e..7d028b826f 100644 --- a/src/test/java/com/scalar/db/api/GetTest.java +++ b/src/test/java/com/scalar/db/api/GetTest.java @@ -49,7 +49,7 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { Key actual = get.getPartitionKey(); // Assert - assertThat((Iterable) expected).isEqualTo(actual); + assertThat((Iterable>) expected).isEqualTo(actual); } @Test diff --git a/src/test/java/com/scalar/db/api/PutTest.java b/src/test/java/com/scalar/db/api/PutTest.java index 29b99e88bd..46f4c53b60 100644 --- a/src/test/java/com/scalar/db/api/PutTest.java +++ b/src/test/java/com/scalar/db/api/PutTest.java @@ -39,7 +39,7 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { Key actual = put.getPartitionKey(); // Assert - assertThat((Iterable) expected).isEqualTo(actual); + assertThat((Iterable>) expected).isEqualTo(actual); } @Test @@ -108,7 +108,7 @@ public void getValues_TryToModifyReturned_ShouldThrowException() { put.withValue(value1).withValue(value2); // Act Assert - Map values = put.getValues(); + Map> values = put.getValues(); assertThatThrownBy( () -> { values.put(ANY_NAME_3, new TextValue(ANY_NAME_3, ANY_TEXT_3)); diff --git a/src/test/java/com/scalar/db/api/ScanTest.java b/src/test/java/com/scalar/db/api/ScanTest.java index 9627e37156..ecbce2247f 100644 --- a/src/test/java/com/scalar/db/api/ScanTest.java +++ b/src/test/java/com/scalar/db/api/ScanTest.java @@ -65,7 +65,7 @@ public void constructorAndSetters_AllSet_ShouldGetWhatsSet() { .withLimit(100); // Assert - assertThat((Iterable) scan.getPartitionKey()).isEqualTo(partitionKey); + assertThat((Iterable>) scan.getPartitionKey()).isEqualTo(partitionKey); assertThat(scan.getStartClusteringKey()).isEqualTo(Optional.of(startClusteringKey)); assertThat(scan.getEndClusteringKey()).isEqualTo(Optional.of(endClusteringKey)); assertThat(scan.getProjections()).isEqualTo(Arrays.asList(ANY_NAME_1)); diff --git a/src/test/java/com/scalar/db/io/KeyTest.java b/src/test/java/com/scalar/db/io/KeyTest.java index d2dbbdc060..61a05ec8b8 100644 --- a/src/test/java/com/scalar/db/io/KeyTest.java +++ b/src/test/java/com/scalar/db/io/KeyTest.java @@ -28,7 +28,7 @@ public void get_ProperKeysGivenInConstructor_ShouldReturnWhatsSet() { Key key = new Key(key1, key2); // Act - List values = key.get(); + List> values = key.get(); // Assert assertThat(values).isEqualTo(Arrays.asList(key1, key2)); @@ -42,7 +42,7 @@ public void get_TryToModifyReturned_ShouldThrowException() { Key key = new Key(key1, key2); // Act Assert - List values = key.get(); + List> values = key.get(); assertThatThrownBy( () -> { values.add(new TextValue(ANY_NAME_3, ANY_TEXT_3)); @@ -205,7 +205,7 @@ public void constructor_NullGiven_ShouldThrowNullPointerException() { // Act Assert assertThatThrownBy( () -> { - new Key((List) null); + new Key((List>) null); }) .isInstanceOf(NullPointerException.class); } diff --git a/src/test/java/com/scalar/db/storage/cassandra/ResultImplTest.java b/src/test/java/com/scalar/db/storage/cassandra/ResultImplTest.java index 01f1844ffb..b91650ee42 100644 --- a/src/test/java/com/scalar/db/storage/cassandra/ResultImplTest.java +++ b/src/test/java/com/scalar/db/storage/cassandra/ResultImplTest.java @@ -1,5 +1,12 @@ package com.scalar.db.storage.cassandra; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import com.datastax.driver.core.ColumnMetadata; import com.datastax.driver.core.DataType; import com.datastax.driver.core.Row; @@ -7,11 +14,6 @@ import com.scalar.db.io.Key; import com.scalar.db.io.TextValue; import com.scalar.db.io.Value; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; @@ -21,13 +23,10 @@ import java.util.List; import java.util.Map; import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; /** */ public class ResultImplTest { @@ -69,7 +68,7 @@ public void setUp() throws Exception { .thenReturn((ByteBuffer) ByteBuffer.allocate(64).put("string".getBytes()).flip()); } - private List prepareValues() { + private List> prepareValues() { return Arrays.asList(new IntValue("k1", 1), new TextValue("k2", "2")); } @@ -85,7 +84,7 @@ public void getValue_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() { spy.interpret(row); // Act - Optional actual = spy.getValue(expectedText); + Optional> actual = spy.getValue(expectedText); // Assert assertThat(actual).isEqualTo(Optional.of(new IntValue(expectedText, expectedInt))); @@ -103,7 +102,7 @@ public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() { spy.interpret(row); // Act - Map actual = spy.getValues(); + Map> actual = spy.getValues(); // Assert assertThat(actual.get(expectedText)).isEqualTo(new IntValue(expectedText, expectedInt)); @@ -130,7 +129,7 @@ public void getValues_TryToModifyReturned_ShouldThrowException() { ResultImpl spy = spy(new ResultImpl(new ArrayList<>(), null)); doReturn(definitions.get()).when(spy).getColumnDefinitions(row); spy.interpret(row); - Map values = spy.getValues(); + Map> values = spy.getValues(); // Act Assert assertThatThrownBy( diff --git a/src/test/java/com/scalar/db/storage/common/checker/OperationCheckerTest.java b/src/test/java/com/scalar/db/storage/common/checker/OperationCheckerTest.java index 4f3edb329a..d933649832 100644 --- a/src/test/java/com/scalar/db/storage/common/checker/OperationCheckerTest.java +++ b/src/test/java/com/scalar/db/storage/common/checker/OperationCheckerTest.java @@ -529,7 +529,7 @@ public void whenCheckingPutOperationWithAllValidArguments_shouldNotThrowAnyExcep // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - List values = + List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = new PutIfNotExists(); @@ -545,7 +545,7 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - List values = + List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = null; @@ -562,7 +562,7 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue("c3", "val1")); Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - List values = + List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = new PutIfExists(); @@ -580,7 +580,7 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue("c3", "val1")); - List values = + List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = new PutIfExists(); @@ -598,7 +598,7 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); Key clusteringKey = null; - List values = + List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = new PutIfNotExists(); @@ -615,7 +615,7 @@ public void whenCheckingPutOperationWithInvalidValues_shouldThrowIllegalArgument // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - List values = + List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue("v4", true)); MutationCondition condition = new PutIfExists(); @@ -632,7 +632,7 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - List values = + List> values = Arrays.asList( new TextValue(COL1, "1"), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = new PutIfNotExists(); @@ -650,7 +650,7 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - List values = + List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = @@ -670,7 +670,7 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - List values = + List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = new DeleteIfExists(); @@ -687,7 +687,7 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu // Arrange Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - List values = + List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = new DeleteIf(); diff --git a/src/test/java/com/scalar/db/storage/cosmos/ResultImplTest.java b/src/test/java/com/scalar/db/storage/cosmos/ResultImplTest.java index b9a42e0454..f3617a56fe 100644 --- a/src/test/java/com/scalar/db/storage/cosmos/ResultImplTest.java +++ b/src/test/java/com/scalar/db/storage/cosmos/ResultImplTest.java @@ -1,5 +1,11 @@ package com.scalar.db.storage.cosmos; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + import com.google.common.collect.ImmutableMap; import com.scalar.db.api.Get; import com.scalar.db.io.BigIntValue; @@ -11,21 +17,14 @@ import com.scalar.db.io.Key; import com.scalar.db.io.TextValue; import com.scalar.db.io.Value; -import org.junit.Before; -import org.junit.Test; - import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Base64; import java.util.Collections; import java.util.Map; import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import org.junit.Before; +import org.junit.Test; public class ResultImplTest { private static final String ANY_ID_1 = "id1"; @@ -96,7 +95,7 @@ public void getValue_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() { ResultImpl result = new ResultImpl(record, get, metadata); // Act - Optional actual = result.getValue(ANY_NAME_1); + Optional> actual = result.getValue(ANY_NAME_1); // Assert assertThat(actual).isEqualTo(Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1))); @@ -108,7 +107,7 @@ public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() { ResultImpl result = new ResultImpl(record, get, metadata); // Act - Map actual = result.getValues(); + Map> actual = result.getValues(); // Assert assertThat(actual.get(ANY_NAME_1)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1)); @@ -129,7 +128,7 @@ public void getValues_NoValuesGivenInConstructor_ShouldReturnDefaultValueSet() { ResultImpl result = new ResultImpl(emptyRecord, get, metadata); // Act - Map actual = result.getValues(); + Map> actual = result.getValues(); // Assert assertThat(actual.get(ANY_COLUMN_NAME_1)).isEqualTo(new BooleanValue(ANY_COLUMN_NAME_1, false)); @@ -160,7 +159,7 @@ public void getValue_GetValueCalledBefore_ShouldNotLoadAgain() { public void getValues_TryToModifyReturned_ShouldThrowException() { // Arrange ResultImpl result = new ResultImpl(record, get, metadata); - Map values = result.getValues(); + Map> values = result.getValues(); // Act Assert assertThatThrownBy( @@ -178,7 +177,7 @@ public void getValues_GetWithProjectionsGiven_ShouldReturnWhatsSet() { ResultImpl result = new ResultImpl(record, getWithProjections, metadata); // Act - Map actual = result.getValues(); + Map> actual = result.getValues(); // Assert assertThat(actual.size()).isEqualTo(4); diff --git a/src/test/java/com/scalar/db/storage/dynamo/ResultImplTest.java b/src/test/java/com/scalar/db/storage/dynamo/ResultImplTest.java index 3b2d1abcf3..e6165c0006 100644 --- a/src/test/java/com/scalar/db/storage/dynamo/ResultImplTest.java +++ b/src/test/java/com/scalar/db/storage/dynamo/ResultImplTest.java @@ -1,5 +1,11 @@ package com.scalar.db.storage.dynamo; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + import com.scalar.db.api.Get; import com.scalar.db.io.BigIntValue; import com.scalar.db.io.BlobValue; @@ -10,22 +16,15 @@ import com.scalar.db.io.Key; import com.scalar.db.io.TextValue; import com.scalar.db.io.Value; -import org.junit.Before; -import org.junit.Test; -import software.amazon.awssdk.core.SdkBytes; -import software.amazon.awssdk.services.dynamodb.model.AttributeValue; - import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import org.junit.Before; +import org.junit.Test; +import software.amazon.awssdk.core.SdkBytes; +import software.amazon.awssdk.services.dynamodb.model.AttributeValue; public class ResultImplTest { private static final String ANY_NAME_1 = "name1"; @@ -91,7 +90,7 @@ public void getValue_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() { ResultImpl result = new ResultImpl(item, get, metadata); // Act - Optional actual = result.getValue(ANY_NAME_1); + Optional> actual = result.getValue(ANY_NAME_1); // Assert assertThat(actual).isEqualTo(Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1))); @@ -103,7 +102,7 @@ public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() { ResultImpl result = new ResultImpl(item, get, metadata); // Act - Map actual = result.getValues(); + Map> actual = result.getValues(); // Assert assertThat(actual.get(ANY_NAME_1)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1)); @@ -119,7 +118,7 @@ public void getValues_NoValuesGivenInConstructor_ShouldReturnDefaultValueSet() { ResultImpl result = new ResultImpl(emptyItem, get, metadata); // Act - Map actual = result.getValues(); + Map> actual = result.getValues(); // Assert assertThat(actual.get(ANY_COLUMN_NAME_1)).isEqualTo(new BooleanValue(ANY_COLUMN_NAME_1, false)); @@ -150,7 +149,7 @@ public void getValues_NullValuesGivenInConstructor_ShouldReturnDefaultValueSet() ResultImpl result = new ResultImpl(nullItem, get, metadata); // Act - Map actual = result.getValues(); + Map> actual = result.getValues(); // Assert assertThat(actual.get(ANY_COLUMN_NAME_1)).isEqualTo(new BooleanValue(ANY_COLUMN_NAME_1, false)); @@ -181,7 +180,7 @@ public void getValue_GetValueCalledBefore_ShouldNotLoadAgain() { public void getValues_TryToModifyReturned_ShouldThrowException() { // Arrange ResultImpl result = new ResultImpl(item, get, metadata); - Map values = result.getValues(); + Map> values = result.getValues(); // Act Assert assertThatThrownBy( @@ -199,7 +198,7 @@ public void getValues_GetWithProjectionsGiven_ShouldReturnWhatsSet() { ResultImpl result = new ResultImpl(item, getWithProjections, metadata); // Act - Map actual = result.getValues(); + Map> actual = result.getValues(); // Assert assertThat(actual.size()).isEqualTo(4); diff --git a/src/test/java/com/scalar/db/storage/jdbc/query/QueryBuilderTest.java b/src/test/java/com/scalar/db/storage/jdbc/query/QueryBuilderTest.java index cfa3dad486..30157c3f58 100644 --- a/src/test/java/com/scalar/db/storage/jdbc/query/QueryBuilderTest.java +++ b/src/test/java/com/scalar/db/storage/jdbc/query/QueryBuilderTest.java @@ -346,7 +346,7 @@ public void selectQueryWithIndexedColumnTest() { @Test public void insertQueryTest() { - Map values = new HashMap<>(); + Map> values = new HashMap<>(); values.put("v1", new TextValue("aaa")); values.put("v2", new TextValue("bbb")); values.put("v3", new TextValue("ddd")); @@ -387,7 +387,7 @@ public void insertQueryTest() { @Test public void updateQueryTest() { - Map values = new HashMap<>(); + Map> values = new HashMap<>(); values.put("v1", new TextValue("aaa")); values.put("v2", new TextValue("bbb")); values.put("v3", new TextValue("ddd")); @@ -515,7 +515,7 @@ public void deleteQueryTest() { @Test public void upsertQueryTest() { - Map values = new HashMap<>(); + Map> values = new HashMap<>(); values.put("v1", new TextValue("aaa")); values.put("v2", new TextValue("bbb")); values.put("v3", new TextValue("ddd")); diff --git a/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java b/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java index 4e090f6ff8..b04caa33d6 100644 --- a/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java +++ b/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java @@ -1,7 +1,10 @@ package com.scalar.db.transaction.consensuscommit; import static com.scalar.db.api.ConditionalExpression.Operator; -import static com.scalar.db.transaction.consensuscommit.Attribute.*; +import static com.scalar.db.transaction.consensuscommit.Attribute.ID; +import static com.scalar.db.transaction.consensuscommit.Attribute.STATE; +import static com.scalar.db.transaction.consensuscommit.Attribute.toIdValue; +import static com.scalar.db.transaction.consensuscommit.Attribute.toStateValue; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -81,8 +84,8 @@ private void configureResult(Result mock, TransactionState state) { when(mock.getClusteringKey()) .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); - ImmutableMap values = - ImmutableMap.builder() + ImmutableMap> values = + ImmutableMap.>builder() .put(ANY_NAME_3, new IntValue(ANY_NAME_3, ANY_INT_2)) .put(Attribute.ID, Attribute.toIdValue(ANY_ID)) .put(Attribute.PREPARED_AT, Attribute.toPreparedAtValue(ANY_TIME_1)) diff --git a/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java b/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java index 664ef10734..ffe2983b41 100644 --- a/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java +++ b/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java @@ -79,8 +79,8 @@ private void configureResult(Result mock, boolean hasClusteringKey, TransactionS when(mock.getClusteringKey()).thenReturn(Optional.empty()); } - ImmutableMap values = - ImmutableMap.builder() + ImmutableMap> values = + ImmutableMap.>builder() .put(Attribute.ID, Attribute.toIdValue(ANY_ID_2)) .put(Attribute.STATE, Attribute.toStateValue(state)) .put(Attribute.VERSION, Attribute.toVersionValue(2)) diff --git a/src/test/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposerTest.java b/src/test/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposerTest.java index 0e2f59d52c..03fada2ae9 100644 --- a/src/test/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposerTest.java +++ b/src/test/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposerTest.java @@ -83,8 +83,8 @@ private void configureResult(Result mock) { when(mock.getClusteringKey()) .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); - ImmutableMap values = - ImmutableMap.builder() + ImmutableMap> values = + ImmutableMap.>builder() .put(ANY_NAME_3, new IntValue(ANY_NAME_3, ANY_INT_2)) .put(Attribute.ID, Attribute.toIdValue(ANY_ID_2)) .put(Attribute.PREPARED_AT, Attribute.toPreparedAtValue(ANY_TIME_3)) diff --git a/src/test/java/com/scalar/db/transaction/consensuscommit/RecoveryHandlerTest.java b/src/test/java/com/scalar/db/transaction/consensuscommit/RecoveryHandlerTest.java index 82b7cd411e..8fa76f143e 100644 --- a/src/test/java/com/scalar/db/transaction/consensuscommit/RecoveryHandlerTest.java +++ b/src/test/java/com/scalar/db/transaction/consensuscommit/RecoveryHandlerTest.java @@ -36,8 +36,8 @@ public void setUp() { } private void configureResult(Result mock, long preparedAt) { - ImmutableMap values = - ImmutableMap.builder() + ImmutableMap> values = + ImmutableMap.>builder() .put(Attribute.ID, Attribute.toIdValue(ANY_ID_1)) .put(Attribute.PREPARED_AT, Attribute.toPreparedAtValue(preparedAt)) .put(Attribute.STATE, Attribute.toStateValue(TransactionState.PREPARED)) diff --git a/src/test/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposerTest.java b/src/test/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposerTest.java index 9fed7c5594..ac4cbc7eb9 100644 --- a/src/test/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposerTest.java +++ b/src/test/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposerTest.java @@ -1,7 +1,10 @@ package com.scalar.db.transaction.consensuscommit; import static com.scalar.db.api.ConditionalExpression.Operator; -import static com.scalar.db.transaction.consensuscommit.Attribute.*; +import static com.scalar.db.transaction.consensuscommit.Attribute.ID; +import static com.scalar.db.transaction.consensuscommit.Attribute.STATE; +import static com.scalar.db.transaction.consensuscommit.Attribute.toIdValue; +import static com.scalar.db.transaction.consensuscommit.Attribute.toStateValue; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -93,8 +96,8 @@ private void configureResult(Result mock, TransactionState state) { when(mock.getClusteringKey()) .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); - ImmutableMap values = - ImmutableMap.builder() + ImmutableMap> values = + ImmutableMap.>builder() .put(ANY_NAME_3, new IntValue(ANY_NAME_3, ANY_INT_2)) .put(Attribute.ID, Attribute.toIdValue(ANY_ID_2)) .put(Attribute.PREPARED_AT, Attribute.toPreparedAtValue(ANY_TIME_3)) @@ -126,7 +129,7 @@ private void configureInitialResult(Result mock, String id, TransactionState sta .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); ImmutableMap.Builder builder = - ImmutableMap.builder() + ImmutableMap.>builder() .put(ANY_NAME_3, new IntValue(ANY_NAME_3, ANY_INT_1)) .put(Attribute.ID, Attribute.toIdValue(id)) .put(Attribute.PREPARED_AT, Attribute.toPreparedAtValue(ANY_TIME_1)) @@ -146,8 +149,8 @@ private TransactionResult prepareInitialResult(String id, TransactionState state return new TransactionResult(result); } - private List extractAfterValues(TransactionResult result) { - List values = new ArrayList<>(); + private List> extractAfterValues(TransactionResult result) { + List> values = new ArrayList<>(); result .getValues() .forEach( diff --git a/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionResultTest.java b/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionResultTest.java index 132bab9876..ab878e7140 100644 --- a/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionResultTest.java +++ b/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionResultTest.java @@ -40,8 +40,8 @@ private void configureResult(Result mock) { when(mock.getClusteringKey()) .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); - ImmutableMap values = - ImmutableMap.builder() + ImmutableMap> values = + ImmutableMap.>builder() .put(ANY_NAME_3, new IntValue(ANY_NAME_3, ANY_INT_2)) .put(Attribute.ID, Attribute.toIdValue(ANY_ID_2)) .put(Attribute.PREPARED_AT, Attribute.toPreparedAtValue(ANY_TIME_3)) @@ -97,7 +97,7 @@ public void getValue_ResultGiven_ShouldReturnCorrectValue() { result = new TransactionResult(prepareResult()); // Act - Optional actual = result.getValue(ANY_NAME_3); + Optional> actual = result.getValue(ANY_NAME_3); // Assert assertThat(actual).isEqualTo(Optional.of(new IntValue(ANY_NAME_3, ANY_INT_2))); @@ -110,7 +110,7 @@ public void getValues_ValuesGiven_ShouldReturnCorrectValues() { result = new TransactionResult(given); // Act - Map values = result.getValues(); + Map> values = result.getValues(); // Assert assertThat(values.size()).isEqualTo(given.getValues().size());