提交 89479b2e 编写于 作者: T terrymanu

for checkstyle

上级 23f597c2
......@@ -119,11 +119,11 @@ public class InsertSetClauseParser implements SQLClauseParser {
}
private void removeUnnecessaryToken(final InsertStatement insertStatement) {
Iterator<SQLToken> sqlTokenIterable = insertStatement.getSqlTokens().iterator();
while (sqlTokenIterable.hasNext()) {
SQLToken sqlToken = sqlTokenIterable.next();
Iterator<SQLToken> sqlTokens = insertStatement.getSqlTokens().iterator();
while (sqlTokens.hasNext()) {
SQLToken sqlToken = sqlTokens.next();
if (sqlToken instanceof InsertColumnToken || sqlToken instanceof ItemsToken) {
sqlTokenIterable.remove();
sqlTokens.remove();
}
}
}
......
......@@ -32,6 +32,7 @@ import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -63,7 +64,7 @@ public abstract class AbstractStatementParserTest {
protected final ShardingMetaData createShardingMetaData() {
Map<String, TableMetaData> tableMetaDataMap = new HashMap<>();
tableMetaDataMap.put("TABLE_XXX", getTableMetaData(new ArrayList<String>(){{add("field1");add("field2");}}));
tableMetaDataMap.put("TABLE_XXX", getTableMetaData(Arrays.asList("field1", "field2")));
ShardingMetaData shardingMetaData = mock(ShardingMetaData.class);
when(shardingMetaData.getTableMetaDataMap()).thenReturn(tableMetaDataMap);
return shardingMetaData;
......
......@@ -292,7 +292,8 @@ public final class SQLRewriteEngineTest {
selectStatement.getSqlTokens().add(new TableToken(85, 0, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(123, 2));
selectStatement.getSqlTokens().add(new RowCountToken(26, 4));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_x x) AS row_ WHERE row_.rownum_>2",
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule,
"SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_x x) AS row_ WHERE row_.rownum_>2",
DatabaseType.SQLServer, selectStatement, null, Collections.emptyList());
assertThat(rewriteEngine.rewrite(true).toSQL(null, tableTokens, null, shardingDataSourceMetaData).getSql(),
is("SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_1 x) AS row_ WHERE row_.rownum_>0"));
......@@ -338,7 +339,8 @@ public final class SQLRewriteEngineTest {
selectStatement.getSqlTokens().add(new RowCountToken(26, 4));
selectStatement.getOrderByItems().add(new OrderItem("x", "id", OrderDirection.ASC, OrderDirection.ASC, Optional.<String>absent()));
selectStatement.getGroupByItems().add(new OrderItem("x", "id", OrderDirection.DESC, OrderDirection.ASC, Optional.<String>absent()));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_x x) AS row_ WHERE row_.rownum_>2",
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule,
"SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_x x) AS row_ WHERE row_.rownum_>2",
DatabaseType.SQLServer, selectStatement, null, Collections.emptyList());
assertThat(rewriteEngine.rewrite(true).toSQL(null, tableTokens, null, shardingDataSourceMetaData).getSql(),
is("SELECT * FROM (SELECT TOP(2147483647) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_1 x) AS row_ WHERE row_.rownum_>0"));
......@@ -378,7 +380,8 @@ public final class SQLRewriteEngineTest {
selectStatement.getSqlTokens().add(new TableToken(85, 0, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(123, 2));
selectStatement.getSqlTokens().add(new RowCountToken(26, 4));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_x x) AS row_ WHERE row_.rownum_>2",
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule,
"SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_x x) AS row_ WHERE row_.rownum_>2",
DatabaseType.SQLServer, selectStatement, null, Collections.emptyList());
assertThat(rewriteEngine.rewrite(false).toSQL(null, tableTokens, null, shardingDataSourceMetaData).getSql(),
is("SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_1 x) AS row_ WHERE row_.rownum_>2"));
......@@ -453,8 +456,9 @@ public final class SQLRewriteEngineTest {
showTablesStatement.getSqlTokens().add(new TableToken(18, 0, "table_x"));
showTablesStatement.getSqlTokens().add(new SchemaToken(31, "'sharding_db'", "table_x"));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SHOW COLUMNS FROM table_x FROM 'sharding_db'", DatabaseType.MySQL, showTablesStatement, null, Collections.emptyList());
assertThat(rewriteEngine.rewrite(false).toSQL(
null, new LinkedHashMap<String, String>() {{put("table_x", "table_x");}}, shardingRule, shardingDataSourceMetaData).getSql(), is("SHOW COLUMNS FROM table_x FROM actual_db"));
Map<String, String> logicAndActualTableMap = new LinkedHashMap<>();
logicAndActualTableMap.put("table_x", "table_x");
assertThat(rewriteEngine.rewrite(false).toSQL(null, logicAndActualTableMap, shardingRule, shardingDataSourceMetaData).getSql(), is("SHOW COLUMNS FROM table_x FROM actual_db"));
}
@Test
......
......@@ -4,4 +4,4 @@
<parser-result sql-case-id="drop_user_cascade" />
<parser-result sql-case-id="drop_role" />
<parser-result sql-case-id="drop_login" />
</parser-result-sets>
\ No newline at end of file
</parser-result-sets>
......@@ -33,7 +33,7 @@ import java.util.Map;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DataSourceConverter {
private static final Yaml yaml = new Yaml();
private static final Yaml YAML = new Yaml();
/**
* Convert data source map to Yaml string.
......@@ -54,7 +54,7 @@ public final class DataSourceConverter {
*/
@SuppressWarnings("unchecked")
public static Map<String, DataSource> dataSourceMapFromYaml(final String dataSourceMapYamlString) {
return (Map<String, DataSource>) yaml.load(dataSourceMapYamlString);
return (Map<String, DataSource>) YAML.load(dataSourceMapYamlString);
}
}
......@@ -33,7 +33,7 @@ import java.util.Map;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DataSourceParameterConverter {
private static final Yaml yaml = new Yaml(new DefaultConfigurationRepresenter());
private static final Yaml YAML = new Yaml(new DefaultConfigurationRepresenter());
/**
* Convert data source parameter map to Yaml string.
......@@ -42,7 +42,7 @@ public final class DataSourceParameterConverter {
* @return Yaml string
*/
public static String dataSourceParameterMapToYaml(final Map<String, DataSourceParameter> dataSourceParameterMap) {
return yaml.dumpAsMap(dataSourceParameterMap);
return YAML.dumpAsMap(dataSourceParameterMap);
}
/**
......@@ -53,7 +53,7 @@ public final class DataSourceParameterConverter {
*/
@SuppressWarnings("unchecked")
public static Map<String, DataSourceParameter> dataSourceParameterMapFromYaml(final String dataSourceParameterMapYamlString) {
return (Map<String, DataSourceParameter>) yaml.load(dataSourceParameterMapYamlString);
return (Map<String, DataSourceParameter>) YAML.load(dataSourceParameterMapYamlString);
}
}
......@@ -37,7 +37,7 @@ import java.util.Map;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MasterSlaveConfigurationConverter {
private static final Yaml yaml = new Yaml(new DefaultConfigurationRepresenter());
private static final Yaml YAML = new Yaml(new DefaultConfigurationRepresenter());
/**
* Convert masterSlaveRuleConfiguration to yaml string.
......@@ -55,11 +55,11 @@ public class MasterSlaveConfigurationConverter {
/**
* Convert master slave rule configuration string to master slave rule configuration.
*
* @param masteSlaveRuleConfigYamlString master slave rule configuration string
* @param masterSlaveRuleConfigYamlString master slave rule configuration string
* @return master slave rule configuration
*/
public static MasterSlaveRuleConfiguration masterSlaveRuleConfigFromYaml(final String masteSlaveRuleConfigYamlString) {
return yaml.loadAs(masteSlaveRuleConfigYamlString, YamlMasterSlaveRuleConfiguration.class).getMasterSlaveRuleConfiguration();
public static MasterSlaveRuleConfiguration masterSlaveRuleConfigFromYaml(final String masterSlaveRuleConfigYamlString) {
return YAML.loadAs(masterSlaveRuleConfigYamlString, YamlMasterSlaveRuleConfiguration.class).getMasterSlaveRuleConfiguration();
}
/**
......@@ -69,7 +69,7 @@ public class MasterSlaveConfigurationConverter {
* @return config map string
*/
public static String configMapToYaml(final Map<String, Object> configMap) {
return yaml.dumpAsMap(configMap);
return YAML.dumpAsMap(configMap);
}
/**
......@@ -80,6 +80,6 @@ public class MasterSlaveConfigurationConverter {
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> configMapFromYaml(final String configMapYamlString) {
return (Map<String, Object>) yaml.load(configMapYamlString);
return (Map<String, Object>) YAML.load(configMapYamlString);
}
}
......@@ -32,7 +32,7 @@ import org.yaml.snakeyaml.Yaml;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ProxyConfigurationConverter {
private static final Yaml yaml = new Yaml(new DefaultConfigurationRepresenter());
private static final Yaml YAML = new Yaml(new DefaultConfigurationRepresenter());
/**
* Convert yaml proxy configuration to yaml string.
......@@ -52,6 +52,6 @@ public final class ProxyConfigurationConverter {
* @return Yaml proxy configuration
*/
public static OrchestrationProxyConfiguration proxyConfigFromYaml(final String yamlProxyConfigYamlString) {
return yaml.loadAs(yamlProxyConfigYamlString, OrchestrationProxyConfiguration.class);
return YAML.loadAs(yamlProxyConfigYamlString, OrchestrationProxyConfiguration.class);
}
}
......@@ -37,7 +37,7 @@ import java.util.Properties;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ShardingConfigurationConverter {
private static final Yaml yaml = new Yaml(new DefaultConfigurationRepresenter());
private static final Yaml YAML = new Yaml(new DefaultConfigurationRepresenter());
/**
* Convert sharding rule configuration to yaml string.
......@@ -59,7 +59,7 @@ public class ShardingConfigurationConverter {
* @return sharding rule configuration
*/
public static ShardingRuleConfiguration shardingRuleConfigFromYaml(final String shardingRuleConfigYamlString) {
return yaml.loadAs(shardingRuleConfigYamlString, YamlShardingRuleConfiguration.class).getShardingRuleConfiguration();
return YAML.loadAs(shardingRuleConfigYamlString, YamlShardingRuleConfiguration.class).getShardingRuleConfiguration();
}
/**
......@@ -69,7 +69,7 @@ public class ShardingConfigurationConverter {
* @return config map string
*/
public static String configMapToYaml(final Map<String, Object> configMap) {
return yaml.dumpAsMap(configMap);
return YAML.dumpAsMap(configMap);
}
/**
......@@ -80,7 +80,7 @@ public class ShardingConfigurationConverter {
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> configMapFromYaml(final String configMapYamlString) {
return (Map<String, Object>) yaml.load(configMapYamlString);
return (Map<String, Object>) YAML.load(configMapYamlString);
}
/**
......@@ -90,7 +90,7 @@ public class ShardingConfigurationConverter {
* @return properties string
*/
public static String propertiesToYaml(final Properties props) {
return yaml.dumpAsMap(props);
return YAML.dumpAsMap(props);
}
/**
......@@ -100,6 +100,6 @@ public class ShardingConfigurationConverter {
* @return properties
*/
public static Properties propertiesFromYaml(final String propertiesYamlString) {
return yaml.loadAs(propertiesYamlString, Properties.class);
return YAML.loadAs(propertiesYamlString, Properties.class);
}
}
......@@ -37,11 +37,12 @@ import java.util.Set;
*/
public class MasterSlaveConfigurationRepresenter extends Representer {
private static Collection<String> eliminatedPropertyNames;
private static Collection<String> eliminatedPropertyNames = new HashSet<>();
static {
eliminatedPropertyNames = new HashSet<String>() { { add("configMap");} }; }
eliminatedPropertyNames.add("configMap");
}
public MasterSlaveConfigurationRepresenter() {
super();
this.nullRepresenter = new NullRepresent();
......
......@@ -37,11 +37,13 @@ import java.util.Set;
*/
public class ProxyConfigurationRepresenter extends Representer {
private static Collection<String> eliminatedPropertyNames;
private static Collection<String> eliminatedPropertyNames = new HashSet<>();
static {
eliminatedPropertyNames = new HashSet<String>() {{ add("dataSources"); add("orchestration"); } }; }
eliminatedPropertyNames.add("dataSources");
eliminatedPropertyNames.add("orchestration");
}
public ProxyConfigurationRepresenter() {
super();
this.nullRepresenter = new NullRepresent();
......
......@@ -37,11 +37,13 @@ import java.util.Set;
*/
public class ShardingConfigurationRepresenter extends Representer {
private static Collection<String> eliminatedPropertyNames;
private static Collection<String> eliminatedPropertyNames = new HashSet<>();
static {
eliminatedPropertyNames = new HashSet<String>() { { add("configMap"); add(";props"); } }; }
eliminatedPropertyNames.add("configMap");
eliminatedPropertyNames.add(";props");
}
public ShardingConfigurationRepresenter() {
super();
this.nullRepresenter = new NullRepresent();
......
......@@ -92,4 +92,4 @@
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
......@@ -81,16 +81,13 @@ public final class IntegrateTestParameters {
return result;
}
private static Collection<Object[]> getParametersWithAssertion(final IntegrateTestCase integrateTestCase, final IntegrateTestCaseAssertion assertion, final DatabaseType databaseType, final SQLCaseType caseType) {
private static Collection<Object[]> getParametersWithAssertion(
final IntegrateTestCase integrateTestCase, final IntegrateTestCaseAssertion assertion, final DatabaseType databaseType, final SQLCaseType caseType) {
Collection<Object[]> result = new LinkedList<>();
for (String each : integrateTestEnvironment.getShardingRuleTypes()) {
Object[] data = new Object[6];
data[0] = integrateTestCase.getSqlCaseId();
data[1] = integrateTestCase.getPath();
if (null == assertion) {
System.out.println();
System.out.println(1111111111);
}
data[2] = assertion;
data[3] = each;
data[4] = new DatabaseTypeEnvironment(databaseType, IntegrateTestEnvironment.getInstance().getDatabaseTypes().contains(databaseType));
......
<dataset>
<t_order_item_0 item_id="10" order_id="10" user_id="10" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
<dataset>
<t_order_item_1 item_id="1" order_id="1" user_id="1" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
<dataset>
<t_order_item_2 item_id="2" order_id="2" user_id="2" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
<dataset>
<t_order_item_3 item_id="3" order_id="3" user_id="3" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
<dataset>
<t_order_item_4 item_id="4" order_id="4" user_id="4" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
<dataset>
<t_order_item_5 item_id="5" order_id="5" user_id="5" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
<dataset>
<t_order_item_6 item_id="6" order_id="6" user_id="6" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
<dataset>
<t_order_item_7 item_id="7" order_id="7" user_id="7" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
<dataset>
<t_order_item_8 item_id="8" order_id="8" user_id="8" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
<dataset>
<t_order_item_9 item_id="9" order_id="9" user_id="9" status="insert" c_date="2020-09-09"/>
</dataset>
\ No newline at end of file
</dataset>
......@@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.TimeUnit;
/**
* samping control service.
* Sampling control service.
*
* @author chenqingyang
*/
......
......@@ -77,8 +77,8 @@ public final class ExecuteEventListenerTest {
public void assertSingleStatement() throws Exception {
Statement statement = mock(Statement.class);
when(statement.getConnection()).thenReturn(mock(Connection.class));
executorEngine.execute(SQLType.DML, Collections.singleton(new StatementUnit(new SQLExecutionUnit("ds_0",
new SQLUnit("insert into ...", Collections.singletonList(Collections.<Object>singletonList(1)))), statement)), new ExecuteCallback<Integer>() {
executorEngine.execute(SQLType.DML, Collections.singleton(new StatementUnit(
new SQLExecutionUnit("ds_0", new SQLUnit("insert into ...", Collections.singletonList(Collections.<Object>singletonList(1)))), statement)), new ExecuteCallback<Integer>() {
@Override
public Integer execute(final BaseStatementUnit baseStatementUnit) {
......@@ -110,13 +110,13 @@ public final class ExecuteEventListenerTest {
@Test
public void assertBatchPreparedStatement() throws Exception {
List<BatchPreparedStatementUnit> statementUnitList = new ArrayList<>(2);
List<List<Object>> parameterSets = Arrays.asList(Arrays.<Object>asList(1,2), Arrays.<Object>asList(3,4));
PreparedStatement pstm1 = mock(PreparedStatement.class);
when(pstm1.getConnection()).thenReturn(mock(Connection.class));
statementUnitList.add(new BatchPreparedStatementUnit(new SQLExecutionUnit("ds_0", new SQLUnit("insert into ...", parameterSets)), pstm1));
PreparedStatement pstm2 = mock(PreparedStatement.class);
when(pstm2.getConnection()).thenReturn(mock(Connection.class));
statementUnitList.add(new BatchPreparedStatementUnit(new SQLExecutionUnit("ds_1", new SQLUnit("insert into ...", parameterSets)), pstm2));
List<List<Object>> parameterSets = Arrays.asList(Arrays.<Object>asList(1, 2), Arrays.<Object>asList(3, 4));
PreparedStatement preparedStatement1 = mock(PreparedStatement.class);
when(preparedStatement1.getConnection()).thenReturn(mock(Connection.class));
statementUnitList.add(new BatchPreparedStatementUnit(new SQLExecutionUnit("ds_0", new SQLUnit("insert into ...", parameterSets)), preparedStatement1));
PreparedStatement preparedStatement2 = mock(PreparedStatement.class);
when(preparedStatement2.getConnection()).thenReturn(mock(Connection.class));
statementUnitList.add(new BatchPreparedStatementUnit(new SQLExecutionUnit("ds_1", new SQLUnit("insert into ...", parameterSets)), preparedStatement2));
executorEngine.execute(SQLType.DML, statementUnitList, new ExecuteCallback<Integer>() {
@Override
......
......@@ -46,7 +46,7 @@ public final class SamplingServiceTest {
}
@Test
public void asserTrySampling() {
public void assertTrySampling() {
SamplingService.getInstance().init(1);
assertTrue(SamplingService.getInstance().trySampling());
SamplingService.getInstance().samplingAdd();
......
......@@ -29,7 +29,7 @@ import io.shardingsphere.proxy.config.DataSourceConfig;
*/
public final class BackendHandlerFactory {
/**
* Create bakcend handler instance.
* Create backend handler instance.
*
* @param databaseType database type
* @param dataSourceConfig dataSourceConfig
......
......@@ -38,7 +38,7 @@ public class ProxyAuthorityHandler {
}
/**
* Judege whether it is legal to login into Proxy.
* Judge whether it is legal to login into Proxy.
*
* @param username connection username.
* @param authResponse connection auth response.
......
......@@ -29,8 +29,6 @@ import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfigura
import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent;
import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusInstance;
import io.shardingsphere.proxy.config.RuleRegistry;
import lombok.Getter;
import lombok.Setter;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
......@@ -48,8 +46,6 @@ import java.util.Map;
* @author zhangyonglun
* @author panjuan
*/
@Getter
@Setter
public final class YamlProxyConfiguration extends OrchestrationProxyConfiguration {
/**
......
......@@ -12,4 +12,4 @@
<sql-case id="alter_user_passwd_set" value="ALTER USER user_dev SET PASSWORD 'passwd_dev'" db-types="H2" />
<sql-case id="alter_role_add_member" value="ALTER ROLE role_dev ADD MEMBER user_dev" db-types="SQLServer" />
<sql-case id="alter_role_drop_member" value="ALTER ROLE role_dev DROP MEMBER user_dev" db-types="SQLServer" />
</sql-cases>
\ No newline at end of file
</sql-cases>
......@@ -104,4 +104,4 @@
<property name="types" value="[java.sql.Connection, java.sql.ResultSet]" />
</properties>
</rule>
</ruleset>
\ No newline at end of file
</ruleset>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册