You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/05/03 09:02:44 UTC
[shardingsphere] branch master updated: Rename variable name from xxxList and xxxCollection to xxxs (#17293)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 9996f239300 Rename variable name from xxxList and xxxCollection to xxxs (#17293)
9996f239300 is described below
commit 9996f23930003d251d1724ddcb05bbc8c2245500
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue May 3 17:02:36 2022 +0800
Rename variable name from xxxList and xxxCollection to xxxs (#17293)
* Rename ResList to Results
* Rename variable name from xxxList and xxxCollection to xxxs
---
.../config/YamlExampleConfigurationValidator.java | 14 +--
.../generator/EncryptAlterTableTokenGenerator.java | 23 ++---
.../merge/dql/EncryptAlgorithmMetaDataTest.java | 6 +-
...adwriteSplittingRuleStatementConverterTest.java | 4 +-
.../route/engine/util/ShadowExtractorTest.java | 12 +--
.../dal/show/ShowTableStatusMergedResult.java | 10 +-
...rdingDataSourceGroupBroadcastRoutingEngine.java | 8 +-
...neratedKeyInsertValueParameterRewriterTest.java | 20 +---
.../AggregationDistinctTokenGeneratorTest.java | 22 ++--
.../token/ConstraintTokenGeneratorTest.java | 38 ++++---
...DistinctProjectionPrefixTokenGeneratorTest.java | 21 ++--
.../GeneratedKeyAssignmentTokenGeneratorTest.java | 18 ++--
...GeneratedKeyInsertValuesTokenGeneratorTest.java | 47 +++------
.../rewrite/token/IndexTokenGeneratorTest.java | 51 ++++------
.../rewrite/token/OrderByTokenGeneratorTest.java | 45 ++++-----
.../token/ProjectionsTokenGeneratorTest.java | 27 ++---
.../ShardingInsertValuesTokenGeneratorTest.java | 39 +++-----
.../rewrite/token/TableTokenGeneratorTest.java | 14 +--
.../UnusedShardingAlgorithmsQueryResultSet.java | 4 +-
.../UnusedShardingKeyGeneratorsQueryResultSet.java | 4 +-
.../spring/boot/ShardingSpringBootStarterTest.java | 4 +-
.../metadata/user/ShardingSphereUsersTest.java | 13 ++-
.../result/impl/memory/MemoryMergedResult.java | 8 +-
.../sql/token/pojo/generic/InsertValueTest.java | 10 +-
.../infra/route/context/RouteContextTest.java | 4 +-
.../parser/DataSourceBeanDefinitionParser.java | 6 +-
.../builder/StoragePrivilegeBuilderTest.java | 3 +-
.../dialect/OraclePrivilegeHandlerTest.java | 8 +-
.../route/SingleTableSQLRouterTest.java | 4 +-
.../repository/standalone/h2/H2Repository.java | 6 +-
.../statement/impl/MySQLStatementSQLVisitor.java | 11 +-
.../impl/OracleDMLStatementSQLVisitor.java | 111 +++++++--------------
.../impl/SQL92DMLStatementSQLVisitor.java | 6 +-
.../impl/SQLServerStatementSQLVisitor.java | 15 ++-
.../sql/common/util/SafeNumberOperationUtil.java | 32 +++---
.../common/util/SafeNumberOperationUtilTest.java | 36 +++----
.../data/pipeline/cases/BaseITCase.java | 10 +-
.../cases/mysql/MySQLManualScalingCase.java | 8 +-
.../postgresql/PostgreSQLManualScalingCase.java | 2 +-
.../pipeline/env/IntegrationTestEnvironment.java | 8 +-
40 files changed, 300 insertions(+), 432 deletions(-)
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/yaml/config/YamlExampleConfigurationValidator.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/yaml/config/YamlExampleConfigurationValidator.java
index 8fc666e1511..7f03c004fbb 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/yaml/config/YamlExampleConfigurationValidator.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/yaml/config/YamlExampleConfigurationValidator.java
@@ -44,20 +44,20 @@ public final class YamlExampleConfigurationValidator {
configurationMap.put("features", config.getFeatures());
configurationMap.put("frameworks", config.getFrameworks());
validateConfigurationValues(configurationMap);
- validateAccountConfigProps(config.getProps());
+ validateAccountConfigProperties(config.getProps());
}
private static void validateConfigurationValues(final Map<String, List<String>> configMap) {
- configMap.forEach((configItem, configValues) -> {
- YamlExampleConfigurationSupportedValue supportedValueEnum = YamlExampleConfigurationSupportedValue.of(configItem);
+ configMap.forEach((key, value) -> {
+ YamlExampleConfigurationSupportedValue supportedValueEnum = YamlExampleConfigurationSupportedValue.of(key);
Set<String> supportedValues = supportedValueEnum.getSupportedValues();
- configValues.forEach(v -> Preconditions.checkArgument(supportedValues.contains(v), getConfigValueErrorMessage(configItem, supportedValues, v)));
+ value.forEach(each -> Preconditions.checkArgument(supportedValues.contains(each), getConfigValueErrorMessage(key, supportedValues, each)));
});
}
- private static void validateAccountConfigProps(final Properties props) {
- List<String> accountConfigItemList = Lists.newArrayList("host", "port", "username", "password");
- accountConfigItemList.forEach(each -> Preconditions.checkArgument(props.get(each) != null, getConfigItemErrorMessage(each)));
+ private static void validateAccountConfigProperties(final Properties props) {
+ Collection<String> accountConfigItems = Arrays.asList("host", "port", "username", "password");
+ accountConfigItems.forEach(each -> null != Preconditions.checkArgument(props.get(each), getConfigItemErrorMessage(each)));
}
private static String getConfigValueErrorMessage(final String configItem, final Set<String> supportedValues, final String errorValue) {
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
index b6a93a2ea28..6472e5d2cf9 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
@@ -66,24 +66,24 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
Collection<SQLToken> result = new LinkedList<>(getAddColumnTokens(tableName, alterTableStatementContext.getSqlStatement().getAddColumnDefinitions()));
result.addAll(getModifyColumnTokens(tableName, alterTableStatementContext.getSqlStatement().getModifyColumnDefinitions()));
result.addAll(getChangeColumnTokens(tableName, alterTableStatementContext.getSqlStatement().getChangeColumnDefinitions()));
- Collection<SQLToken> dropCollection = getDropColumnTokens(tableName, alterTableStatementContext.getSqlStatement().getDropColumnDefinitions());
+ Collection<SQLToken> dropColumnTokens = getDropColumnTokens(tableName, alterTableStatementContext.getSqlStatement().getDropColumnDefinitions());
String databaseName = alterTableStatementContext.getDatabaseType().getName();
if ("SQLServer".equals(databaseName)) {
- result.addAll(mergeDropColumnStatement(dropCollection, "", ""));
+ result.addAll(mergeDropColumnStatement(dropColumnTokens, "", ""));
} else if ("Oracle".equals(databaseName)) {
- result.addAll(mergeDropColumnStatement(dropCollection, "(", ")"));
+ result.addAll(mergeDropColumnStatement(dropColumnTokens, "(", ")"));
} else {
- result.addAll(dropCollection);
+ result.addAll(dropColumnTokens);
}
return result;
}
- private Collection<SQLToken> mergeDropColumnStatement(final Collection<SQLToken> dropCollection, final String leftJoiner, final String rightJoiner) {
+ private Collection<SQLToken> mergeDropColumnStatement(final Collection<SQLToken> dropSQLTokens, final String leftJoiner, final String rightJoiner) {
Collection<SQLToken> result = new LinkedList<>();
- List<String> dropColumnList = new ArrayList<>();
+ List<String> dropColumns = new ArrayList<>();
int lastStartIndex = -1;
- for (int i = 0; i < dropCollection.size(); i++) {
- SQLToken token = (SQLToken) ((List) dropCollection).get(i);
+ for (int i = 0; i < dropSQLTokens.size(); i++) {
+ SQLToken token = (SQLToken) ((List) dropSQLTokens).get(i);
if (token instanceof RemoveToken) {
if (i != 0) {
result.add(new RemoveToken(lastStartIndex, ((RemoveToken) token).getStopIndex()));
@@ -92,10 +92,9 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
}
} else {
EncryptAlterTableToken encryptAlterTableToken = (EncryptAlterTableToken) token;
- dropColumnList.add(encryptAlterTableToken.getColumnName());
- if (i == dropCollection.size() - 1) {
- result.add(new EncryptAlterTableToken(token.getStartIndex(), encryptAlterTableToken.getStopIndex(),
- leftJoiner + String.join(",", dropColumnList) + rightJoiner, "DROP COLUMN"));
+ dropColumns.add(encryptAlterTableToken.getColumnName());
+ if (i == dropSQLTokens.size() - 1) {
+ result.add(new EncryptAlterTableToken(token.getStartIndex(), encryptAlterTableToken.getStopIndex(), leftJoiner + String.join(",", dropColumns) + rightJoiner, "DROP COLUMN"));
}
}
lastStartIndex = ((Substitutable) token).getStartIndex();
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
index 7c4311791be..62c74216d72 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
import org.apache.shardingsphere.infra.binder.segment.select.projection.ProjectionsContext;
import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.DerivedProjection;
@@ -41,7 +40,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
@@ -82,8 +80,7 @@ public final class EncryptAlgorithmMetaDataTest {
@Before
public void setUp() {
when(selectStatementContext.getProjectionsContext()).thenReturn(projectionsContext);
- List<Projection> columnProjectionList = Collections.singletonList(columnProjection);
- when(projectionsContext.getExpandProjections()).thenReturn(columnProjectionList);
+ when(projectionsContext.getExpandProjections()).thenReturn(Collections.singletonList(columnProjection));
when(columnProjection.getName()).thenReturn("id");
when(columnProjection.getExpression()).thenReturn("id");
when(selectStatementContext.getTablesContext()).thenReturn(tablesContext);
@@ -127,6 +124,7 @@ public final class EncryptAlgorithmMetaDataTest {
assertFalse(actual.isPresent());
}
+ @SuppressWarnings("rawtypes")
@Test
public void assertFindEncryptor() {
when(encryptRule.findEncryptor("t_order", "id")).thenReturn(Optional.of(encryptAlgorithm));
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphe [...]
index 6affd6e224e..a2e9245ab2d 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java
@@ -105,9 +105,9 @@ public final class ReadwriteSplittingRuleStatementConverterTest {
});
}
- private ReadwriteSplittingRuleSegment createReadwriteSplittingRuleSegment(final String name, final String writeDataSource, final List<String> readDataSourceList, final String loadBalancerTypeName,
+ private ReadwriteSplittingRuleSegment createReadwriteSplittingRuleSegment(final String name, final String writeDataSource, final List<String> readDataSources, final String loadBalancerTypeName,
final Properties props) {
- return new ReadwriteSplittingRuleSegment(name, writeDataSource, readDataSourceList, loadBalancerTypeName, props);
+ return new ReadwriteSplittingRuleSegment(name, writeDataSource, readDataSources, loadBalancerTypeName, props);
}
private ReadwriteSplittingRuleSegment createReadwriteSplittingRuleSegment(final String name, final String autoAwareResource, final String loadBalancer, final Properties props) {
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractorTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractorTest.java
index a812b215899..3010ec8a46e 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractorTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/engine/util/ShadowExtractorTest.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.shadow.route.engine.util;
-import java.util.LinkedList;
-import java.util.List;
-
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.SimpleExpressionSegment;
import org.junit.Test;
+import java.util.LinkedList;
+import java.util.List;
+
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -33,8 +33,8 @@ public final class ShadowExtractorTest {
@Test
public void assertExtractValuesSimpleExpressionSegment() {
SimpleExpressionSegment simpleExpressionSegment = new LiteralExpressionSegment(1, 2, "expected");
- List<Object> parametersList = new LinkedList<>();
- assertTrue(ShadowExtractor.extractValues(simpleExpressionSegment, parametersList).isPresent());
- assertThat(ShadowExtractor.extractValues(simpleExpressionSegment, parametersList).get().iterator().next(), is("expected"));
+ List<Object> parameters = new LinkedList<>();
+ assertTrue(ShadowExtractor.extractValues(simpleExpressionSegment, parameters).isPresent());
+ assertThat(ShadowExtractor.extractValues(simpleExpressionSegment, parameters).get().iterator().next(), is("expected"));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResult.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResult.java
index 34199e268cf..cb4fcb5db7e 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResult.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResult.java
@@ -46,7 +46,7 @@ public final class ShowTableStatusMergedResult extends MemoryMergedResult<Shardi
@Override
protected List<MemoryQueryResultRow> init(final ShardingRule shardingRule, final ShardingSphereSchema schema,
final SQLStatementContext<?> sqlStatementContext, final List<QueryResult> queryResults) throws SQLException {
- Map<String, MemoryQueryResultRow> memoryQueryResultRowMap = new LinkedHashMap<>();
+ Map<String, MemoryQueryResultRow> memoryQueryResultRows = new LinkedHashMap<>();
for (QueryResult each : queryResults) {
while (each.next()) {
MemoryQueryResultRow memoryResultSetRow = new MemoryQueryResultRow(each);
@@ -54,14 +54,14 @@ public final class ShowTableStatusMergedResult extends MemoryMergedResult<Shardi
Optional<TableRule> tableRule = shardingRule.findTableRuleByActualTable(actualTableName);
tableRule.ifPresent(optional -> memoryResultSetRow.setCell(1, optional.getLogicTable()));
String tableName = memoryResultSetRow.getCell(1).toString();
- if (memoryQueryResultRowMap.containsKey(tableName)) {
- merge(memoryQueryResultRowMap.get(tableName), memoryResultSetRow);
+ if (memoryQueryResultRows.containsKey(tableName)) {
+ merge(memoryQueryResultRows.get(tableName), memoryResultSetRow);
} else {
- memoryQueryResultRowMap.put(tableName, memoryResultSetRow);
+ memoryQueryResultRows.put(tableName, memoryResultSetRow);
}
}
}
- return new LinkedList<>(memoryQueryResultRowMap.values());
+ return new LinkedList<>(memoryQueryResultRows.values());
}
private void merge(final MemoryQueryResultRow row, final MemoryQueryResultRow newRow) {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngine.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngine.java
index 330bf50301f..5902b10180f 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngine.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngine.java
@@ -66,16 +66,16 @@ public final class ShardingDataSourceGroupBroadcastRoutingEngine implements Shar
private Collection<Set<String>> getCandidateDataSourceGroup(final Collection<Set<String>> dataSourceSetGroup, final Set<String> compareSet) {
Collection<Set<String>> result = new LinkedList<>();
- Set<String> intersectionSet;
+ Set<String> intersections;
if (dataSourceSetGroup.isEmpty()) {
result.add(compareSet);
return result;
}
boolean hasIntersection = false;
for (Set<String> each : dataSourceSetGroup) {
- intersectionSet = Sets.intersection(each, compareSet);
- if (!intersectionSet.isEmpty()) {
- result.add(intersectionSet);
+ intersections = Sets.intersection(each, compareSet);
+ if (!intersections.isEmpty()) {
+ result.add(intersections);
hasIntersection = true;
} else {
result.add(each);
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameter/ShardingGeneratedKeyInsertValueParameterRewriterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameter/ShardingGeneratedKeyInsertValueParameterRewriterTest.java
index a18f4ea0e90..1bc78c350f2 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameter/ShardingGeneratedKeyInsertValueParameterRewriterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameter/ShardingGeneratedKeyInsertValueParameterRewriterTest.java
@@ -26,11 +26,9 @@ import org.apache.shardingsphere.sharding.rewrite.parameter.impl.ShardingGenerat
import org.junit.Test;
import org.mockito.stubbing.Answer;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import static org.hamcrest.CoreMatchers.hasItem;
@@ -85,25 +83,17 @@ public final class ShardingGeneratedKeyInsertValueParameterRewriterTest {
addedIndexAndParameters.put(index, parameters);
return null;
}).when(standardParameterBuilder).addAddedParameters(anyInt(), anyCollection());
- List<StandardParameterBuilder> parameterBuildersList = new ArrayList<>();
- parameterBuildersList.add(standardParameterBuilder);
GroupedParameterBuilder result = mock(GroupedParameterBuilder.class);
- when(result.getParameterBuilders()).thenReturn(parameterBuildersList);
+ when(result.getParameterBuilders()).thenReturn(Collections.singletonList(standardParameterBuilder));
return result;
}
private InsertStatementContext getInsertStatementContext() {
InsertStatementContext result = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
- when(result.getGeneratedKeyContext().isPresent()).thenReturn(Boolean.TRUE);
+ when(result.getGeneratedKeyContext().isPresent()).thenReturn(true);
when(result.getGeneratedKeyContext().get().getColumnName()).thenReturn("testColumnName");
- Collection<Comparable<?>> generatedValuesCollection = new LinkedList<>();
- generatedValuesCollection.add(TEST_GENERATED_VALUE);
- when(result.getGeneratedKeyContext().get().getGeneratedValues()).thenReturn(generatedValuesCollection);
- List<Object> groupedParameter = new LinkedList<>();
- groupedParameter.add("testGroupedParameter");
- List<List<Object>> groupedParametersList = new LinkedList<>();
- groupedParametersList.add(groupedParameter);
- when(result.getGroupedParameters()).thenReturn(groupedParametersList);
+ when(result.getGeneratedKeyContext().get().getGeneratedValues()).thenReturn(Collections.singleton(TEST_GENERATED_VALUE));
+ when(result.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList("testGroupedParameter")));
when(result.getInsertValueContexts().get(0).getParameterCount()).thenReturn(TEST_PARAMETER_COUNT);
return result;
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/AggregationDistinctTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/AggregationDistinctTokenGeneratorTest.java
index 14267d9fcd5..90686d893b3 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/AggregationDistinctTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/AggregationDistinctTokenGeneratorTest.java
@@ -24,10 +24,10 @@ import org.apache.shardingsphere.sharding.rewrite.token.generator.impl.Aggregati
import org.apache.shardingsphere.sharding.rewrite.token.pojo.AggregationDistinctToken;
import org.junit.Test;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
@@ -51,23 +51,19 @@ public final class AggregationDistinctTokenGeneratorTest {
@Test
public void assertGenerateSQLToken() {
AggregationDistinctProjection aggregationDistinctProjection = mock(AggregationDistinctProjection.class);
- final String testAlias = "AVG_DERIVED_COUNT_0";
+ String testAlias = "AVG_DERIVED_COUNT_0";
when(aggregationDistinctProjection.getAlias()).thenReturn(Optional.of(testAlias));
- final int testStartIndex = 0;
- when(aggregationDistinctProjection.getStartIndex()).thenReturn(testStartIndex);
- final int testStopIndex = 2;
- when(aggregationDistinctProjection.getStopIndex()).thenReturn(testStopIndex);
- final String testDistinctInnerExpression = "TEST_DISTINCT_INNER_EXPRESSION";
+ when(aggregationDistinctProjection.getStartIndex()).thenReturn(0);
+ when(aggregationDistinctProjection.getStopIndex()).thenReturn(2);
+ String testDistinctInnerExpression = "TEST_DISTINCT_INNER_EXPRESSION";
when(aggregationDistinctProjection.getDistinctInnerExpression()).thenReturn(testDistinctInnerExpression);
- List<AggregationDistinctProjection> aggregationDistinctProjectionList = new LinkedList<>();
- aggregationDistinctProjectionList.add(aggregationDistinctProjection);
SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
- when(selectStatementContext.getProjectionsContext().getAggregationDistinctProjections()).thenReturn(aggregationDistinctProjectionList);
+ when(selectStatementContext.getProjectionsContext().getAggregationDistinctProjections()).thenReturn(Collections.singletonList(aggregationDistinctProjection));
AggregationDistinctTokenGenerator aggregationDistinctTokenGenerator = new AggregationDistinctTokenGenerator();
- List<AggregationDistinctToken> generateSQLTokensResult = aggregationDistinctTokenGenerator.generateSQLTokens(selectStatementContext).stream().collect(Collectors.toList());
+ List<AggregationDistinctToken> generateSQLTokensResult = new ArrayList<>(aggregationDistinctTokenGenerator.generateSQLTokens(selectStatementContext));
assertThat(generateSQLTokensResult.get(0).toString(), is(testDistinctInnerExpression + " AS " + testAlias));
when(aggregationDistinctProjection.getAlias()).thenReturn(Optional.of("TEST_ERROR_ALIAS"));
- generateSQLTokensResult = aggregationDistinctTokenGenerator.generateSQLTokens(selectStatementContext).stream().collect(Collectors.toList());
+ generateSQLTokensResult = new ArrayList<>(aggregationDistinctTokenGenerator.generateSQLTokens(selectStatementContext));
assertThat(generateSQLTokensResult.get(0).toString(), is(testDistinctInnerExpression));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ConstraintTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ConstraintTokenGeneratorTest.java
index 092df618ee9..d4c79b05dd2 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ConstraintTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ConstraintTokenGeneratorTest.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.Identifi
import org.junit.Test;
import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedList;
import static org.hamcrest.CoreMatchers.is;
@@ -40,35 +41,30 @@ public final class ConstraintTokenGeneratorTest {
@Test
public void assertIsGenerateSQLToken() {
- CreateDatabaseStatementContext createDatabaseStatementContext = mock(CreateDatabaseStatementContext.class);
- ConstraintTokenGenerator constraintTokenGenerator = new ConstraintTokenGenerator();
- assertFalse(constraintTokenGenerator.isGenerateSQLToken(createDatabaseStatementContext));
+ ConstraintTokenGenerator generator = new ConstraintTokenGenerator();
+ assertFalse(generator.isGenerateSQLToken(mock(CreateDatabaseStatementContext.class)));
AlterTableStatementContext alterTableStatementContext = mock(AlterTableStatementContext.class);
- Collection<ConstraintSegment> constraintSegmentCollection = new LinkedList<>();
- when(alterTableStatementContext.getConstraints()).thenReturn(constraintSegmentCollection);
- assertFalse(constraintTokenGenerator.isGenerateSQLToken(alterTableStatementContext));
- constraintSegmentCollection.add(mock(ConstraintSegment.class));
- assertTrue(constraintTokenGenerator.isGenerateSQLToken(alterTableStatementContext));
+ Collection<ConstraintSegment> constraintSegments = new LinkedList<>();
+ when(alterTableStatementContext.getConstraints()).thenReturn(constraintSegments);
+ assertFalse(generator.isGenerateSQLToken(alterTableStatementContext));
+ constraintSegments.add(mock(ConstraintSegment.class));
+ assertTrue(generator.isGenerateSQLToken(alterTableStatementContext));
}
@Test
public void assertGenerateSQLTokens() {
ConstraintSegment constraintSegment = mock(ConstraintSegment.class);
- final int testStartIndex = 1;
- when(constraintSegment.getStartIndex()).thenReturn(testStartIndex);
- final int testStopIndex = 3;
- when(constraintSegment.getStopIndex()).thenReturn(testStopIndex);
+ when(constraintSegment.getStartIndex()).thenReturn(1);
+ when(constraintSegment.getStopIndex()).thenReturn(3);
IdentifierValue constraintIdentifier = mock(IdentifierValue.class);
when(constraintSegment.getIdentifier()).thenReturn(constraintIdentifier);
- Collection<ConstraintSegment> constraintSegmentCollection = new LinkedList<>();
- constraintSegmentCollection.add(constraintSegment);
AlterTableStatementContext alterTableStatementContext = mock(AlterTableStatementContext.class);
- when(alterTableStatementContext.getConstraints()).thenReturn(constraintSegmentCollection);
- ShardingRule shardingRule = mock(ShardingRule.class);
- ConstraintTokenGenerator constraintTokenGenerator = new ConstraintTokenGenerator();
- constraintTokenGenerator.setShardingRule(shardingRule);
- Collection<ConstraintToken> result = constraintTokenGenerator.generateSQLTokens(alterTableStatementContext);
- assertThat(result.size(), is(1));
- assertThat((new LinkedList<>(result)).get(0).getStartIndex(), is(testStartIndex));
+ when(alterTableStatementContext.getConstraints()).thenReturn(Collections.singleton(constraintSegment));
+ ConstraintTokenGenerator generator = new ConstraintTokenGenerator();
+ generator.setShardingRule(mock(ShardingRule.class));
+ Collection<ConstraintToken> actual = generator.generateSQLTokens(alterTableStatementContext);
+ assertThat(actual.size(), is(1));
+ assertThat((new LinkedList<>(actual)).get(0).getStartIndex(), is(1));
+ assertThat((new LinkedList<>(actual)).get(0).getStopIndex(), is(3));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/DistinctProjectionPrefixTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/DistinctProjectionPrefixTokenGeneratorTest.java
index 249f12cd1f9..99be7fcbffc 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/DistinctProjectionPrefixTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/DistinctProjectionPrefixTokenGeneratorTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.Agg
import org.apache.shardingsphere.infra.binder.statement.ddl.CreateDatabaseStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.sharding.rewrite.token.generator.impl.DistinctProjectionPrefixTokenGenerator;
-import org.apache.shardingsphere.sharding.rewrite.token.pojo.DistinctProjectionPrefixToken;
import org.junit.Test;
import java.util.LinkedList;
@@ -39,15 +38,14 @@ public final class DistinctProjectionPrefixTokenGeneratorTest {
@Test
public void assertIsGenerateSQLToken() {
- CreateDatabaseStatementContext createDatabaseStatementContext = mock(CreateDatabaseStatementContext.class);
- DistinctProjectionPrefixTokenGenerator distinctProjectionPrefixTokenGenerator = new DistinctProjectionPrefixTokenGenerator();
- assertFalse(distinctProjectionPrefixTokenGenerator.isGenerateSQLToken(createDatabaseStatementContext));
+ DistinctProjectionPrefixTokenGenerator generator = new DistinctProjectionPrefixTokenGenerator();
+ assertFalse(generator.isGenerateSQLToken(mock(CreateDatabaseStatementContext.class)));
SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
- List<AggregationDistinctProjection> aggregationDistinctProjectionList = new LinkedList<>();
- when(selectStatementContext.getProjectionsContext().getAggregationDistinctProjections()).thenReturn(aggregationDistinctProjectionList);
- assertFalse(distinctProjectionPrefixTokenGenerator.isGenerateSQLToken(selectStatementContext));
- aggregationDistinctProjectionList.add(mock(AggregationDistinctProjection.class));
- assertTrue(distinctProjectionPrefixTokenGenerator.isGenerateSQLToken(selectStatementContext));
+ List<AggregationDistinctProjection> aggregationDistinctProjections = new LinkedList<>();
+ when(selectStatementContext.getProjectionsContext().getAggregationDistinctProjections()).thenReturn(aggregationDistinctProjections);
+ assertFalse(generator.isGenerateSQLToken(selectStatementContext));
+ aggregationDistinctProjections.add(mock(AggregationDistinctProjection.class));
+ assertTrue(generator.isGenerateSQLToken(selectStatementContext));
}
@Test
@@ -55,8 +53,7 @@ public final class DistinctProjectionPrefixTokenGeneratorTest {
SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
final int testStartIndex = 1;
when(selectStatementContext.getProjectionsContext().getStartIndex()).thenReturn(testStartIndex);
- DistinctProjectionPrefixTokenGenerator distinctProjectionPrefixTokenGenerator = new DistinctProjectionPrefixTokenGenerator();
- DistinctProjectionPrefixToken distinctProjectionPrefixToken = distinctProjectionPrefixTokenGenerator.generateSQLToken(selectStatementContext);
- assertThat(distinctProjectionPrefixToken.toString(), is("DISTINCT "));
+ DistinctProjectionPrefixTokenGenerator generator = new DistinctProjectionPrefixTokenGenerator();
+ assertThat(generator.generateSQLToken(selectStatementContext).toString(), is("DISTINCT "));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/GeneratedKeyAssignmentTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/GeneratedKeyAssignmentTokenGeneratorTest.java
index 23329f01246..73d9d1d94a7 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/GeneratedKeyAssignmentTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/GeneratedKeyAssignmentTokenGeneratorTest.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.Se
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLInsertStatement;
import org.junit.Test;
-import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@@ -43,23 +43,19 @@ public final class GeneratedKeyAssignmentTokenGeneratorTest {
public void assertGenerateSQLToken() {
GeneratedKeyContext generatedKeyContext = mock(GeneratedKeyContext.class, RETURNS_DEEP_STUBS);
when(generatedKeyContext.getColumnName()).thenReturn("testColumnName");
- Collection<Comparable<?>> testGeneratedValuesCollection = new LinkedList<>();
- final int testGeneratedValue = 4;
- testGeneratedValuesCollection.add(testGeneratedValue);
- when(generatedKeyContext.getGeneratedValues()).thenReturn(testGeneratedValuesCollection);
+ when(generatedKeyContext.getGeneratedValues()).thenReturn(Collections.singleton(4));
InsertStatementContext insertStatementContext = mock(InsertStatementContext.class);
when(insertStatementContext.getGeneratedKeyContext()).thenReturn(Optional.of(generatedKeyContext));
MySQLInsertStatement insertStatement = mock(MySQLInsertStatement.class);
when(insertStatementContext.getSqlStatement()).thenReturn(insertStatement);
SetAssignmentSegment setAssignmentSegment = mock(SetAssignmentSegment.class);
- final int testStopIndex = 2;
- when(setAssignmentSegment.getStopIndex()).thenReturn(testStopIndex);
+ when(setAssignmentSegment.getStopIndex()).thenReturn(2);
when(insertStatement.getSetAssignment()).thenReturn(Optional.of(setAssignmentSegment));
List<Object> testParameters = new LinkedList<>();
- GeneratedKeyAssignmentTokenGenerator generatedKeyAssignmentTokenGenerator = new GeneratedKeyAssignmentTokenGenerator();
- generatedKeyAssignmentTokenGenerator.setParameters(testParameters);
- assertThat(generatedKeyAssignmentTokenGenerator.generateSQLToken(insertStatementContext), instanceOf(LiteralGeneratedKeyAssignmentToken.class));
+ GeneratedKeyAssignmentTokenGenerator generator = new GeneratedKeyAssignmentTokenGenerator();
+ generator.setParameters(testParameters);
+ assertThat(generator.generateSQLToken(insertStatementContext), instanceOf(LiteralGeneratedKeyAssignmentToken.class));
testParameters.add("testObject");
- assertThat(generatedKeyAssignmentTokenGenerator.generateSQLToken(insertStatementContext), instanceOf(ParameterMarkerGeneratedKeyAssignmentToken.class));
+ assertThat(generator.generateSQLToken(insertStatementContext), instanceOf(ParameterMarkerGeneratedKeyAssignmentToken.class));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/GeneratedKeyInsertValuesTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/GeneratedKeyInsertValuesTokenGeneratorTest.java
index 8a34b586ec8..fc1c21bc51d 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/GeneratedKeyInsertValuesTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/GeneratedKeyInsertValuesTokenGeneratorTest.java
@@ -26,10 +26,10 @@ import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValue;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValuesToken;
import org.apache.shardingsphere.sharding.rewrite.token.generator.impl.keygen.GeneratedKeyInsertValuesTokenGenerator;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import org.junit.Test;
-import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@@ -46,50 +46,31 @@ public final class GeneratedKeyInsertValuesTokenGeneratorTest {
InsertStatementContext insertStatementContext = mock(InsertStatementContext.class);
GeneratedKeyContext generatedKeyContext = getGeneratedKeyContext();
when(insertStatementContext.getGeneratedKeyContext()).thenReturn(Optional.of(generatedKeyContext));
- List<InsertValueContext> insertValueContextsList = getInsertValueContextsList();
- when(insertStatementContext.getInsertValueContexts()).thenReturn(insertValueContextsList);
- List<List<Object>> groupedParametersList = new LinkedList<>();
- List<Object> groupedParameters = new LinkedList<>();
- groupedParameters.add(new Object());
- groupedParametersList.add(groupedParameters);
- when(insertStatementContext.getGroupedParameters()).thenReturn(groupedParametersList);
- GeneratedKeyInsertValuesTokenGenerator generatedKeyInsertValuesTokenGenerator = new GeneratedKeyInsertValuesTokenGenerator();
- List<SQLToken> previousSQLTokens = getPreviousSQLTokens();
- generatedKeyInsertValuesTokenGenerator.setPreviousSQLTokens(previousSQLTokens);
- SQLToken sqlToken = generatedKeyInsertValuesTokenGenerator.generateSQLToken(insertStatementContext);
+ when(insertStatementContext.getInsertValueContexts()).thenReturn(Collections.singletonList(mock(InsertValueContext.class)));
+ List<List<Object>> parameterGroups = Collections.singletonList(new ArrayList<>(Collections.singletonList(new Object())));
+ when(insertStatementContext.getGroupedParameters()).thenReturn(parameterGroups);
+ GeneratedKeyInsertValuesTokenGenerator generator = new GeneratedKeyInsertValuesTokenGenerator();
+ generator.setPreviousSQLTokens(getPreviousSQLTokens());
+ SQLToken sqlToken = generator.generateSQLToken(insertStatementContext);
assertThat(sqlToken, instanceOf(InsertValuesToken.class));
assertThat(((InsertValuesToken) sqlToken).getInsertValues().get(0).getValues().get(0), instanceOf(DerivedParameterMarkerExpressionSegment.class));
- groupedParametersList.get(0).clear();
+ parameterGroups.get(0).clear();
((InsertValuesToken) sqlToken).getInsertValues().get(0).getValues().clear();
- sqlToken = generatedKeyInsertValuesTokenGenerator.generateSQLToken(insertStatementContext);
+ sqlToken = generator.generateSQLToken(insertStatementContext);
assertThat(((InsertValuesToken) sqlToken).getInsertValues().get(0).getValues().get(0), instanceOf(DerivedLiteralExpressionSegment.class));
}
private List<SQLToken> getPreviousSQLTokens() {
- List<ExpressionSegment> valuesList = new LinkedList<>();
InsertValue insertValue = mock(InsertValue.class);
- when(insertValue.getValues()).thenReturn(valuesList);
- List<InsertValue> insertValuesList = new LinkedList<>();
- insertValuesList.add(insertValue);
+ when(insertValue.getValues()).thenReturn(new LinkedList<>());
InsertValuesToken insertValuesToken = mock(InsertValuesToken.class);
- when(insertValuesToken.getInsertValues()).thenReturn(insertValuesList);
- List<SQLToken> result = new LinkedList<>();
- result.add(insertValuesToken);
- return result;
+ when(insertValuesToken.getInsertValues()).thenReturn(Collections.singletonList(insertValue));
+ return Collections.singletonList(insertValuesToken);
}
private GeneratedKeyContext getGeneratedKeyContext() {
GeneratedKeyContext result = mock(GeneratedKeyContext.class);
- Collection<Comparable<?>> generatedValuesCollection = new LinkedList<>();
- generatedValuesCollection.add("TEST_GENERATED_VALUE");
- when(result.getGeneratedValues()).thenReturn(generatedValuesCollection);
- return result;
- }
-
- private List<InsertValueContext> getInsertValueContextsList() {
- InsertValueContext insertValueContext = mock(InsertValueContext.class);
- List<InsertValueContext> result = new LinkedList<>();
- result.add(insertValueContext);
+ when(result.getGeneratedValues()).thenReturn(Collections.singleton("TEST_GENERATED_VALUE"));
return result;
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/IndexTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/IndexTokenGeneratorTest.java
index dd57e01be04..e5440436c25 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/IndexTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/IndexTokenGeneratorTest.java
@@ -30,9 +30,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.Identifi
import org.junit.Test;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.LinkedList;
-import java.util.Map;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
@@ -48,44 +47,32 @@ public final class IndexTokenGeneratorTest {
@Test
public void assertIsGenerateSQLToken() {
CreateDatabaseStatementContext createDatabaseStatementContext = mock(CreateDatabaseStatementContext.class);
- IndexTokenGenerator indexTokenGenerator = new IndexTokenGenerator();
- assertFalse(indexTokenGenerator.isGenerateSQLToken(createDatabaseStatementContext));
+ IndexTokenGenerator generator = new IndexTokenGenerator();
+ assertFalse(generator.isGenerateSQLToken(createDatabaseStatementContext));
AlterIndexStatementContext alterIndexStatementContext = mock(AlterIndexStatementContext.class);
- Collection<IndexSegment> indexSegmentCollection = new LinkedList<>();
- when(alterIndexStatementContext.getIndexes()).thenReturn(indexSegmentCollection);
- assertFalse(indexTokenGenerator.isGenerateSQLToken(alterIndexStatementContext));
- indexSegmentCollection.add(mock(IndexSegment.class));
- assertTrue(indexTokenGenerator.isGenerateSQLToken(alterIndexStatementContext));
+ Collection<IndexSegment> indexSegments = new LinkedList<>();
+ when(alterIndexStatementContext.getIndexes()).thenReturn(indexSegments);
+ assertFalse(generator.isGenerateSQLToken(alterIndexStatementContext));
+ indexSegments.add(mock(IndexSegment.class));
+ assertTrue(generator.isGenerateSQLToken(alterIndexStatementContext));
}
@Test
public void assertGenerateSQLTokens() {
IndexSegment indexSegment = mock(IndexSegment.class, RETURNS_DEEP_STUBS);
- int testStartIndex = 1;
- when(indexSegment.getStartIndex()).thenReturn(testStartIndex);
- int testStopIndex = 3;
- when(indexSegment.getStopIndex()).thenReturn(testStopIndex);
- IndexNameSegment indexNameSegment = new IndexNameSegment(testStartIndex, testStopIndex, mock(IdentifierValue.class));
- when(indexSegment.getIndexName()).thenReturn(indexNameSegment);
- Collection<IndexSegment> indexSegments = new LinkedList<>();
- indexSegments.add(indexSegment);
+ when(indexSegment.getStartIndex()).thenReturn(1);
+ when(indexSegment.getStopIndex()).thenReturn(3);
+ when(indexSegment.getIndexName()).thenReturn(new IndexNameSegment(1, 3, mock(IdentifierValue.class)));
AlterIndexStatementContext alterIndexStatementContext = mock(AlterIndexStatementContext.class, RETURNS_DEEP_STUBS);
- when(alterIndexStatementContext.getIndexes()).thenReturn(indexSegments);
+ when(alterIndexStatementContext.getIndexes()).thenReturn(Collections.singleton(indexSegment));
when(alterIndexStatementContext.getDatabaseType()).thenReturn(new MySQLDatabaseType());
when(alterIndexStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.empty());
- IndexTokenGenerator indexTokenGenerator = new IndexTokenGenerator();
- ShardingRule shardingRule = mock(ShardingRule.class);
- indexTokenGenerator.setShardingRule(shardingRule);
- indexTokenGenerator.setSchemas(mockSchemaMap());
- indexTokenGenerator.setDatabaseName("test");
- Collection<IndexToken> result = indexTokenGenerator.generateSQLTokens(alterIndexStatementContext);
- assertThat(result.size(), is(1));
- assertThat((new LinkedList<>(result)).get(0).getStartIndex(), is(testStartIndex));
- }
-
- private Map<String, ShardingSphereSchema> mockSchemaMap() {
- Map<String, ShardingSphereSchema> result = new HashMap<>(1, 1);
- result.put("test", mock(ShardingSphereSchema.class));
- return result;
+ IndexTokenGenerator generator = new IndexTokenGenerator();
+ generator.setShardingRule(mock(ShardingRule.class));
+ generator.setSchemas(Collections.singletonMap("test", mock(ShardingSphereSchema.class)));
+ generator.setDatabaseName("test");
+ Collection<IndexToken> actual = generator.generateSQLTokens(alterIndexStatementContext);
+ assertThat(actual.size(), is(1));
+ assertThat((new LinkedList<>(actual)).get(0).getStartIndex(), is(1));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/OrderByTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/OrderByTokenGeneratorTest.java
index 7260208e4a6..0d7c8fc2921 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/OrderByTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/OrderByTokenGeneratorTest.java
@@ -29,9 +29,12 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.Or
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.WindowSegment;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import java.util.Arrays;
import java.util.Collection;
-import java.util.LinkedList;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
@@ -42,6 +45,7 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.class)
public final class OrderByTokenGeneratorTest {
private static final String TEST_COLUMN_ORDER_BY_ITEM_SEGMENT_COLUMN_LABEL = "TEST_COLUMN_ORDER_BY_ITEM_SEGMENT_COLUMN_LABEL";
@@ -50,40 +54,39 @@ public final class OrderByTokenGeneratorTest {
private static final int TEST_OTHER_CLASS_ORDER_BY_ITEM_INDEX = 5;
- private OrderDirection orderDirection = mock(OrderDirection.class);
+ @Mock
+ private OrderDirection orderDirection;
@Test
public void assertIsGenerateSQLToken() {
- InsertStatementContext insertStatementContext = mock(InsertStatementContext.class);
- OrderByTokenGenerator orderByTokenGenerator = new OrderByTokenGenerator();
- assertFalse(orderByTokenGenerator.isGenerateSQLToken(insertStatementContext));
+ OrderByTokenGenerator generator = new OrderByTokenGenerator();
+ assertFalse(generator.isGenerateSQLToken(mock(InsertStatementContext.class)));
SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(selectStatementContext.getOrderByContext().isGenerated()).thenReturn(Boolean.FALSE);
- assertFalse(orderByTokenGenerator.isGenerateSQLToken(selectStatementContext));
+ assertFalse(generator.isGenerateSQLToken(selectStatementContext));
when(selectStatementContext.getOrderByContext().isGenerated()).thenReturn(Boolean.TRUE);
- assertTrue(orderByTokenGenerator.isGenerateSQLToken(selectStatementContext));
+ assertTrue(generator.isGenerateSQLToken(selectStatementContext));
}
@Test
public void assertGenerateSQLToken() {
WindowSegment windowSegment = mock(WindowSegment.class);
- final int testStopIndex = 2;
- when(windowSegment.getStopIndex()).thenReturn(testStopIndex);
+ when(windowSegment.getStopIndex()).thenReturn(2);
MySQLSelectStatement mySQLSelectStatement = mock(MySQLSelectStatement.class);
when(mySQLSelectStatement.getWindow()).thenReturn(Optional.of(windowSegment));
SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(selectStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
- Collection<OrderByItem> orderByItemCollection = getOrderByItemCollection();
- when(selectStatementContext.getOrderByContext().getItems()).thenReturn(orderByItemCollection);
- OrderByTokenGenerator orderByTokenGenerator = new OrderByTokenGenerator();
- OrderByToken orderByToken = orderByTokenGenerator.generateSQLToken(selectStatementContext);
- assertThat(orderByToken.getColumnLabels().get(0), is(TEST_COLUMN_ORDER_BY_ITEM_SEGMENT_COLUMN_LABEL));
- assertThat(orderByToken.getColumnLabels().get(1), is(TEST_EXPRESSION_ORDER_BY_ITEM_SEGMENT_COLUMN_LABEL));
- assertThat(orderByToken.getColumnLabels().get(2), is(String.valueOf(TEST_OTHER_CLASS_ORDER_BY_ITEM_INDEX)));
- assertThat(orderByToken.getOrderDirections().get(0), is(orderDirection));
+ Collection<OrderByItem> orderByItems = getOrderByItems();
+ when(selectStatementContext.getOrderByContext().getItems()).thenReturn(orderByItems);
+ OrderByTokenGenerator generator = new OrderByTokenGenerator();
+ OrderByToken actual = generator.generateSQLToken(selectStatementContext);
+ assertThat(actual.getColumnLabels().get(0), is(TEST_COLUMN_ORDER_BY_ITEM_SEGMENT_COLUMN_LABEL));
+ assertThat(actual.getColumnLabels().get(1), is(TEST_EXPRESSION_ORDER_BY_ITEM_SEGMENT_COLUMN_LABEL));
+ assertThat(actual.getColumnLabels().get(2), is(String.valueOf(TEST_OTHER_CLASS_ORDER_BY_ITEM_INDEX)));
+ assertThat(actual.getOrderDirections().get(0), is(orderDirection));
}
- private Collection<OrderByItem> getOrderByItemCollection() {
+ private Collection<OrderByItem> getOrderByItems() {
ColumnOrderByItemSegment columnOrderByItemSegment = mock(ColumnOrderByItemSegment.class);
when(columnOrderByItemSegment.getText()).thenReturn(TEST_COLUMN_ORDER_BY_ITEM_SEGMENT_COLUMN_LABEL);
when(columnOrderByItemSegment.getOrderDirection()).thenReturn(orderDirection);
@@ -99,10 +102,6 @@ public final class OrderByTokenGeneratorTest {
OrderByItem otherClassOrderByItem = mock(OrderByItem.class);
when(otherClassOrderByItem.getSegment()).thenReturn(orderByItemSegment);
when(otherClassOrderByItem.getIndex()).thenReturn(TEST_OTHER_CLASS_ORDER_BY_ITEM_INDEX);
- Collection<OrderByItem> result = new LinkedList<>();
- result.add(columnOrderByItem);
- result.add(expressionOrderByItem);
- result.add(otherClassOrderByItem);
- return result;
+ return Arrays.asList(columnOrderByItem, expressionOrderByItem, otherClassOrderByItem);
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ProjectionsTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ProjectionsTokenGeneratorTest.java
index 02989ebc651..bcc528547df 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ProjectionsTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ProjectionsTokenGeneratorTest.java
@@ -39,9 +39,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedList;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
@@ -101,21 +101,14 @@ public final class ProjectionsTokenGeneratorTest {
@Test
public void assertGenerateSQLToken() {
- Collection<Projection> projectionCollection = new LinkedList<>();
- AggregationProjection aggregationProjection = getAggregationProjection();
- projectionCollection.add(aggregationProjection);
- DerivedProjection derivedProjection = getDerivedProjection();
- projectionCollection.add(derivedProjection);
- DerivedProjection otherDerivedProjection = getOtherDerivedProjection();
- projectionCollection.add(otherDerivedProjection);
SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
- when(selectStatementContext.getProjectionsContext().getProjections()).thenReturn(projectionCollection);
- final int testStopIndex = 2;
- when(selectStatementContext.getProjectionsContext().getStopIndex()).thenReturn(testStopIndex);
+ Collection<Projection> projections = Arrays.asList(getAggregationProjection(), getDerivedProjection(), getOtherDerivedProjection());
+ when(selectStatementContext.getProjectionsContext().getProjections()).thenReturn(projections);
+ when(selectStatementContext.getProjectionsContext().getStopIndex()).thenReturn(2);
when(selectStatementContext.getSqlStatement()).thenReturn(new MySQLSelectStatement());
- ProjectionsTokenGenerator projectionsTokenGenerator = getProjectionsTokenGenerator();
- ProjectionsToken projectionsToken = projectionsTokenGenerator.generateSQLToken(selectStatementContext);
- assertThat(projectionsToken.toString(routeUnit), is(", " + TEST_AGGREGATION_DISTINCT_PROJECTION_DISTINCT_INNER_EXPRESSION + " AS " + TEST_AGGREGATION_DISTINCT_PROJECTION_ALIAS + " "
+ ProjectionsTokenGenerator generator = getProjectionsTokenGenerator();
+ ProjectionsToken actual = generator.generateSQLToken(selectStatementContext);
+ assertThat(actual.toString(routeUnit), is(", " + TEST_AGGREGATION_DISTINCT_PROJECTION_DISTINCT_INNER_EXPRESSION + " AS " + TEST_AGGREGATION_DISTINCT_PROJECTION_ALIAS + " "
+ ", " + TEST_ACTUAL_TABLE_NAME_WRAPPED + ".null" + " AS " + TEST_DERIVED_PROJECTION_ALIAS + " "
+ ", " + TEST_OTHER_DERIVED_PROJECTION_EXPRESSION + " AS " + TEST_OTHER_DERIVED_PROJECTION_ALIAS + " "));
}
@@ -143,10 +136,8 @@ public final class ProjectionsTokenGeneratorTest {
when(ownerSegment.getIdentifier().getQuoteCharacter().wrap(anyString())).thenReturn(TEST_ACTUAL_TABLE_NAME_WRAPPED);
ColumnOrderByItemSegment oldColumnOrderByItemSegment = mock(ColumnOrderByItemSegment.class, RETURNS_DEEP_STUBS);
when(oldColumnOrderByItemSegment.getColumn().getOwner()).thenReturn(Optional.of(ownerSegment));
- OrderDirection orderDirection = mock(OrderDirection.class);
- when(oldColumnOrderByItemSegment.getOrderDirection()).thenReturn(orderDirection);
- IdentifierValue oldColumnIdentifierValue = mock(IdentifierValue.class);
- when(oldColumnOrderByItemSegment.getColumn().getIdentifier()).thenReturn(oldColumnIdentifierValue);
+ when(oldColumnOrderByItemSegment.getOrderDirection()).thenReturn(mock(OrderDirection.class));
+ when(oldColumnOrderByItemSegment.getColumn().getIdentifier()).thenReturn(mock(IdentifierValue.class));
DerivedProjection result = mock(DerivedProjection.class);
when(result.getAlias()).thenReturn(Optional.of(TEST_DERIVED_PROJECTION_ALIAS));
when(result.getDerivedProjection()).thenReturn(oldColumnOrderByItemSegment);
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingInsertValuesTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingInsertValuesTokenGeneratorTest.java
index f6e7076c1a2..cdaa36446f7 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingInsertValuesTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingInsertValuesTokenGeneratorTest.java
@@ -26,13 +26,10 @@ import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.sharding.rewrite.token.generator.impl.ShardingInsertValuesTokenGenerator;
import org.apache.shardingsphere.sharding.rewrite.token.pojo.ShardingInsertValue;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import org.junit.Test;
-import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
-import java.util.List;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
@@ -47,39 +44,29 @@ public final class ShardingInsertValuesTokenGeneratorTest {
@Test
public void assertIsGenerateSQLToken() {
- SelectStatementContext selectStatementContext = mock(SelectStatementContext.class);
- ShardingInsertValuesTokenGenerator shardingInsertValuesTokenGenerator = new ShardingInsertValuesTokenGenerator();
- assertFalse(shardingInsertValuesTokenGenerator.isGenerateSQLToken(selectStatementContext));
+ ShardingInsertValuesTokenGenerator generator = new ShardingInsertValuesTokenGenerator();
+ assertFalse(generator.isGenerateSQLToken(mock(SelectStatementContext.class)));
InsertStatementContext insertStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
when(insertStatementContext.getSqlStatement().getValues().isEmpty()).thenReturn(Boolean.TRUE);
- assertFalse(shardingInsertValuesTokenGenerator.isGenerateSQLToken(insertStatementContext));
+ assertFalse(generator.isGenerateSQLToken(insertStatementContext));
when(insertStatementContext.getSqlStatement().getValues().isEmpty()).thenReturn(Boolean.FALSE);
- assertTrue(shardingInsertValuesTokenGenerator.isGenerateSQLToken(insertStatementContext));
+ assertTrue(generator.isGenerateSQLToken(insertStatementContext));
}
@Test
public void assertGenerateSQLToken() {
- List<ExpressionSegment> expressionSegmentList = new LinkedList<>();
- InsertValuesSegment insertValuesSegment = new InsertValuesSegment(1, 2, expressionSegmentList);
- Collection<InsertValuesSegment> insertValuesSegmentCollection = new LinkedList<>();
- insertValuesSegmentCollection.add(insertValuesSegment);
- InsertValueContext insertValueContext = new InsertValueContext(expressionSegmentList, Collections.emptyList(), 4);
- List<InsertValueContext> insertValueContextList = new LinkedList<>();
- insertValueContextList.add(insertValueContext);
InsertStatementContext insertStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
- when(insertStatementContext.getInsertValueContexts()).thenReturn(insertValueContextList);
- when(insertStatementContext.getSqlStatement().getValues()).thenReturn(insertValuesSegmentCollection);
- ShardingInsertValuesTokenGenerator shardingInsertValuesTokenGenerator = new ShardingInsertValuesTokenGenerator();
- InsertValuesToken insertValuesToken = shardingInsertValuesTokenGenerator.generateSQLToken(insertStatementContext);
+ when(insertStatementContext.getInsertValueContexts()).thenReturn(Collections.singletonList(new InsertValueContext(Collections.emptyList(), Collections.emptyList(), 4)));
+ when(insertStatementContext.getSqlStatement().getValues()).thenReturn(Collections.singleton(new InsertValuesSegment(1, 2, Collections.emptyList())));
+ ShardingInsertValuesTokenGenerator generator = new ShardingInsertValuesTokenGenerator();
+ InsertValuesToken insertValuesToken = generator.generateSQLToken(insertStatementContext);
assertThat(insertValuesToken.getInsertValues().size(), is(1));
- Collection<DataNode> dataNodes = new LinkedList<>();
- final String testDatasource = "testDatasource";
- final String testTable = "testTable";
- dataNodes.add(new DataNode(testDatasource, testTable));
+ String testDatasource = "testDatasource";
+ String testTable = "testTable";
RouteContext routeContext = new RouteContext();
- routeContext.getOriginalDataNodes().add(dataNodes);
- shardingInsertValuesTokenGenerator.setRouteContext(routeContext);
- insertValuesToken = shardingInsertValuesTokenGenerator.generateSQLToken(insertStatementContext);
+ routeContext.getOriginalDataNodes().add(Collections.singleton(new DataNode(testDatasource, testTable)));
+ generator.setRouteContext(routeContext);
+ insertValuesToken = generator.generateSQLToken(insertStatementContext);
assertThat(insertValuesToken.getInsertValues().get(0), instanceOf(ShardingInsertValue.class));
ShardingInsertValue generatedShardingInsertValue = (ShardingInsertValue) insertValuesToken.getInsertValues().get(0);
assertThat((new LinkedList<>(generatedShardingInsertValue.getDataNodes())).get(0).getDataSourceName(), is(testDatasource));
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/TableTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/TableTokenGeneratorTest.java
index 619b25d67dc..e346bd9aaff 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/TableTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/TableTokenGeneratorTest.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.sharding.rewrite.token;
import org.apache.shardingsphere.infra.binder.statement.ddl.CreateDatabaseStatementContext;
import org.apache.shardingsphere.infra.binder.statement.ddl.CreateTableStatementContext;
import org.apache.shardingsphere.sharding.rewrite.token.generator.impl.TableTokenGenerator;
-import org.apache.shardingsphere.sharding.rewrite.token.pojo.TableToken;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
@@ -28,9 +27,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Tab
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import org.junit.Test;
-import java.util.Collection;
+import java.util.ArrayList;
import java.util.Collections;
-import java.util.LinkedList;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
@@ -49,14 +47,10 @@ public final class TableTokenGeneratorTest {
tableTokenGenerator.setShardingRule(shardingRule);
CreateDatabaseStatementContext createDatabaseStatementContext = mock(CreateDatabaseStatementContext.class);
assertThat(tableTokenGenerator.generateSQLTokens(createDatabaseStatementContext), is(Collections.emptyList()));
- final int testStartIndex = 3;
+ int testStartIndex = 3;
TableNameSegment tableNameSegment = new TableNameSegment(testStartIndex, 8, new IdentifierValue("test"));
- SimpleTableSegment simpleTableSegment = new SimpleTableSegment(tableNameSegment);
- Collection<SimpleTableSegment> simpleTableSegmentCollection = new LinkedList<>();
- simpleTableSegmentCollection.add(simpleTableSegment);
CreateTableStatementContext createTableStatementContext = mock(CreateTableStatementContext.class);
- when(createTableStatementContext.getAllTables()).thenReturn(simpleTableSegmentCollection);
- Collection<TableToken> result = tableTokenGenerator.generateSQLTokens(createTableStatementContext);
- assertThat((new LinkedList<>(result)).get(0).getStartIndex(), is(testStartIndex));
+ when(createTableStatementContext.getAllTables()).thenReturn(Collections.singleton(new SimpleTableSegment(tableNameSegment)));
+ assertThat((new ArrayList<>(tableTokenGenerator.generateSQLTokens(createTableStatementContext))).get(0).getStartIndex(), is(testStartIndex));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingAlgorithmsQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingAlgorithmsQueryResultSet.java
index 9e042cd9219..2960b889dee 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingAlgorithmsQueryResultSet.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingAlgorithmsQueryResultSet.java
@@ -95,10 +95,10 @@ public final class UnusedShardingAlgorithmsQueryResultSet implements DistSQLResu
}
private void getUnusedShardingAlgorithms(final ShardingRuleConfiguration shardingRuleConfig) {
- Collection<String> inUsedSet = getUsedShardingAlgorithms(shardingRuleConfig);
+ Collection<String> inUsedAlgorithms = getUsedShardingAlgorithms(shardingRuleConfig);
Map<String, ShardingSphereAlgorithmConfiguration> map = new HashMap<>();
for (Entry<String, ShardingSphereAlgorithmConfiguration> each : shardingRuleConfig.getShardingAlgorithms().entrySet()) {
- if (!inUsedSet.contains(each.getKey())) {
+ if (!inUsedAlgorithms.contains(each.getKey())) {
map.put(each.getKey(), each.getValue());
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingKeyGeneratorsQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingKeyGeneratorsQueryResultSet.java
index faf95153f78..84d339ab608 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingKeyGeneratorsQueryResultSet.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingKeyGeneratorsQueryResultSet.java
@@ -95,10 +95,10 @@ public final class UnusedShardingKeyGeneratorsQueryResultSet implements DistSQLR
}
private void getUnusedKeyGenerators(final ShardingRuleConfiguration shardingRuleConfig) {
- Collection<String> inUsedSet = getUsedKeyGenerators(shardingRuleConfig);
+ Collection<String> inUsedKeyGenerators = getUsedKeyGenerators(shardingRuleConfig);
Map<String, ShardingSphereAlgorithmConfiguration> map = new HashMap<>();
for (Entry<String, ShardingSphereAlgorithmConfiguration> each : shardingRuleConfig.getKeyGenerators().entrySet()) {
- if (!inUsedSet.contains(each.getKey())) {
+ if (!inUsedKeyGenerators.contains(each.getKey())) {
map.put(each.getKey(), each.getValue());
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootStarterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootStarterTest.java
index eabf582689a..94d55d399c4 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootStarterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootStarterTest.java
@@ -101,8 +101,8 @@ public class ShardingSpringBootStarterTest {
private void assertShardingConfigurationBindingTableGroups() {
assertThat(shardingRuleConfig.getBindingTableGroups().size(), is(1));
- List<String> bindingTableGroupsList = new ArrayList<>(shardingRuleConfig.getBindingTableGroups());
- assertThat(bindingTableGroupsList.get(0), is("t_order,t_order_item"));
+ List<String> bindingTableGroups = new ArrayList<>(shardingRuleConfig.getBindingTableGroups());
+ assertThat(bindingTableGroups.get(0), is("t_order,t_order_item"));
}
private void assertShardingConfigurationBroadcastTables() {
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java
index caf32a8f423..a3fb54626c1 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java
@@ -19,12 +19,12 @@ package org.apache.shardingsphere.infra.metadata.user;
import org.junit.Test;
-import java.util.LinkedList;
-import java.util.Collection;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -32,14 +32,13 @@ public final class ShardingSphereUsersTest {
@Test
public void assertFindUser() {
- Collection<ShardingSphereUser> shardingSphereUserCollection = new LinkedList<>();
ShardingSphereUser shardingSphereUser = mock(ShardingSphereUser.class);
Grantee testGrantee = mock(Grantee.class);
when(shardingSphereUser.getGrantee()).thenReturn(testGrantee);
- shardingSphereUserCollection.add(shardingSphereUser);
- ShardingSphereUsers shardingSphereUsers = new ShardingSphereUsers(shardingSphereUserCollection);
- assertThat(shardingSphereUsers.findUser(testGrantee).get(), is(shardingSphereUser));
+ ShardingSphereUsers actual = new ShardingSphereUsers(Collections.singleton(shardingSphereUser));
+ assertTrue(actual.findUser(testGrantee).isPresent());
+ assertThat(actual.findUser(testGrantee).get(), is(shardingSphereUser));
Grantee notExistGrantee = mock(Grantee.class);
- assertFalse(shardingSphereUsers.findUser(notExistGrantee).isPresent());
+ assertFalse(actual.findUser(notExistGrantee).isPresent());
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
index 86eff8dd6bf..6832a5f4e60 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
@@ -48,10 +48,10 @@ public abstract class MemoryMergedResult<T extends ShardingSphereRule> implement
private boolean wasNull;
protected MemoryMergedResult(final T rule, final ShardingSphereSchema schema, final SQLStatementContext<?> sqlStatementContext, final List<QueryResult> queryResults) throws SQLException {
- List<MemoryQueryResultRow> memoryQueryResultRowList = init(rule, schema, sqlStatementContext, queryResults);
- memoryResultSetRows = memoryQueryResultRowList.iterator();
- if (!memoryQueryResultRowList.isEmpty()) {
- currentResultSetRow = memoryQueryResultRowList.get(0);
+ List<MemoryQueryResultRow> memoryQueryResultRows = init(rule, schema, sqlStatementContext, queryResults);
+ memoryResultSetRows = memoryQueryResultRows.iterator();
+ if (!memoryQueryResultRows.isEmpty()) {
+ currentResultSetRow = memoryQueryResultRows.get(0);
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertValueTest.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertValueTest.java
index d9ba57cffe7..8a08a04af0b 100644
--- a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertValueTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/InsertValueTest.java
@@ -33,7 +33,7 @@ public final class InsertValueTest {
@Test
public void assertToString() {
- List<ExpressionSegment> expressionSegmentList = new ArrayList<>(3);
+ List<ExpressionSegment> expressionSegments = new ArrayList<>(3);
ParameterMarkerExpressionSegment parameterMarkerExpressionSegment = new ParameterMarkerExpressionSegment(1, 1, 1);
LiteralExpressionSegment literalExpressionSegment = new LiteralExpressionSegment(2, 2, "literals");
ComplexExpressionSegment complexExpressionSegment = new ComplexExpressionSegment() {
@@ -53,10 +53,10 @@ public final class InsertValueTest {
return 3;
}
};
- expressionSegmentList.add(parameterMarkerExpressionSegment);
- expressionSegmentList.add(literalExpressionSegment);
- expressionSegmentList.add(complexExpressionSegment);
- InsertValue insertValue = new InsertValue(expressionSegmentList);
+ expressionSegments.add(parameterMarkerExpressionSegment);
+ expressionSegments.add(literalExpressionSegment);
+ expressionSegments.add(complexExpressionSegment);
+ InsertValue insertValue = new InsertValue(expressionSegments);
String actualToString = insertValue.toString();
String expectedToString = "(?, 'literals', complexExpressionSegment)";
assertThat(actualToString, is(expectedToString));
diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/context/RouteContextTest.java b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/context/RouteContextTest.java
index 362ed98a0bf..69ca5902034 100644
--- a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/context/RouteContextTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/context/RouteContextTest.java
@@ -89,9 +89,7 @@ public final class RouteContextTest {
@Test
public void assertGetActualTableNameGroups() {
- Set<String> logicTableSet = new HashSet<>();
- logicTableSet.add(LOGIC_TABLE);
- List<Set<String>> actual = multiRouteContext.getActualTableNameGroups(DATASOURCE_NAME_1, logicTableSet);
+ List<Set<String>> actual = multiRouteContext.getActualTableNameGroups(DATASOURCE_NAME_1, new HashSet<>(Collections.singleton(LOGIC_TABLE)));
assertThat(actual.size(), is(1));
assertTrue(actual.get(0).contains(ACTUAL_TABLE));
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/parser/DataSourceBeanDefinitionParser.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/parser/DataSourceBeanDefinitionParser.java
index 1017ee876a9..899cb629114 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/parser/DataSourceBeanDefinitionParser.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/parser/DataSourceBeanDefinitionParser.java
@@ -101,9 +101,9 @@ public final class DataSourceBeanDefinitionParser extends AbstractBeanDefinition
}
private Collection<RuntimeBeanReference> parseRuleConfigurations(final Element element) {
- List<String> ruleIdList = Splitter.on(",").trimResults().splitToList(element.getAttribute(DataSourceBeanDefinitionTag.RULE_REFS_ATTRIBUTE));
- Collection<RuntimeBeanReference> result = new ManagedList<>(ruleIdList.size());
- for (String each : ruleIdList) {
+ List<String> ruleIds = Splitter.on(",").trimResults().splitToList(element.getAttribute(DataSourceBeanDefinitionTag.RULE_REFS_ATTRIBUTE));
+ Collection<RuntimeBeanReference> result = new ManagedList<>(ruleIds.size());
+ for (String each : ruleIds) {
result.add(new RuntimeBeanReference(each));
}
return result;
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java
index 9df87c59c79..c003ead4604 100644
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java
+++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java
@@ -73,8 +73,7 @@ public final class StoragePrivilegeBuilderTest {
private ShardingSphereMetaData mockShardingSphereMetaData(final Collection<ShardingSphereUser> users) throws SQLException {
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
DataSource dataSource = mockDataSourceForPrivileges(users);
- Collection<DataSource> dataSourceList = Collections.singletonList(dataSource);
- when(result.getResource().getAllInstanceDataSources()).thenReturn(dataSourceList);
+ when(result.getResource().getAllInstanceDataSources()).thenReturn(Collections.singleton(dataSource));
when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
return result;
}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java
index 333cbf62433..2952aafc09d 100644
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java
+++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java
@@ -126,12 +126,12 @@ public final class OraclePrivilegeHandlerTest {
private DataSource mockDataSource(final Collection<ShardingSphereUser> users) throws SQLException {
ResultSet sysPrivilegeResultSet = mockSysPrivilegeResultSet();
DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- String sysPrivilegeSql = "SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE IN (%s)";
+ String sysPrivilegeSQL = "SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE IN (%s)";
String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- when(result.getConnection().createStatement().executeQuery(String.format(sysPrivilegeSql, userList))).thenReturn(sysPrivilegeResultSet);
+ when(result.getConnection().createStatement().executeQuery(String.format(sysPrivilegeSQL, userList))).thenReturn(sysPrivilegeResultSet);
ResultSet tabPrivilegeResultSet = mockTabPrivilegeResultSet();
- String tabPrivilegeSql = "SELECT GRANTEE, TABLE_SCHEMA, TABLE_NAME, PRIVILEGE, GRANTABLE, INHERITED FROM ALL_TAB_PRIVS WHERE GRANTEE IN (%s)";
- when(result.getConnection().createStatement().executeQuery(String.format(tabPrivilegeSql, userList))).thenReturn(tabPrivilegeResultSet);
+ String tabPrivilegeSQL = "SELECT GRANTEE, TABLE_SCHEMA, TABLE_NAME, PRIVILEGE, GRANTABLE, INHERITED FROM ALL_TAB_PRIVS WHERE GRANTEE IN (%s)";
+ when(result.getConnection().createStatement().executeQuery(String.format(tabPrivilegeSQL, userList))).thenReturn(tabPrivilegeResultSet);
return result;
}
diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java
index 264a09c240b..c55c0a10c5f 100644
--- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java
+++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java
@@ -134,9 +134,9 @@ public final class SingleTableSQLRouterTest {
SimpleTableSegment simpleTableSegment = new SimpleTableSegment(tableNameSegment);
CreateTableStatement createTableStatement = new MySQLCreateTableStatement();
createTableStatement.setTable(simpleTableSegment);
- List<Object> parametersList = new LinkedList<>();
+ List<Object> parameters = new LinkedList<>();
SQLStatementContext<CreateTableStatement> sqlStatementContext = new CreateTableStatementContext(createTableStatement);
- return new LogicSQL(sqlStatementContext, "create table", parametersList);
+ return new LogicSQL(sqlStatementContext, "create table", parameters);
}
private Map<String, DataSource> createSingleDataSourceMap() {
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardin [...]
index 20a99258080..fad93ef1be0 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
@@ -95,16 +95,16 @@ public final class H2Repository implements StandalonePersistRepository {
try (
PreparedStatement statement = connection.prepareStatement("SELECT key FROM REPOSITORY WHERE parent = '" + key + "'");
ResultSet resultSet = statement.executeQuery()) {
- List<String> resultChildrenList = new ArrayList<>(10);
+ List<String> resultChildren = new ArrayList<>(10);
while (resultSet.next()) {
String childrenKey = resultSet.getString("key");
if (Strings.isNullOrEmpty(childrenKey)) {
continue;
}
int lastIndexOf = childrenKey.lastIndexOf(SEPARATOR);
- resultChildrenList.add(childrenKey.substring(lastIndexOf + 1));
+ resultChildren.add(childrenKey.substring(lastIndexOf + 1));
}
- return resultChildrenList;
+ return resultChildren;
} catch (final SQLException ex) {
log.error("Get children h2 data by key: {} failed", key, ex);
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
index 226bbadeeca..09048a43902 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
@@ -1216,8 +1216,7 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
ExpressionSegment value = (ExpressionSegment) visit(ctx.assignmentValue());
List<ColumnSegment> columnSegments = new LinkedList<>();
columnSegments.add(column);
- AssignmentSegment result = new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
- return result;
+ return new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
}
@Override
@@ -1555,11 +1554,11 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
joinTableSource.setCondition(condition);
}
if (null != ctx.USING()) {
- List<ColumnSegment> columnSegmentList = new LinkedList<>();
- for (ColumnNameContext cname : ctx.columnNames().columnName()) {
- columnSegmentList.add((ColumnSegment) visit(cname));
+ List<ColumnSegment> columnSegments = new LinkedList<>();
+ for (ColumnNameContext each : ctx.columnNames().columnName()) {
+ columnSegments.add((ColumnSegment) visit(each));
}
- joinTableSource.setUsing(columnSegmentList);
+ joinTableSource.setUsing(columnSegments);
}
return joinTableSource;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java
index bf88fdad338..2bda32a4a35 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java
@@ -169,13 +169,7 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
@Override
public ASTNode visitInsert(final InsertContext ctx) {
// TODO :FIXME, since there is no segment for insertValuesClause, InsertStatement is created by sub rule.
- if (null != ctx.insertSingleTable()) {
- OracleInsertStatement result = (OracleInsertStatement) visit(ctx.insertSingleTable());
- return result;
- } else {
- OracleInsertStatement result = (OracleInsertStatement) visit(ctx.insertMultiTable());
- return result;
- }
+ return null == ctx.insertSingleTable() ? visit(ctx.insertMultiTable()) : visit(ctx.insertSingleTable());
}
@Override
@@ -255,22 +249,19 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
@Override
public ASTNode visitDmlTableClause(final DmlTableClauseContext ctx) {
- SimpleTableSegment result = (SimpleTableSegment) visit(ctx.tableName());
- return result;
+ return visit(ctx.tableName());
}
@Override
public ASTNode visitDmlSubqueryClause(final DmlSubqueryClauseContext ctx) {
OracleSelectStatement subquery = (OracleSelectStatement) visit(ctx.selectSubquery());
- SubquerySegment result = new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), subquery);
- return result;
+ return new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), subquery);
}
@Override
public ASTNode visitTableCollectionExpr(final TableCollectionExprContext ctx) {
OracleSelectStatement subquery = (OracleSelectStatement) visit(ctx.collectionExpr().selectSubquery());
- SubquerySegment result = new SubquerySegment(ctx.collectionExpr().selectSubquery().start.getStartIndex(), ctx.collectionExpr().selectSubquery().stop.getStopIndex(), subquery);
- return result;
+ return new SubquerySegment(ctx.collectionExpr().selectSubquery().start.getStartIndex(), ctx.collectionExpr().selectSubquery().stop.getStopIndex(), subquery);
}
@Override
@@ -330,19 +321,15 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
@Override
public ASTNode visitUpdateSpecification(final UpdateSpecificationContext ctx) {
- TableSegment result;
if (null != ctx.dmlTableExprClause().dmlTableClause()) {
- result = (TableSegment) visit(ctx.dmlTableExprClause().dmlTableClause());
- } else if (null != ctx.dmlTableExprClause().dmlSubqueryClause()) {
+ return visit(ctx.dmlTableExprClause().dmlTableClause());
+ }
+ if (null != ctx.dmlTableExprClause().dmlSubqueryClause()) {
SubquerySegment subquerySegment = (SubquerySegment) visit(ctx.dmlTableExprClause().dmlSubqueryClause());
- SubqueryTableSegment subqueryTableSegment = new SubqueryTableSegment(subquerySegment);
- result = (TableSegment) subqueryTableSegment;
- } else {
- SubquerySegment subquerySegment = (SubquerySegment) visit(ctx.dmlTableExprClause().tableCollectionExpr());
- SubqueryTableSegment subqueryTableSegment = new SubqueryTableSegment(subquerySegment);
- result = (TableSegment) subqueryTableSegment;
+ return new SubqueryTableSegment(subquerySegment);
}
- return result;
+ SubquerySegment subquerySegment = (SubquerySegment) visit(ctx.dmlTableExprClause().tableCollectionExpr());
+ return new SubqueryTableSegment(subquerySegment);
}
@Override
@@ -355,14 +342,12 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
} else {
assignments.add((AssignmentSegment) visit(ctx.updateSetValueClause()));
}
- SetAssignmentSegment result = new SetAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), assignments);
- return result;
+ return new SetAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), assignments);
}
@Override
public ASTNode visitUpdateSetColumnClause(final UpdateSetColumnClauseContext ctx) {
- AssignmentSegment result = 1 == ctx.columnName().size() ? createAssignmentSegmentFromSingleColumnAssignment(ctx) : createAssignmentSegmentFromMultiColumnAssignment(ctx);
- return result;
+ return 1 == ctx.columnName().size() ? createAssignmentSegmentFromSingleColumnAssignment(ctx) : createAssignmentSegmentFromMultiColumnAssignment(ctx);
}
private AssignmentSegment createAssignmentSegmentFromSingleColumnAssignment(final UpdateSetColumnClauseContext ctx) {
@@ -371,21 +356,20 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
columnSegments.add(column);
if (null != ctx.expr()) {
ExpressionSegment value = (ExpressionSegment) visit(ctx.expr());
- AssignmentSegment result = new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
- return result;
- } else if (null != ctx.selectSubquery()) {
+ return new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
+ }
+ if (null != ctx.selectSubquery()) {
SubquerySegment subquerySegment = new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(),
(OracleSelectStatement) visit(ctx.selectSubquery()));
SubqueryExpressionSegment value = new SubqueryExpressionSegment(subquerySegment);
AssignmentSegment result = new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
result.getColumns().add(column);
return result;
- } else {
- CommonExpressionSegment value = new CommonExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.DEFAULT().getText());
- AssignmentSegment result = new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
- result.getColumns().add(column);
- return result;
}
+ CommonExpressionSegment value = new CommonExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.DEFAULT().getText());
+ AssignmentSegment result = new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
+ result.getColumns().add(column);
+ return result;
}
private AssignmentSegment createAssignmentSegmentFromMultiColumnAssignment(final UpdateSetColumnClauseContext ctx) {
@@ -396,8 +380,7 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
SubquerySegment subquerySegment =
new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), (OracleSelectStatement) visit(ctx.selectSubquery()));
SubqueryExpressionSegment value = new SubqueryExpressionSegment(subquerySegment);
- AssignmentSegment result = new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
- return result;
+ return new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
}
@Override
@@ -432,10 +415,7 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
@Override
public ASTNode visitAssignmentValue(final AssignmentValueContext ctx) {
ExprContext expr = ctx.expr();
- if (null != expr) {
- return visit(expr);
- }
- return new CommonExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.getText());
+ return null == expr ? new CommonExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.getText()) : visit(expr);
}
@Override
@@ -455,19 +435,15 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
@Override
public ASTNode visitDeleteSpecification(final DeleteSpecificationContext ctx) {
- TableSegment result;
if (null != ctx.dmlTableExprClause().dmlTableClause()) {
- result = (TableSegment) visit(ctx.dmlTableExprClause().dmlTableClause());
- } else if (null != ctx.dmlTableExprClause().dmlSubqueryClause()) {
+ return visit(ctx.dmlTableExprClause().dmlTableClause());
+ }
+ if (null != ctx.dmlTableExprClause().dmlSubqueryClause()) {
SubquerySegment subquerySegment = (SubquerySegment) visit(ctx.dmlTableExprClause().dmlSubqueryClause());
- SubqueryTableSegment subqueryTableSegment = new SubqueryTableSegment(subquerySegment);
- result = (TableSegment) subqueryTableSegment;
- } else {
- SubquerySegment subquerySegment = (SubquerySegment) visit(ctx.dmlTableExprClause().tableCollectionExpr());
- SubqueryTableSegment subqueryTableSegment = new SubqueryTableSegment(subquerySegment);
- result = (TableSegment) subqueryTableSegment;
+ return new SubqueryTableSegment(subquerySegment);
}
- return result;
+ SubquerySegment subquerySegment = (SubquerySegment) visit(ctx.dmlTableExprClause().tableCollectionExpr());
+ return new SubqueryTableSegment(subquerySegment);
}
@Override
@@ -589,15 +565,13 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
private SubquerySegment extractSelectSubqueryValueFromMultiColumnForLoop(final MultiColumnForLoopContext ctx) {
OracleSelectStatement subquery = (OracleSelectStatement) visit(ctx.selectSubquery());
- SubquerySegment result = new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), subquery);
- return result;
+ return new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), subquery);
}
@Override
public ASTNode visitReferenceModel(final ReferenceModelContext ctx) {
OracleSelectStatement subquery = (OracleSelectStatement) visit(ctx.selectSubquery());
- SubquerySegment result = new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), subquery);
- return result;
+ return new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), subquery);
}
@Override
@@ -833,11 +807,11 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
joinTableSource.setCondition(condition);
}
if (null != ctx.USING()) {
- List<ColumnSegment> columnSegmentList = new LinkedList<>();
+ List<ColumnSegment> columnSegments = new LinkedList<>();
for (ColumnNameContext cname : ctx.columnNames().columnName()) {
- columnSegmentList.add((ColumnSegment) visit(cname));
+ columnSegments.add((ColumnSegment) visit(cname));
}
- joinTableSource.setUsing(columnSegmentList);
+ joinTableSource.setUsing(columnSegments);
}
return joinTableSource;
}
@@ -857,8 +831,7 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
@Override
public ASTNode visitCollectionExpr(final CollectionExprContext ctx) {
OracleSelectStatement subquery = (OracleSelectStatement) visit(ctx.selectSubquery());
- SubquerySegment result = new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), subquery);
- return result;
+ return new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), subquery);
}
@Override
@@ -879,14 +852,12 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
@Override
public ASTNode visitContainersClause(final ContainersClauseContext ctx) {
- SimpleTableSegment result = (SimpleTableSegment) visit(ctx.tableName());
- return result;
+ return visit(ctx.tableName());
}
@Override
public ASTNode visitShardsClause(final ShardsClauseContext ctx) {
- SimpleTableSegment result = (SimpleTableSegment) visit(ctx.tableName());
- return result;
+ return visit(ctx.tableName());
}
@Override
@@ -953,9 +924,7 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
}
private Collection<OrderByItemSegment> generateOrderByItemSegmentsFromRollupCubeClause(final RollupCubeClauseContext ctx) {
- Collection<OrderByItemSegment> result = new LinkedList<>();
- result.addAll(generateOrderByItemSegmentsFromGroupingExprList(ctx.groupingExprList()));
- return result;
+ return new LinkedList<>(generateOrderByItemSegmentsFromGroupingExprList(ctx.groupingExprList()));
}
private Collection<OrderByItemSegment> generateOrderByItemSegmentsFromGroupingSetsClause(final GroupingSetsClauseContext ctx) {
@@ -1118,17 +1087,13 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
ExpressionSegment value = (ExpressionSegment) visit(ctx.mergeAssignmentValue());
List<ColumnSegment> columnSegments = new LinkedList<>();
columnSegments.add(column);
- AssignmentSegment result = new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
- return result;
+ return new ColumnAssignmentSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnSegments, value);
}
@Override
public ASTNode visitMergeAssignmentValue(final MergeAssignmentValueContext ctx) {
ExprContext expr = ctx.expr();
- if (null != expr) {
- return visit(expr);
- }
- return new CommonExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.getText());
+ return null == expr ? new CommonExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.getText()) : visit(expr);
}
@Override
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92DMLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92DMLStatementSQLVisitor.java
index 19a37182df8..0d7193e245d 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92DMLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92DMLStatementSQLVisitor.java
@@ -451,11 +451,11 @@ public final class SQL92DMLStatementSQLVisitor extends SQL92StatementSQLVisitor
joinTableSource.setCondition(condition);
}
if (null != ctx.USING()) {
- List<ColumnSegment> columnSegmentList = new LinkedList<>();
+ List<ColumnSegment> columnSegments = new LinkedList<>();
for (ColumnNameContext cname : ctx.columnNames().columnName()) {
- columnSegmentList.add((ColumnSegment) visit(cname));
+ columnSegments.add((ColumnSegment) visit(cname));
}
- joinTableSource.setUsing(columnSegmentList);
+ joinTableSource.setUsing(columnSegments);
}
return joinTableSource;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
index fdfacb9ae1d..84873e56f9f 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
@@ -264,21 +264,18 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
@Override
public final ASTNode visitIdentifier(final IdentifierContext ctx) {
- IdentifierValue result = (IdentifierValue) (null != ctx.regularIdentifier() ? visit(ctx.regularIdentifier()) : visit(ctx.delimitedIdentifier()));
- return result;
+ return null != ctx.regularIdentifier() ? visit(ctx.regularIdentifier()) : visit(ctx.delimitedIdentifier());
}
@Override
public final ASTNode visitRegularIdentifier(final RegularIdentifierContext ctx) {
UnreservedWordContext unreservedWord = ctx.unreservedWord();
- IdentifierValue result = null != unreservedWord ? (IdentifierValue) visit(unreservedWord) : new IdentifierValue(ctx.getText());
- return result;
+ return null == unreservedWord ? new IdentifierValue(ctx.getText()) : (IdentifierValue) visit(unreservedWord);
}
@Override
public final ASTNode visitDelimitedIdentifier(final DelimitedIdentifierContext ctx) {
- IdentifierValue result = new IdentifierValue(ctx.getText());
- return result;
+ return new IdentifierValue(ctx.getText());
}
@Override
@@ -1209,11 +1206,11 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
joinTableSource.setCondition(condition);
}
if (null != ctx.USING()) {
- List<ColumnSegment> columnSegmentList = new LinkedList<>();
+ List<ColumnSegment> columnSegments = new LinkedList<>();
for (ColumnNameContext cname : ctx.columnNames().columnName()) {
- columnSegmentList.add((ColumnSegment) visit(cname));
+ columnSegments.add((ColumnSegment) visit(cname));
}
- joinTableSource.setUsing(columnSegmentList);
+ joinTableSource.setUsing(columnSegments);
}
return joinTableSource;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtil.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtil.java
index e60275a8ed4..9bf89f1dfac 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtil.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtil.java
@@ -122,19 +122,19 @@ public final class SafeNumberOperationUtil {
* Execute collection equals method by safe mode.
*
* @param sources source collection
- * @param targetCollection target collection
+ * @param targets target collection
* @return whether the element in source collection and target collection are all same
*/
- public static boolean safeCollectionEquals(final Collection<Comparable<?>> sources, final Collection<Comparable<?>> targetCollection) {
- List<Comparable<?>> collection = new ArrayList<>(sources);
- collection.addAll(targetCollection);
- Optional<Class<?>> clazz = getTargetNumericType(collection);
+ public static boolean safeCollectionEquals(final Collection<Comparable<?>> sources, final Collection<Comparable<?>> targets) {
+ List<Comparable<?>> all = new ArrayList<>(sources);
+ all.addAll(targets);
+ Optional<Class<?>> clazz = getTargetNumericType(all);
if (!clazz.isPresent()) {
- return sources.equals(targetCollection);
+ return sources.equals(targets);
}
- List<Comparable<?>> sourceClazzCollection = sources.stream().map(each -> parseNumberByClazz(each.toString(), clazz.get())).collect(Collectors.toList());
- List<Comparable<?>> targetClazzCollection = targetCollection.stream().map(each -> parseNumberByClazz(each.toString(), clazz.get())).collect(Collectors.toList());
- return sourceClazzCollection.equals(targetClazzCollection);
+ List<Comparable<?>> sourceClasses = sources.stream().map(each -> parseNumberByClazz(each.toString(), clazz.get())).collect(Collectors.toList());
+ List<Comparable<?>> targetClasses = targets.stream().map(each -> parseNumberByClazz(each.toString(), clazz.get())).collect(Collectors.toList());
+ return sourceClasses.equals(targetClasses);
}
private static Class<?> getRangeTargetNumericType(final Range<Comparable<?>> sourceRange, final Range<Comparable<?>> targetRange) {
@@ -163,19 +163,19 @@ public final class SafeNumberOperationUtil {
}
private static Optional<Class<?>> getTargetNumericType(final List<Comparable<?>> endpoints) {
- Set<Class<?>> clazzSet = endpoints.stream().filter(Objects::nonNull).map(Comparable::getClass).collect(Collectors.toSet());
+ Set<Class<?>> classes = endpoints.stream().filter(Objects::nonNull).map(Comparable::getClass).collect(Collectors.toSet());
Class<?> clazz = null;
- if (clazzSet.contains(BigDecimal.class)) {
+ if (classes.contains(BigDecimal.class)) {
clazz = BigDecimal.class;
- } else if (clazzSet.contains(Double.class)) {
+ } else if (classes.contains(Double.class)) {
clazz = Double.class;
- } else if (clazzSet.contains(Float.class)) {
+ } else if (classes.contains(Float.class)) {
clazz = Float.class;
- } else if (clazzSet.contains(BigInteger.class)) {
+ } else if (classes.contains(BigInteger.class)) {
clazz = BigInteger.class;
- } else if (clazzSet.contains(Long.class)) {
+ } else if (classes.contains(Long.class)) {
clazz = Long.class;
- } else if (clazzSet.contains(Integer.class)) {
+ } else if (classes.contains(Integer.class)) {
clazz = Integer.class;
}
return Optional.ofNullable(clazz);
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilTest.java
index f285950e213..f2e2de0f14a 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilTest.java
@@ -179,44 +179,44 @@ public final class SafeNumberOperationUtilTest {
@Test
public void assertSafeCollectionEqualsForInteger() {
- List<Comparable<?>> sourceCollection = Arrays.asList(10, 12);
- List<Comparable<?>> targetCollection = Arrays.asList(10, 12);
- assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
+ List<Comparable<?>> sources = Arrays.asList(10, 12);
+ List<Comparable<?>> targets = Arrays.asList(10, 12);
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sources, targets));
}
@Test
public void assertSafeCollectionEqualsForLong() {
- List<Comparable<?>> sourceCollection = Arrays.asList(10, 12);
- List<Comparable<?>> targetCollection = Arrays.asList(10L, 12L);
- assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
+ List<Comparable<?>> sources = Arrays.asList(10, 12);
+ List<Comparable<?>> targets = Arrays.asList(10L, 12L);
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sources, targets));
}
@Test
public void assertSafeCollectionEqualsForBigInteger() {
- List<Comparable<?>> sourceCollection = Arrays.asList(10, 12);
- List<Comparable<?>> targetCollection = Arrays.asList(BigInteger.valueOf(10), BigInteger.valueOf(12L));
- assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
+ List<Comparable<?>> sources = Arrays.asList(10, 12);
+ List<Comparable<?>> targets = Arrays.asList(BigInteger.valueOf(10), BigInteger.valueOf(12L));
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sources, targets));
}
@Test
public void assertSafeCollectionEqualsForFloat() {
- List<Comparable<?>> sourceCollection = Arrays.asList(10.01F, 12.01F);
- List<Comparable<?>> targetCollection = Arrays.asList(10.01F, 12.01F);
- assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
+ List<Comparable<?>> sources = Arrays.asList(10.01F, 12.01F);
+ List<Comparable<?>> targets = Arrays.asList(10.01F, 12.01F);
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sources, targets));
}
@Test
public void assertSafeCollectionEqualsForDouble() {
- List<Comparable<?>> sourceCollection = Arrays.asList(10.01, 12.01);
- List<Comparable<?>> targetCollection = Arrays.asList(10.01F, 12.01);
- assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
+ List<Comparable<?>> sources = Arrays.asList(10.01, 12.01);
+ List<Comparable<?>> targets = Arrays.asList(10.01F, 12.01);
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sources, targets));
}
@Test
public void assertSafeCollectionEqualsForBigDecimal() {
- List<Comparable<?>> sourceCollection = Arrays.asList(10.01, 12.01);
- List<Comparable<?>> targetCollection = Arrays.asList(BigDecimal.valueOf(10.01), BigDecimal.valueOf(12.01));
- assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
+ List<Comparable<?>> sources = Arrays.asList(10.01, 12.01);
+ List<Comparable<?>> targets = Arrays.asList(BigDecimal.valueOf(10.01), BigDecimal.valueOf(12.01));
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sources, targets));
}
@Test
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/BaseITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/BaseITCase.java
index d825d7b0e81..73b380f6c4b 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/BaseITCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/BaseITCase.java
@@ -176,16 +176,16 @@ public abstract class BaseITCase {
}
assertThat(actualStatusMap.values().stream().filter(StringUtils::isNotBlank).collect(Collectors.toSet()).size(), is(1));
jdbcTemplate.execute(String.format("STOP SCALING SOURCE WRITING %s", jobId));
- List<Map<String, Object>> checkScalingResList = jdbcTemplate.queryForList(String.format("CHECK SCALING %s BY TYPE (NAME=DATA_MATCH)", jobId));
- for (Map<String, Object> entry : checkScalingResList) {
+ List<Map<String, Object>> checkScalingResults = jdbcTemplate.queryForList(String.format("CHECK SCALING %s BY TYPE (NAME=DATA_MATCH)", jobId));
+ for (Map<String, Object> entry : checkScalingResults) {
assertTrue(Boolean.parseBoolean(entry.get("records_content_matched").toString()));
}
jdbcTemplate.execute(String.format("APPLY SCALING %s", jobId));
// TODO make sure the scaling job was applied
ThreadUtil.sleep(2000);
- List<Map<String, Object>> previewResList = jdbcTemplate.queryForList("PREVIEW SELECT COUNT(1) FROM t_order");
- Set<Object> originalSourceList = previewResList.stream().map(each -> each.get("data_source_name")).collect(Collectors.toSet());
- assertThat(originalSourceList, is(Sets.newHashSet("ds_2", "ds_3", "ds_4")));
+ List<Map<String, Object>> previewResults = jdbcTemplate.queryForList("PREVIEW SELECT COUNT(1) FROM t_order");
+ Set<Object> originalSources = previewResults.stream().map(each -> each.get("data_source_name")).collect(Collectors.toSet());
+ assertThat(originalSources, is(Sets.newHashSet("ds_2", "ds_3", "ds_4")));
}
@After
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLManualScalingCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLManualScalingCase.java
index cad1af73bad..d9907cd08b2 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLManualScalingCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLManualScalingCase.java
@@ -54,7 +54,7 @@ public final class MySQLManualScalingCase extends BaseMySQLITCase {
@Parameters(name = "{0}")
public static Collection<ScalingParameterized> getParameters() {
Collection<ScalingParameterized> result = new LinkedList<>();
- for (String version : ENV.getMysqlVersionList()) {
+ for (String version : ENV.getMysqlVersions()) {
if (Strings.isNullOrEmpty(version)) {
continue;
}
@@ -70,9 +70,9 @@ public final class MySQLManualScalingCase extends BaseMySQLITCase {
@Test
public void assertManualScalingSuccess() throws InterruptedException {
- List<Map<String, Object>> previewResList = getJdbcTemplate().queryForList("PREVIEW SELECT COUNT(1) FROM t_order");
- Set<Object> originalSourceList = previewResList.stream().map(each -> each.get("data_source_name")).collect(Collectors.toSet());
- assertThat(originalSourceList, is(Sets.newHashSet("ds_0", "ds_1")));
+ List<Map<String, Object>> previewResults = getJdbcTemplate().queryForList("PREVIEW SELECT COUNT(1) FROM t_order");
+ Set<Object> originalSources = previewResults.stream().map(each -> each.get("data_source_name")).collect(Collectors.toSet());
+ assertThat(originalSources, is(Sets.newHashSet("ds_0", "ds_1")));
getJdbcTemplate().execute(getCommonSQLCommand().getAutoAlterTableRule());
Map<String, Object> showScalingResMap = getJdbcTemplate().queryForMap("SHOW SCALING LIST");
String jobId = showScalingResMap.get("id").toString();
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLManualScalingCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLManualScalingCase.java
index 3e8c681a106..ff1713a3081 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLManualScalingCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLManualScalingCase.java
@@ -48,7 +48,7 @@ public final class PostgreSQLManualScalingCase extends BasePostgreSQLITCase {
@Parameters(name = "{0}")
public static Collection<ScalingParameterized> getParameters() {
Collection<ScalingParameterized> result = new LinkedList<>();
- for (String dockerImageName : ENV.getPostgresVersionList()) {
+ for (String dockerImageName : ENV.getPostgresVersions()) {
if (Strings.isNullOrEmpty(dockerImageName)) {
continue;
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/env/IntegrationTestEnvironment.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/env/IntegrationTestEnvironment.java
index f3cb6424fdc..4395190a7a0 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/env/IntegrationTestEnvironment.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/env/IntegrationTestEnvironment.java
@@ -37,15 +37,15 @@ public final class IntegrationTestEnvironment {
private final ITEnvTypeEnum itEnvType;
- private final List<String> mysqlVersionList;
+ private final List<String> mysqlVersions;
- private final List<String> postgresVersionList;
+ private final List<String> postgresVersions;
private IntegrationTestEnvironment() {
props = loadProperties();
itEnvType = ITEnvTypeEnum.valueOf(props.getProperty("it.env.type", ITEnvTypeEnum.DOCKER.name()).toUpperCase());
- mysqlVersionList = Splitter.on(",").trimResults().splitToList(props.getOrDefault("it.env.mysql.version", "").toString());
- postgresVersionList = Splitter.on(",").trimResults().splitToList(props.getOrDefault("it.env.postgresql.version", "").toString());
+ mysqlVersions = Splitter.on(",").trimResults().splitToList(props.getOrDefault("it.env.mysql.version", "").toString());
+ postgresVersions = Splitter.on(",").trimResults().splitToList(props.getOrDefault("it.env.postgresql.version", "").toString());
}
private Properties loadProperties() {