diff --git a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java index b37c8673f435acb0915e8aa2efa8dc01f4a8c576..359765ac949d70b991d69a7c2eaa9171caa4aa85 100644 --- a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java +++ b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java @@ -25,11 +25,11 @@ import org.apache.shardingsphere.orchestration.center.config.OrchestrationConfig import org.apache.shardingsphere.orchestration.center.yaml.config.YamlCenterRepositoryConfiguration; import org.apache.shardingsphere.orchestration.center.yaml.swapper.CenterRepositoryConfigurationYamlSwapper; import org.apache.shardingsphere.sharding.core.strategy.algorithm.sharding.inline.InlineExpressionParser; -import org.apache.shardingsphere.sharding.core.yaml.swapper.root.RuleRootConfigurationsYamlSwapper; import org.apache.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingSphereDataSource; import org.apache.shardingsphere.shardingjdbc.orchestration.internal.datasource.OrchestrationShardingSphereDataSource; import org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.common.SpringBootRootConfigurationProperties; import org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.sharding.LocalShardingRuleCondition; +import org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.sharding.OrchestrationSpringBootRuleConfigurationsYamlSwapper; import org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.sharding.OrchestrationSpringBootRulesConfigurationProperties; import org.apache.shardingsphere.spring.boot.datasource.DataSourcePropertiesSetterHolder; import org.apache.shardingsphere.spring.boot.util.DataSourceUtil; @@ -107,7 +107,7 @@ public class OrchestrationSpringBootConfiguration implements EnvironmentAware { @Conditional(LocalShardingRuleCondition.class) public DataSource shardingSphereDataSourceByLocal(final OrchestrationConfiguration orchestrationConfiguration) throws SQLException { return new OrchestrationShardingSphereDataSource( - new ShardingSphereDataSource(dataSourceMap, new RuleRootConfigurationsYamlSwapper().swap(rules), root.getProps()), orchestrationConfiguration); + new ShardingSphereDataSource(dataSourceMap, new OrchestrationSpringBootRuleConfigurationsYamlSwapper().swap(rules), root.getProps()), orchestrationConfiguration); } /** diff --git a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/sharding/OrchestrationSpringBootRuleConfigurationsYamlSwapper.java b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/sharding/OrchestrationSpringBootRuleConfigurationsYamlSwapper.java new file mode 100644 index 0000000000000000000000000000000000000000..97c7496eddf7f636e4db3766caa4198e8991c90e --- /dev/null +++ b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/sharding/OrchestrationSpringBootRuleConfigurationsYamlSwapper.java @@ -0,0 +1,81 @@ +/* + * 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.shardingjdbc.orchestration.spring.boot.sharding; + +import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration; +import org.apache.shardingsphere.encrypt.yaml.swapper.EncryptRuleConfigurationYamlSwapper; +import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration; +import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; +import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; +import org.apache.shardingsphere.sharding.core.yaml.swapper.MasterSlaveRuleConfigurationYamlSwapper; +import org.apache.shardingsphere.sharding.core.yaml.swapper.ShadowRuleConfigurationYamlSwapper; +import org.apache.shardingsphere.sharding.core.yaml.swapper.ShardingRuleConfigurationYamlSwapper; +import org.apache.shardingsphere.underlying.common.config.RuleConfiguration; +import org.apache.shardingsphere.underlying.common.yaml.swapper.YamlSwapper; + +import java.util.Collection; +import java.util.LinkedList; + +/** + * Orchestration Spring boot root configurations YAML swapper. + */ +public final class OrchestrationSpringBootRuleConfigurationsYamlSwapper implements YamlSwapper> { + + private final ShardingRuleConfigurationYamlSwapper shardingRuleConfigurationYamlSwapper = new ShardingRuleConfigurationYamlSwapper(); + + private final MasterSlaveRuleConfigurationYamlSwapper masterSlaveRuleConfigurationYamlSwapper = new MasterSlaveRuleConfigurationYamlSwapper(); + + private final EncryptRuleConfigurationYamlSwapper encryptRuleConfigurationYamlSwapper = new EncryptRuleConfigurationYamlSwapper(); + + private final ShadowRuleConfigurationYamlSwapper shadowRuleConfigurationYamlSwapper = new ShadowRuleConfigurationYamlSwapper(); + + @Override + public OrchestrationSpringBootRulesConfigurationProperties swap(final Collection data) { + OrchestrationSpringBootRulesConfigurationProperties result = new OrchestrationSpringBootRulesConfigurationProperties(); + for (RuleConfiguration each : data) { + if (each instanceof ShardingRuleConfiguration) { + result.setShardingRule(shardingRuleConfigurationYamlSwapper.swap((ShardingRuleConfiguration) each)); + } else if (each instanceof MasterSlaveRuleConfiguration) { + result.setMasterSlaveRule(masterSlaveRuleConfigurationYamlSwapper.swap((MasterSlaveRuleConfiguration) each)); + } else if (each instanceof EncryptRuleConfiguration) { + result.setEncryptRule(encryptRuleConfigurationYamlSwapper.swap((EncryptRuleConfiguration) each)); + } else if (each instanceof ShadowRuleConfiguration) { + result.setShadowRule(shadowRuleConfigurationYamlSwapper.swap((ShadowRuleConfiguration) each)); + } + } + return result; + } + + @Override + public Collection swap(final OrchestrationSpringBootRulesConfigurationProperties configurations) { + Collection result = new LinkedList<>(); + if (null != configurations.getShardingRule()) { + result.add(shardingRuleConfigurationYamlSwapper.swap(configurations.getShardingRule())); + } + if (null != configurations.getMasterSlaveRule()) { + result.add(masterSlaveRuleConfigurationYamlSwapper.swap(configurations.getMasterSlaveRule())); + } + if (null != configurations.getEncryptRule()) { + result.add(encryptRuleConfigurationYamlSwapper.swap(configurations.getEncryptRule())); + } + if (null != configurations.getShadowRule()) { + result.add(shadowRuleConfigurationYamlSwapper.swap(configurations.getShadowRule())); + } + return result; + } +} diff --git a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/sharding/OrchestrationSpringBootRulesConfigurationProperties.java b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/sharding/OrchestrationSpringBootRulesConfigurationProperties.java index 47fc8c537c1542342b09b3dd5822bd27856cd254..d732726ae9c2d030a8242e5fb3778daaa7ca567c 100644 --- a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/sharding/OrchestrationSpringBootRulesConfigurationProperties.java +++ b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/sharding/OrchestrationSpringBootRulesConfigurationProperties.java @@ -19,14 +19,26 @@ package org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.shardin import lombok.Getter; import lombok.Setter; -import org.apache.shardingsphere.sharding.core.yaml.config.YamlRootRuleConfigurations; +import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration; +import org.apache.shardingsphere.sharding.core.yaml.config.masterslave.YamlMasterSlaveRuleConfiguration; +import org.apache.shardingsphere.sharding.core.yaml.config.shadow.YamlShadowRuleConfiguration; +import org.apache.shardingsphere.sharding.core.yaml.config.sharding.YamlShardingRuleConfiguration; +import org.apache.shardingsphere.underlying.common.yaml.config.YamlConfiguration; import org.springframework.boot.context.properties.ConfigurationProperties; /** - * Spring boot rules configuration properties for orchestration. + * Orchestration spring boot rules configuration properties. */ @ConfigurationProperties(prefix = "spring.shardingsphere.rules") @Getter @Setter -public final class OrchestrationSpringBootRulesConfigurationProperties extends YamlRootRuleConfigurations { +public class OrchestrationSpringBootRulesConfigurationProperties implements YamlConfiguration { + + private YamlShardingRuleConfiguration shardingRule; + + private YamlMasterSlaveRuleConfiguration masterSlaveRule; + + private YamlEncryptRuleConfiguration encryptRule; + + private YamlShadowRuleConfiguration shadowRule; } diff --git a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryEncryptTest.java b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryEncryptTest.java index bcc9979b74f8fed2568e28465617e8849fc3c067..389ac969f226867670bab8bcb99b086a8cd2f0f9 100644 --- a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryEncryptTest.java +++ b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryEncryptTest.java @@ -52,25 +52,28 @@ public class OrchestrationSpringBootRegistryEncryptTest { public static void init() { EmbedTestingServer.start(); TestCenterRepository testCenter = new TestCenterRepository(); - testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", - "dataSource: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" - + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" - + " properties:\n" - + " url: jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" - + " maxTotal: 100\n" - + " password: ''\n" - + " username: sa\n"); - testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", "encryptRule:\n encryptors:\n" - + " order_encrypt:\n" - + " props:\n" - + " aes.key.value: '123456'\n" - + " type: aes\n" - + " tables:\n" - + " t_order:\n" - + " columns:\n" - + " user_id:\n" - + " cipherColumn: user_id\n" - + " encryptor: order_encrypt\n"); + testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", "" + + "dataSource: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" + + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" + + " properties:\n" + + " url: jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" + + " maxTotal: 100\n" + + " password: ''\n" + + " username: sa\n"); + testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", "" + + "rules:\n" + + "- !!org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration\n" + + " encryptors:\n" + + " order_encrypt:\n" + + " props:\n" + + " aes.key.value: '123456'\n" + + " type: aes\n" + + " tables:\n" + + " t_order:\n" + + " columns:\n" + + " user_id:\n" + + " cipherColumn: user_id\n" + + " encryptor: order_encrypt\n"); testCenter.persist("/demo_spring_boot_ds_center/config/props", "sql.show: 'true'\n"); testCenter.persist("/demo_spring_boot_ds_center/registry/datasources", ""); } diff --git a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryMasterSlaveTest.java b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryMasterSlaveTest.java index c4efe44aadb33ae4085d51436c9144369ce1cb2d..cd7e74ac67384b1a6d60a1c6f22a1e6158f586b5 100644 --- a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryMasterSlaveTest.java +++ b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryMasterSlaveTest.java @@ -52,37 +52,39 @@ public class OrchestrationSpringBootRegistryMasterSlaveTest { public static void init() { EmbedTestingServer.start(); TestCenterRepository testCenter = new TestCenterRepository(); - testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", - "ds_master: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" - + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" - + " properties:\n" - + " url: jdbc:h2:mem:ds_master;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" - + " maxTotal: 16\n" - + " password: ''\n" - + " username: root\n" - + "ds_slave_0: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" - + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" - + " properties:\n" - + " url: jdbc:h2:mem:demo_ds_slave_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" - + " maxTotal: 16\n" - + " password: ''\n" - + " username: root\n" - + "ds_slave_1: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" - + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" - + " properties:\n" - + " url: jdbc:h2:mem:demo_ds_slave_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" - + " maxTotal: 16\n" - + " password: ''\n" - + " username: root\n"); - testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", "masterSlaveRule:\n" - + " dataSources:\n" - + " ds_ms:\n" - + " loadBalanceAlgorithmType: ROUND_ROBIN\n" - + " masterDataSourceName: ds_master\n" - + " name: ds_ms\n" - + " slaveDataSourceNames: \n" - + " - ds_slave_0\n" - + " - ds_slave_1\n"); + testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", "" + + "ds_master: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" + + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" + + " properties:\n" + + " url: jdbc:h2:mem:ds_master;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" + + " maxTotal: 16\n" + + " password: ''\n" + + " username: root\n" + + "ds_slave_0: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" + + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" + + " properties:\n" + + " url: jdbc:h2:mem:demo_ds_slave_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" + + " maxTotal: 16\n" + + " password: ''\n" + + " username: root\n" + + "ds_slave_1: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" + + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" + + " properties:\n" + + " url: jdbc:h2:mem:demo_ds_slave_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" + + " maxTotal: 16\n" + + " password: ''\n" + + " username: root\n"); + testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", "" + + "rules:\n" + + "- !!org.apache.shardingsphere.sharding.core.yaml.config.masterslave.YamlMasterSlaveRuleConfiguration\n" + + " dataSources:\n" + + " ds_ms:\n" + + " loadBalanceAlgorithmType: ROUND_ROBIN\n" + + " masterDataSourceName: ds_master\n" + + " name: ds_ms\n" + + " slaveDataSourceNames: \n" + + " - ds_slave_0\n" + + " - ds_slave_1\n"); testCenter.persist("/demo_spring_boot_ds_center/config/props", "{}\n"); testCenter.persist("/demo_spring_boot_ds_center/registry/datasources", ""); } diff --git a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryShardingTest.java b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryShardingTest.java index 201689646a1d31b041d2a85014c206e110878dca..b9d4ea390f16be7d54abe0a49d0631d1ac93b3f5 100644 --- a/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryShardingTest.java +++ b/sharding-spring/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/spring/boot/type/OrchestrationSpringBootRegistryShardingTest.java @@ -60,72 +60,77 @@ public class OrchestrationSpringBootRegistryShardingTest { public static void init() { EmbedTestingServer.start(); TestCenterRepository testCenter = new TestCenterRepository(); - testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", "ds: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" - + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" - + " properties:\n" - + " url: jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" - + " maxTotal: 16\n" - + " password: ''\n" - + " username: sa\n" - + "ds_0: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" - + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" - + " properties:\n" - + " url: jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" - + " maxTotal: 16\n" - + " password: ''\n" - + " username: sa\n" - + "ds_1: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" - + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" - + " properties:\n" - + " url: jdbc:h2:mem:ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" - + " maxTotal: 16\n" - + " password: ''\n" - + " username: sa\n"); - testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", "shardingRule:\n" - + " bindingTables:\n" - + " - t_order\n" - + " - t_order_item\n" - + " broadcastTables:\n" - + " - t_config\n" - + " defaultDatabaseStrategy:\n" - + " standard:\n" - + " shardingAlgorithm:\n" - + " type: INLINE\n" - + " props:\n" - + " algorithm.expression: ds_${user_id % 2}\n" - + " shardingColumn: user_id\n" - + " tables:\n" - + " t_order:\n" - + " actualDataNodes: ds_${0..1}.t_order_${0..1}\n" - + " keyGenerator:\n" - + " column: order_id\n" - + " props:\n" - + " worker.id: '123'\n" - + " type: SNOWFLAKE\n" - + " logicTable: t_order\n" - + " tableStrategy:\n" - + " standard:\n" - + " shardingAlgorithm:\n" - + " type: INLINE\n" - + " props:\n" - + " algorithm.expression: t_order_${order_id % 2}\n" - + " shardingColumn: order_id\n" - + " t_order_item:\n" - + " actualDataNodes: ds_${0..1}.t_order_item_${0..1}\n" - + " keyGenerator:\n" - + " column: order_item_id\n" - + " props:\n" - + " worker.id: '123'\n" - + " type: SNOWFLAKE\n" - + " logicTable: t_order_item\n" - + " tableStrategy:\n" - + " standard:\n" - + " shardingAlgorithm:\n" - + " type: INLINE\n" - + " props:\n" - + " algorithm.expression: t_order_item_${order_id % 2}\n" - + " shardingColumn: order_id\n"); - testCenter.persist("/demo_spring_boot_ds_center/config/props", "executor.size: '100'\nsql.show: 'true'\n"); + testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", "" + + "ds: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" + + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" + + " properties:\n" + + " url: jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" + + " maxTotal: 16\n" + + " password: ''\n" + + " username: sa\n" + + "ds_0: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" + + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" + + " properties:\n" + + " url: jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" + + " maxTotal: 16\n" + + " password: ''\n" + + " username: sa\n" + + "ds_1: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" + + " dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n" + + " properties:\n" + + " url: jdbc:h2:mem:ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n" + + " maxTotal: 16\n" + + " password: ''\n" + + " username: sa\n"); + testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", "" + + "rules:\n" + + "- !!org.apache.shardingsphere.sharding.core.yaml.config.sharding.YamlShardingRuleConfiguration\n" + + " bindingTables:\n" + + " - t_order\n" + + " - t_order_item\n" + + " broadcastTables:\n" + + " - t_config\n" + + " defaultDatabaseStrategy:\n" + + " standard:\n" + + " shardingAlgorithm:\n" + + " type: INLINE\n" + + " props:\n" + + " algorithm.expression: ds_${user_id % 2}\n" + + " shardingColumn: user_id\n" + + " tables:\n" + + " t_order:\n" + + " actualDataNodes: ds_${0..1}.t_order_${0..1}\n" + + " keyGenerator:\n" + + " column: order_id\n" + + " props:\n" + + " worker.id: '123'\n" + + " type: SNOWFLAKE\n" + + " logicTable: t_order\n" + + " tableStrategy:\n" + + " standard:\n" + + " shardingAlgorithm:\n" + + " type: INLINE\n" + + " props:\n" + + " algorithm.expression: t_order_${order_id % 2}\n" + + " shardingColumn: order_id\n" + + " t_order_item:\n" + + " actualDataNodes: ds_${0..1}.t_order_item_${0..1}\n" + + " keyGenerator:\n" + + " column: order_item_id\n" + + " props:\n" + + " worker.id: '123'\n" + + " type: SNOWFLAKE\n" + + " logicTable: t_order_item\n" + + " tableStrategy:\n" + + " standard:\n" + + " shardingAlgorithm:\n" + + " type: INLINE\n" + + " props:\n" + + " algorithm.expression: t_order_item_${order_id % 2}\n" + + " shardingColumn: order_id\n"); + testCenter.persist("/demo_spring_boot_ds_center/config/props", "" + + "executor.size: '100'\n" + + "sql.show: 'true'\n"); testCenter.persist("/demo_spring_boot_ds_center/registry/datasources", ""); } diff --git a/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/spring/boot/sharding/SpringBootRuleConfigurationsYamlSwapper.java b/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/spring/boot/sharding/SpringBootRuleConfigurationsYamlSwapper.java index 22ffc2883bb711c11e16365a74b4de9e522eb176..857a64695c65fbbac9abcaaefdd8587a8c6ab2cb 100644 --- a/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/spring/boot/sharding/SpringBootRuleConfigurationsYamlSwapper.java +++ b/sharding-spring/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/org/apache/shardingsphere/shardingjdbc/spring/boot/sharding/SpringBootRuleConfigurationsYamlSwapper.java @@ -32,7 +32,7 @@ import java.util.Collection; import java.util.LinkedList; /** - * Rule root configurations YAML swapper. + * Spring boot rule configurations YAML swapper. */ public final class SpringBootRuleConfigurationsYamlSwapper implements YamlSwapper> {