提交 10f7b6af 编写于 作者: T terrymanu

add arg check for KeyGeneratorConfiguration

上级 182d63ff
......@@ -17,8 +17,9 @@
package org.apache.shardingsphere.api.config.sharding;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Properties;
......@@ -27,13 +28,20 @@ import java.util.Properties;
*
* @author panjuan
*/
@RequiredArgsConstructor
@Getter
public final class KeyGeneratorConfiguration {
private final String column;
private final String type;
private final String column;
private final Properties props;
public KeyGeneratorConfiguration(final String type, final String column, final Properties props) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(type), "Type is required.");
Preconditions.checkArgument(!Strings.isNullOrEmpty(column), "Column is required.");
this.type = type;
this.column = column;
this.props = null == props ? new Properties() : props;
}
}
......@@ -17,7 +17,6 @@
package org.apache.shardingsphere.core.rule;
import com.google.common.base.Preconditions;
import lombok.Getter;
import org.apache.shardingsphere.api.algorithm.masterslave.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.api.algorithm.masterslave.MasterSlaveLoadBalanceAlgorithmType;
......@@ -45,10 +44,6 @@ public class MasterSlaveRule {
private final MasterSlaveRuleConfiguration masterSlaveRuleConfiguration;
public MasterSlaveRule(final MasterSlaveRuleConfiguration config) {
Preconditions.checkNotNull(config.getName(), "Master-slave rule name cannot be null.");
Preconditions.checkNotNull(config.getMasterDataSourceName(), "Master data source name cannot be null.");
Preconditions.checkNotNull(config.getSlaveDataSourceNames(), "Slave data source names cannot be null.");
Preconditions.checkState(!config.getSlaveDataSourceNames().isEmpty(), "Slave data source names cannot be empty.");
name = config.getName();
masterDataSourceName = config.getMasterDataSourceName();
slaveDataSourceNames = config.getSlaveDataSourceNames();
......
......@@ -32,9 +32,9 @@ import java.util.Properties;
@Setter
public final class YamlKeyGeneratorConfiguration implements YamlConfiguration {
private String column;
private String type;
private String column;
private Properties props = new Properties();
}
......@@ -31,14 +31,14 @@ public final class KeyGeneratorConfigurationYamlSwapper implements YamlSwapper<Y
@Override
public YamlKeyGeneratorConfiguration swap(final KeyGeneratorConfiguration data) {
YamlKeyGeneratorConfiguration result = new YamlKeyGeneratorConfiguration();
result.setColumn(data.getColumn());
result.setType(data.getType());
result.setColumn(data.getColumn());
result.setProps(data.getProps());
return result;
}
@Override
public KeyGeneratorConfiguration swap(final YamlKeyGeneratorConfiguration yamlConfiguration) {
return new KeyGeneratorConfiguration(yamlConfiguration.getColumn(), yamlConfiguration.getType(), yamlConfiguration.getProps());
return new KeyGeneratorConfiguration(yamlConfiguration.getType(), yamlConfiguration.getColumn(), yamlConfiguration.getProps());
}
}
......@@ -19,6 +19,7 @@ package org.apache.shardingsphere.api.config;
import org.apache.shardingsphere.api.config.encryptor.EncryptorConfigurationTest;
import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfigurationTest;
import org.apache.shardingsphere.api.config.sharding.KeyGeneratorConfigurationTest;
import org.apache.shardingsphere.api.config.sharding.TableRuleConfigurationTest;
import org.apache.shardingsphere.api.config.sharding.strategy.ComplexShardingStrategyConfigurationTest;
import org.apache.shardingsphere.api.config.sharding.strategy.HintShardingStrategyConfigurationTest;
......@@ -35,7 +36,8 @@ import org.junit.runners.Suite.SuiteClasses;
InlineShardingStrategyConfigurationTest.class,
ComplexShardingStrategyConfigurationTest.class,
HintShardingStrategyConfigurationTest.class,
MasterSlaveRuleConfigurationTest.class,
MasterSlaveRuleConfigurationTest.class,
KeyGeneratorConfigurationTest.class,
EncryptorConfigurationTest.class
})
public final class AllConfigTests {
......
......@@ -46,7 +46,18 @@ public final class EncryptorConfigurationTest {
}
@Test
public void assertConstructorWithFullArguments() {
public void assertConstructorWithMinArguments() {
Properties props = new Properties();
props.setProperty("key", "value");
EncryptorConfiguration actual = new EncryptorConfiguration("TEST", "pwd", props);
assertThat(actual.getType(), is("TEST"));
assertThat(actual.getColumns(), is("pwd"));
assertThat(actual.getAssistedQueryColumns(), is(""));
assertThat(actual.getProps(), is(props));
}
@Test
public void assertConstructorWithMaxArguments() {
Properties props = new Properties();
props.setProperty("key", "value");
EncryptorConfiguration actual = new EncryptorConfiguration("TEST", "pwd", "pwd_query", props);
......
......@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
public final class MasterSlaveRuleConfigurationTest {
......@@ -50,7 +51,16 @@ public final class MasterSlaveRuleConfigurationTest {
}
@Test
public void assertConstructorWithFullArguments() {
public void assertConstructorWithMinArguments() {
MasterSlaveRuleConfiguration actual = new MasterSlaveRuleConfiguration("ds", "master_ds", Collections.singletonList("slave_ds"));
assertThat(actual.getName(), is("ds"));
assertThat(actual.getMasterDataSourceName(), is("master_ds"));
assertThat(actual.getSlaveDataSourceNames(), CoreMatchers.<Collection<String>>is(Collections.singletonList("slave_ds")));
assertNull(actual.getLoadBalanceAlgorithm());
}
@Test
public void assertConstructorWithMaxArguments() {
MasterSlaveRuleConfiguration actual = new MasterSlaveRuleConfiguration(
"ds", "master_ds", Collections.singletonList("slave_ds"), MasterSlaveLoadBalanceAlgorithmType.getDefaultAlgorithmType().getAlgorithm());
assertThat(actual.getName(), is("ds"));
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shardingsphere.api.config.sharding;
import org.junit.Test;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class KeyGeneratorConfigurationTest {
@Test(expected = IllegalArgumentException.class)
public void assertConstructorWithoutType() {
new KeyGeneratorConfiguration("", "id", new Properties());
}
@Test(expected = IllegalArgumentException.class)
public void assertConstructorWithoutColumn() {
new KeyGeneratorConfiguration("TEST", "", new Properties());
}
@Test
public void assertConstructorWithoutProperties() {
KeyGeneratorConfiguration actual = new KeyGeneratorConfiguration("TEST", "id", null);
assertThat(actual.getType(), is("TEST"));
assertThat(actual.getColumn(), is("id"));
assertThat(actual.getProps(), is(new Properties()));
}
@Test
public void assertConstructorWithFullArguments() {
Properties props = new Properties();
props.setProperty("key", "value");
KeyGeneratorConfiguration actual = new KeyGeneratorConfiguration("TEST", "id", props);
assertThat(actual.getType(), is("TEST"));
assertThat(actual.getColumn(), is("id"));
assertThat(actual.getProps(), is(props));
}
}
......@@ -22,6 +22,7 @@ import org.apache.shardingsphere.api.algorithm.sharding.standard.RangeShardingAl
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
......@@ -38,7 +39,16 @@ public final class StandardShardingStrategyConfigurationTest {
}
@Test
public void assertConstructorWithFullArguments() {
public void assertConstructorWithMinArguments() {
PreciseShardingAlgorithm preciseShardingAlgorithm = mock(PreciseShardingAlgorithm.class);
StandardShardingStrategyConfiguration actual = new StandardShardingStrategyConfiguration("id", preciseShardingAlgorithm);
assertThat(actual.getShardingColumn(), is("id"));
assertThat(actual.getPreciseShardingAlgorithm(), is(preciseShardingAlgorithm));
assertNull(actual.getRangeShardingAlgorithm());
}
@Test
public void assertConstructorWithMaxArguments() {
PreciseShardingAlgorithm preciseShardingAlgorithm = mock(PreciseShardingAlgorithm.class);
RangeShardingAlgorithm rangeShardingAlgorithm = mock(RangeShardingAlgorithm.class);
StandardShardingStrategyConfiguration actual = new StandardShardingStrategyConfiguration("id", preciseShardingAlgorithm, rangeShardingAlgorithm);
......
......@@ -22,23 +22,26 @@ import org.junit.Test;
import java.util.Collections;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public final class MasterSlaveRuleTest {
@Test(expected = NullPointerException.class)
public void assertNewMasterSlaveRuleFailure() {
MasterSlaveRuleConfiguration masterSlaveRuleConfig = new MasterSlaveRuleConfiguration("", "", null);
new MasterSlaveRule(masterSlaveRuleConfig);
@Test
public void assertContainDataSourceNameWithMasterDataSourceName() {
MasterSlaveRule actual = new MasterSlaveRule(new MasterSlaveRuleConfiguration("master_slave", "master_ds", Collections.singletonList("slave_ds")));
assertTrue(actual.containDataSourceName("master_ds"));
}
@Test(expected = IllegalStateException.class)
public void assertNewMasterSlaveRuleWithEmptySlaveDataSourceNames() {
MasterSlaveRuleConfiguration masterSlaveRuleConfig = new MasterSlaveRuleConfiguration("", "", Collections.<String>emptyList());
new MasterSlaveRule(masterSlaveRuleConfig);
@Test
public void assertContainDataSourceNameWithSlaveDataSourceName() {
MasterSlaveRule actual = new MasterSlaveRule(new MasterSlaveRuleConfiguration("master_slave", "master_ds", Collections.singletonList("slave_ds")));
assertTrue(actual.containDataSourceName("slave_ds"));
}
@Test
public void assertNewMasterSlaveRuleSuccess() {
MasterSlaveRuleConfiguration masterSlaveRuleConfig = new MasterSlaveRuleConfiguration("master_slave", "master0", Collections.singletonList("slave0"));
new MasterSlaveRule(masterSlaveRuleConfig);
public void assertNotContainDataSourceName() {
MasterSlaveRule actual = new MasterSlaveRule(new MasterSlaveRuleConfiguration("master_slave", "master_ds", Collections.singletonList("slave_ds")));
assertFalse(actual.containDataSourceName("master_slave"));
}
}
......@@ -277,7 +277,7 @@ public final class ShardingRuleTest {
@Test
public void assertNotFindGenerateKeyColumn() {
assertFalse(createMaximumShardingRule().findGenerateKeyColumn("sub_logic_table").isPresent());
assertFalse(createMinimumShardingRule().findGenerateKeyColumn("sub_logic_table").isPresent());
}
@Test(expected = ShardingConfigurationException.class)
......@@ -293,7 +293,6 @@ public final class ShardingRuleTest {
@Test
public void assertGenerateKeyWithKeyGenerator() {
assertThat(createMaximumShardingRule().generateKey("logic_table"), instanceOf(Integer.class));
}
@Test
......@@ -371,29 +370,28 @@ public final class ShardingRuleTest {
private ShardingRule createMaximumShardingRule() {
ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
shardingRuleConfiguration.setDefaultDataSourceName("ds_0");
TableRuleConfiguration tableRuleConfiguration = createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}", "id");
TableRuleConfiguration subTableRuleConfiguration = createTableRuleConfiguration("SUB_LOGIC_TABLE", "ds_${0..1}.sub_table_${0..2}", null);
TableRuleConfiguration tableRuleConfiguration = createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
tableRuleConfiguration.setKeyGeneratorConfig(new KeyGeneratorConfiguration("INCREMENT", "id", new Properties()));
TableRuleConfiguration subTableRuleConfiguration = createTableRuleConfiguration("SUB_LOGIC_TABLE", "ds_${0..1}.sub_table_${0..2}");
shardingRuleConfiguration.getTableRuleConfigs().add(tableRuleConfiguration);
shardingRuleConfiguration.getTableRuleConfigs().add(subTableRuleConfiguration);
shardingRuleConfiguration.getBindingTableGroups().add(tableRuleConfiguration.getLogicTable() + "," + subTableRuleConfiguration.getLogicTable());
shardingRuleConfiguration.getBroadcastTables().add("BROADCAST_TABLE");
shardingRuleConfiguration.setDefaultDatabaseShardingStrategyConfig(new InlineShardingStrategyConfiguration("id", "ds_%{id % 2}"));
shardingRuleConfiguration.setDefaultTableShardingStrategyConfig(new InlineShardingStrategyConfiguration("id", "table_%{id % 2}"));
shardingRuleConfiguration.setDefaultKeyGeneratorConfig(new KeyGeneratorConfiguration(null, "INCREMENT", new Properties()));
shardingRuleConfiguration.setDefaultKeyGeneratorConfig(new KeyGeneratorConfiguration("INCREMENT", "id", new Properties()));
return new ShardingRule(shardingRuleConfiguration, createDataSourceNames());
}
private ShardingRule createMinimumShardingRule() {
ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfiguration = createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}", "id");
TableRuleConfiguration tableRuleConfiguration = createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
shardingRuleConfiguration.getTableRuleConfigs().add(tableRuleConfiguration);
return new ShardingRule(shardingRuleConfiguration, createDataSourceNames());
}
private TableRuleConfiguration createTableRuleConfiguration(final String logicTableName, final String actualDataNodes, final String keyGeneratorColumnName) {
TableRuleConfiguration result = new TableRuleConfiguration(logicTableName, actualDataNodes);
result.setKeyGeneratorConfig(new KeyGeneratorConfiguration(keyGeneratorColumnName, null, new Properties()));
return result;
private TableRuleConfiguration createTableRuleConfiguration(final String logicTableName, final String actualDataNodes) {
return new TableRuleConfiguration(logicTableName, actualDataNodes);
}
private Collection<String> createDataSourceNames() {
......@@ -402,7 +400,7 @@ public final class ShardingRuleTest {
private ShardingRule createMasterSlaveShardingRule() {
ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfiguration = createTableRuleConfiguration("LOGIC_TABLE", "ms_ds_${0..1}.table_${0..2}", "id");
TableRuleConfiguration tableRuleConfiguration = createTableRuleConfiguration("LOGIC_TABLE", "ms_ds_${0..1}.table_${0..2}");
shardingRuleConfiguration.getTableRuleConfigs().add(tableRuleConfiguration);
shardingRuleConfiguration.getMasterSlaveRuleConfigs().add(createMasterSlaveRuleConfiguration("ms_ds_0", "master_ds_0", "slave_ds_0"));
shardingRuleConfiguration.getMasterSlaveRuleConfigs().add(createMasterSlaveRuleConfiguration("ms_ds_1", "master_ds_1", "slave_ds_1"));
......
......@@ -58,7 +58,7 @@ public final class TableRuleTest {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration("LOGIC_TABLE", "ds${0..1}.table_${0..2}");
tableRuleConfig.setDatabaseShardingStrategyConfig(new NoneShardingStrategyConfiguration());
tableRuleConfig.setTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
tableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("col_1", "INCREMENT", new Properties()));
tableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("INCREMENT", "col_1", new Properties()));
tableRuleConfig.setLogicIndex("LOGIC_INDEX");
TableRule actual = new TableRule(tableRuleConfig, createShardingDataSourceNames(), null);
assertThat(actual.getLogicTable(), is("logic_table"));
......
......@@ -30,20 +30,20 @@ public final class KeyGeneratorConfigurationYamlSwapperTest {
@Test
public void assertSwapToYaml() {
YamlKeyGeneratorConfiguration actual = new KeyGeneratorConfigurationYamlSwapper().swap(new KeyGeneratorConfiguration("id", "UUID", new Properties()));
assertThat(actual.getColumn(), is("id"));
YamlKeyGeneratorConfiguration actual = new KeyGeneratorConfigurationYamlSwapper().swap(new KeyGeneratorConfiguration("UUID", "id", new Properties()));
assertThat(actual.getType(), is("UUID"));
assertThat(actual.getColumn(), is("id"));
assertThat(actual.getProps(), is(new Properties()));
}
@Test
public void assertSwapToObject() {
YamlKeyGeneratorConfiguration yamlConfiguration = new YamlKeyGeneratorConfiguration();
yamlConfiguration.setColumn("id");
yamlConfiguration.setType("UUID");
yamlConfiguration.setColumn("id");
KeyGeneratorConfiguration actual = new KeyGeneratorConfigurationYamlSwapper().swap(yamlConfiguration);
assertThat(actual.getColumn(), is("id"));
assertThat(actual.getType(), is("UUID"));
assertThat(actual.getColumn(), is("id"));
assertThat(actual.getProps(), is(new Properties()));
}
}
......@@ -23,6 +23,6 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: SNOWFLAKE
column: order_id
logicIndex: order_index
......@@ -26,8 +26,8 @@ shardingRule:
shardingColumns: user_id, order_id, item_id
algorithmClassName: org.apache.shardingsphere.api.algorithm.fixture.TestComplexKeysShardingAlgorithm
keyGenerator:
column: item_id
type: SNOWFLAKE
column: item_id
t_place:
actualDataNodes: db${0..1}.t_place
tableStrategy:
......@@ -36,5 +36,3 @@ shardingRule:
algorithmClassName: org.apache.shardingsphere.api.algorithm.fixture.TestComplexKeysShardingAlgorithm
bindingTables:
- t_order, t_order_item
defaultKeyGenerator:
type: SNOWFLAKE
......@@ -15,8 +15,8 @@ shardingRule:
table_x:
actualDataNodes: db${0..1}.table_x
keyGenerator:
column: id
type: SNOWFLAKE
column: id
logicIndex: logic_index
table_y:
actualDataNodes: db${0..1}.table_y
......
......@@ -62,8 +62,8 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: SNOWFLAKE
column: order_id
logicIndex: order_index
t_order_item:
actualDataNodes: ds_${0..1}.t_order_item_${0..1}
......@@ -83,9 +83,6 @@ shardingRule:
algorithmExpression: ds_${order_id % 2}
defaultTableStrategy:
none:
defaultKeyGenerator:
type: SNOWFLAKE
masterSlaveRules:
ds_0:
masterDataSourceName: master_ds_0
......
......@@ -65,7 +65,7 @@ public abstract class AbstractShardingJDBCDatabaseAndTableTest extends AbstractS
orderItemActualDataNodes.add(dataSourceName + ".t_order_item_${0..1}");
}
TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration("t_order_item", Joiner.on(",").join(orderItemActualDataNodes));
orderItemTableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("item_id", "INCREMENT", new Properties()));
orderItemTableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("INCREMENT", "item_id", new Properties()));
shardingRuleConfig.getTableRuleConfigs().add(orderItemTableRuleConfig);
TableRuleConfiguration configTableRuleConfig = new TableRuleConfiguration("t_config");
shardingRuleConfig.getTableRuleConfigs().add(configTableRuleConfig);
......
......@@ -16,8 +16,8 @@ shardingRule:
preciseAlgorithmClassName: org.apache.shardingsphere.dbtest.fixture.PreciseModuloAlgorithm
rangeAlgorithmClassName: org.apache.shardingsphere.dbtest.fixture.RangeModuloAlgorithm
keyGenerator:
column: item_id
type: CONSTANT
column: item_id
bindingTables:
- t_order,t_order_item
defaultDataSourceName: db_0
......@@ -28,8 +28,8 @@ shardingRule:
preciseAlgorithmClassName: org.apache.shardingsphere.dbtest.fixture.PreciseModuloAlgorithm
rangeAlgorithmClassName: org.apache.shardingsphere.dbtest.fixture.RangeModuloAlgorithm
keyGenerator:
column: item_id
type: Constant
column: item_id
bindingTables:
- t_order,t_order_item
defaultDataSourceName: db_ms_0
......
......@@ -16,8 +16,8 @@ shardingRule:
preciseAlgorithmClassName: org.apache.shardingsphere.dbtest.fixture.PreciseModuloAlgorithm
rangeAlgorithmClassName: org.apache.shardingsphere.dbtest.fixture.RangeModuloAlgorithm
keyGenerator:
column: item_id
type: Constant
column: item_id
bindingTables:
- t_order,t_order_item
defaultDataSourceName: tbl
......@@ -40,6 +40,8 @@ import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
......@@ -56,12 +58,11 @@ public final class OrchestrationShardingDataSourceTest {
private static OrchestrationShardingDataSource shardingDataSource;
@BeforeClass
public static void setUp() throws SQLException {
public static void setUp() throws SQLException, IOException, URISyntaxException {
shardingDataSource = new OrchestrationShardingDataSource(getShardingDataSource(), getOrchestrationConfiguration());
}
@SneakyThrows
private static ShardingDataSource getShardingDataSource() {
private static ShardingDataSource getShardingDataSource() throws IOException, SQLException, URISyntaxException {
File yamlFile = new File(OrchestrationShardingDataSourceTest.class.getResource("/yaml/unit/sharding.yaml").toURI());
return (ShardingDataSource) YamlShardingDataSourceFactory.createDataSource(yamlFile);
}
......
......@@ -28,9 +28,8 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: INCREMENT
column: order_id
t_order_item:
actualDataNodes: db${0..1}.t_order_item_${0..1}
databaseStrategy:
......
......@@ -28,9 +28,8 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: INCREMENT
column: order_id
t_order_item:
actualDataNodes: db${0..1}.t_order_item_${0..1}
databaseStrategy:
......
......@@ -14,9 +14,8 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: INCREMENT
column: order_id
t_order_item:
actualDataNodes: db${0..1}.t_order_item_${0..1}
databaseStrategy:
......
......@@ -13,9 +13,8 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: INCREMENT
column: order_id
t_order_item:
actualDataNodes: db${0..1}.t_order_item_${0..1}
databaseStrategy:
......
......@@ -40,9 +40,8 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: INCREMENT
column: order_id
t_order_item:
actualDataNodes: db_ms_${0..1}.t_order_item_${0..1}
databaseStrategy:
......
......@@ -40,9 +40,8 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: INCREMENT
column: order_id
t_order_item:
actualDataNodes: db_ms_${0..1}.t_order_item_${0..1}
databaseStrategy:
......
......@@ -14,9 +14,8 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: INCREMENT
column: order_id
t_order_item:
actualDataNodes: db_ms_${0..1}.t_order_item_${0..1}
databaseStrategy:
......
......@@ -14,9 +14,8 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
column: order_id
type: INCREMENT
column: order_id
t_order_item:
actualDataNodes: db_ms_${0..1}.t_order_item_${0..1}
databaseStrategy:
......
......@@ -23,6 +23,7 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
type: SNOWFLAKE
column: order_id
t_order_item:
actualDataNodes: ds_ms.t_order_item_${0..1}
......@@ -31,6 +32,7 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_item_${order_id % 2}
keyGenerator:
type: SNOWFLAKE
column: order_item_id
bindingTables:
- t_order,t_order_item
......@@ -45,7 +47,5 @@ shardingRule:
algorithmExpression: ds_ms_${user_id % 2}
defaultTableStrategy:
none:
defaultKeyGenerator:
type: SNOWFLAKE
props:
sql.show: false
\ No newline at end of file
......@@ -72,8 +72,8 @@ public final class ConfigurationServiceTest {
+ "ds_1: !!org.apache.shardingsphere.core.rule.DataSourceParameter\n"
+ " url: jdbc:mysql://localhost:3306/ds_1\n" + " username: root\n" + " password: root\n";
private static final String SHARDING_RULE_YAML = "tables:\n" + " t_order:\n" + " actualDataNodes: ds_${0..1}.t_order_${0..1}\n" + " keyGenerator:\n"
+ " type: SNOWFLAKE\n" + " logicTable: t_order\n" + " tableStrategy:\n" + " inline:\n" + " algorithmExpression: t_order_${order_id % 2}\n"
private static final String SHARDING_RULE_YAML = "tables:\n" + " t_order:\n" + " actualDataNodes: ds_${0..1}.t_order_${0..1}\n"
+ " logicTable: t_order\n" + " tableStrategy:\n" + " inline:\n" + " algorithmExpression: t_order_${order_id % 2}\n"
+ " shardingColumn: order_id\n";
private static final String MASTER_SLAVE_RULE_YAML = "masterDataSourceName: master_ds\n" + "name: ms_ds\n" + "slaveDataSourceNames:\n" + "- slave_ds_0\n" + "- slave_ds_1\n";
......
......@@ -37,6 +37,7 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
type: SNOWFLAKE
column: order_id
t_order_item:
actualDataNodes: ds_${0..1}.t_order_item_${0..1}
......@@ -45,6 +46,7 @@ shardingRule:
shardingColumn: order_id
algorithmExpression: t_order_item_${order_id % 2}
keyGenerator:
type: SNOWFLAKE
column: order_item_id
bindingTables:
- t_order,t_order_item
......@@ -54,5 +56,3 @@ shardingRule:
algorithmExpression: ds_${user_id % 2}
defaultTableStrategy:
none:
defaultKeyGenerator:
type: SNOWFLAKE
......@@ -37,6 +37,7 @@
# shardingColumn: order_id
# algorithmExpression: t_order_${order_id % 2}
# keyGenerator:
# type: SNOWFLAKE
# column: order_id
# t_order_item:
# actualDataNodes: ds_${0..1}.t_order_item_${0..1}
......@@ -45,6 +46,7 @@
# shardingColumn: order_id
# algorithmExpression: t_order_item_${order_id % 2}
# keyGenerator:
# type: SNOWFLAKE
# column: order_item_id
# bindingTables:
# - t_order,t_order_item
......@@ -54,5 +56,3 @@
# algorithmExpression: ds_${user_id % 2}
# defaultTableStrategy:
# none:
# defaultKeyGenerator:
# type: SNOWFLAKE
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册