You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/08/06 02:30:40 UTC
[shardingsphere] branch master updated: JDBC-GOVERNANCE ADD SCHEMA
NAME API (#11665)
This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 4ee3bce JDBC-GOVERNANCE ADD SCHEMA NAME API (#11665)
4ee3bce is described below
commit 4ee3bce7a7da9218fa56aea59213bdd95b8d4309
Author: zhaojinchao <33...@users.noreply.github.com>
AuthorDate: Fri Aug 6 10:30:10 2021 +0800
JDBC-GOVERNANCE ADD SCHEMA NAME API (#11665)
---
.../GovernanceShardingSphereDataSourceFactory.java | 54 +++++++++++++++++++++-
...lGovernanceShardingSphereDataSourceFactory.java | 24 +++++-----
.../GovernanceShardingSphereDataSource.java | 33 +++++++++++++
.../sharding/configWithDataSourceWithProps.yaml | 2 +
.../ShardingSphereGovernanceAutoConfiguration.java | 8 +++-
.../constants/SchemaNameBeanDefinitionTag.java | 30 ++++++++++++
.../parser/DataSourceBeanDefinitionParser.java | 11 ++++-
.../resources/META-INF/namespace/governance.xsd | 1 +
8 files changed, 147 insertions(+), 16 deletions(-)
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/GovernanceShardingSphereDataSourceFactory.java b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/GovernanceShardingSphereDataSourceFactory.java
index 573076a..91c02cb 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/GovernanceShardingSphereDataSourceFactory.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/GovernanceShardingSphereDataSourceFactory.java
@@ -21,8 +21,8 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.driver.governance.internal.datasource.GovernanceShardingSphereDataSource;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
+import org.apache.shardingsphere.infra.database.DefaultSchema;
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -58,6 +58,25 @@ public final class GovernanceShardingSphereDataSourceFactory {
/**
* Create ShardingSphere data source.
*
+ * @param dataSourceMap data source map
+ * @param ruleConfigurations rule configurations
+ * @param governanceConfig governance configuration
+ * @param props properties for data source
+ * @param schemaName schema name configuration
+ * @return ShardingSphere data source
+ * @throws SQLException SQL exception
+ */
+ public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigurations,
+ final Properties props, final GovernanceConfiguration governanceConfig, final String schemaName) throws SQLException {
+ if (null == ruleConfigurations || ruleConfigurations.isEmpty()) {
+ return createDataSource(governanceConfig, schemaName);
+ }
+ return new GovernanceShardingSphereDataSource(dataSourceMap, ruleConfigurations, props, governanceConfig, schemaName);
+ }
+
+ /**
+ * Create ShardingSphere data source.
+ *
* @param dataSource data source
* @param ruleConfigurations rule configurations
* @param governanceConfig governance configuration
@@ -69,7 +88,26 @@ public final class GovernanceShardingSphereDataSourceFactory {
final Properties props, final GovernanceConfiguration governanceConfig) throws SQLException {
Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
dataSourceMap.put(DefaultSchema.LOGIC_NAME, dataSource);
- return createDataSource(dataSourceMap, ruleConfigurations, props, governanceConfig);
+ return createDataSource(dataSourceMap, ruleConfigurations, props, governanceConfig, DefaultSchema.LOGIC_NAME);
+ }
+
+ /**
+ * Create ShardingSphere data source.
+ *
+ * @param dataSource data source
+ * @param ruleConfigurations rule configurations
+ * @param governanceConfig governance configuration
+ * @param props properties for data source
+ * @param schemaName schema name configuration
+ * @return ShardingSphere data source
+ * @throws SQLException SQL exception
+ */
+ public static DataSource createDataSource(final DataSource dataSource, final Collection<RuleConfiguration> ruleConfigurations,
+ final Properties props, final GovernanceConfiguration governanceConfig,
+ final String schemaName) throws SQLException {
+ Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
+ dataSourceMap.put(schemaName, dataSource);
+ return createDataSource(dataSourceMap, ruleConfigurations, props, governanceConfig, schemaName);
}
/**
@@ -82,4 +120,16 @@ public final class GovernanceShardingSphereDataSourceFactory {
public static DataSource createDataSource(final GovernanceConfiguration governanceConfig) throws SQLException {
return new GovernanceShardingSphereDataSource(governanceConfig);
}
+
+ /**
+ * Create ShardingSphere data source.
+ *
+ * @param governanceConfig governance configuration
+ * @param schemaName schema name configuration
+ * @return ShardingSphere data source
+ * @throws SQLException SQL exception
+ */
+ public static DataSource createDataSource(final GovernanceConfiguration governanceConfig, final String schemaName) throws SQLException {
+ return new GovernanceShardingSphereDataSource(governanceConfig, schemaName);
+ }
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/yaml/YamlGovernanceShardingSphereDataSourceFactory.java b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/yaml/YamlGovernanceShardingSphereDataSourceFactory.java
index 4cf06d4..b2c592f 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/yaml/YamlGovernanceShardingSphereDataSourceFactory.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/yaml/YamlGovernanceShardingSphereDataSourceFactory.java
@@ -53,7 +53,7 @@ public final class YamlGovernanceShardingSphereDataSourceFactory {
public static DataSource createDataSource(final File yamlFile) throws SQLException, IOException {
YamlGovernanceRootRuleConfigurations configurations = unmarshal(yamlFile);
return createDataSource(new YamlDataSourceConfigurationSwapper().swapToDataSources(configurations.getDataSources()),
- configurations, configurations.getProps(), configurations.getGovernance());
+ configurations, configurations.getProps(), configurations.getGovernance(), configurations.getSchemaName());
}
/**
@@ -67,7 +67,7 @@ public final class YamlGovernanceShardingSphereDataSourceFactory {
*/
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final File yamlFile) throws SQLException, IOException {
YamlGovernanceRootRuleConfigurations configurations = unmarshal(yamlFile);
- return createDataSource(dataSourceMap, configurations, configurations.getProps(), configurations.getGovernance());
+ return createDataSource(dataSourceMap, configurations, configurations.getProps(), configurations.getGovernance(), configurations.getSchemaName());
}
/**
@@ -81,7 +81,7 @@ public final class YamlGovernanceShardingSphereDataSourceFactory {
public static DataSource createDataSource(final byte[] yamlBytes) throws SQLException, IOException {
YamlGovernanceRootRuleConfigurations configurations = unmarshal(yamlBytes);
return createDataSource(new YamlDataSourceConfigurationSwapper().swapToDataSources(configurations.getDataSources()),
- configurations, configurations.getProps(), configurations.getGovernance());
+ configurations, configurations.getProps(), configurations.getGovernance(), configurations.getSchemaName());
}
/**
@@ -95,27 +95,29 @@ public final class YamlGovernanceShardingSphereDataSourceFactory {
*/
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final byte[] yamlBytes) throws SQLException, IOException {
YamlGovernanceRootRuleConfigurations configurations = unmarshal(yamlBytes);
- return createDataSource(dataSourceMap, configurations, configurations.getProps(), configurations.getGovernance());
+ return createDataSource(dataSourceMap, configurations, configurations.getProps(), configurations.getGovernance(), configurations.getSchemaName());
}
private static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final YamlGovernanceRootRuleConfigurations configurations,
- final Properties props, final YamlGovernanceConfiguration governance) throws SQLException {
+ final Properties props, final YamlGovernanceConfiguration governance,
+ final String schemaName) throws SQLException {
if (configurations.getRules().isEmpty() || dataSourceMap.isEmpty()) {
- return createDataSourceWithoutRules(governance);
+ return createDataSourceWithoutRules(governance, schemaName);
} else {
return createDataSourceWithRules(dataSourceMap, new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(configurations.getRules()),
- props, governance);
+ props, governance, schemaName);
}
}
- private static DataSource createDataSourceWithoutRules(final YamlGovernanceConfiguration governance) throws SQLException {
- return new GovernanceShardingSphereDataSource(YamlGovernanceConfigurationSwapperUtil.marshal(governance));
+ private static DataSource createDataSourceWithoutRules(final YamlGovernanceConfiguration governance, final String schemaName) throws SQLException {
+ return new GovernanceShardingSphereDataSource(YamlGovernanceConfigurationSwapperUtil.marshal(governance), schemaName);
}
private static DataSource createDataSourceWithRules(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigurations,
- final Properties props, final YamlGovernanceConfiguration governance) throws SQLException {
+ final Properties props, final YamlGovernanceConfiguration governance,
+ final String schemaName) throws SQLException {
return new GovernanceShardingSphereDataSource(dataSourceMap, ruleConfigurations, props,
- YamlGovernanceConfigurationSwapperUtil.marshal(governance));
+ YamlGovernanceConfigurationSwapperUtil.marshal(governance), schemaName);
}
private static YamlGovernanceRootRuleConfigurations unmarshal(final File yamlFile) throws IOException {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
index b7e4d51..4ae5c84 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.driver.governance.internal.datasource;
import lombok.Getter;
+import org.apache.commons.lang.StringUtils;
import org.apache.shardingsphere.driver.governance.internal.state.DriverStateContext;
import org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOperationDataSource;
import org.apache.shardingsphere.governance.context.metadata.GovernanceMetaDataContexts;
@@ -64,7 +65,21 @@ public final class GovernanceShardingSphereDataSource extends AbstractUnsupporte
@Getter
private final TransactionContexts transactionContexts;
+ private final String schemaName;
+
public GovernanceShardingSphereDataSource(final GovernanceConfiguration governanceConfig) throws SQLException {
+ schemaName = DefaultSchema.LOGIC_NAME;
+ // TODO new GovernanceRule from SPI
+ governanceRule = new GovernanceRule(governanceConfig);
+ DistMetaDataPersistService persistService = new DistMetaDataPersistService(governanceRule.getRegistryCenter().getRepository());
+ metaDataContexts = new GovernanceMetaDataContexts(createMetaDataContexts(persistService), persistService, governanceRule.getRegistryCenter());
+ String xaTransactionMangerType = metaDataContexts.getProps().getValue(ConfigurationPropertyKey.XA_TRANSACTION_MANAGER_TYPE);
+ transactionContexts = createTransactionContexts(metaDataContexts.getDefaultMetaData().getResource().getDatabaseType(),
+ metaDataContexts.getDefaultMetaData().getResource().getDataSources(), xaTransactionMangerType);
+ }
+
+ public GovernanceShardingSphereDataSource(final GovernanceConfiguration governanceConfig, final String schemaName) throws SQLException {
+ this.schemaName = getSchemaName(schemaName);
// TODO new GovernanceRule from SPI
governanceRule = new GovernanceRule(governanceConfig);
DistMetaDataPersistService persistService = new DistMetaDataPersistService(governanceRule.getRegistryCenter().getRepository());
@@ -76,6 +91,20 @@ public final class GovernanceShardingSphereDataSource extends AbstractUnsupporte
public GovernanceShardingSphereDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigs,
final Properties props, final GovernanceConfiguration governanceConfig) throws SQLException {
+ schemaName = DefaultSchema.LOGIC_NAME;
+ // TODO new GovernanceRule from SPI
+ governanceRule = new GovernanceRule(governanceConfig);
+ DistMetaDataPersistService persistService = new DistMetaDataPersistService(governanceRule.getRegistryCenter().getRepository());
+ metaDataContexts = new GovernanceMetaDataContexts(createMetaDataContexts(persistService, dataSourceMap, ruleConfigs, props), persistService, governanceRule.getRegistryCenter());
+ String xaTransactionMangerType = metaDataContexts.getProps().getValue(ConfigurationPropertyKey.XA_TRANSACTION_MANAGER_TYPE);
+ transactionContexts = createTransactionContexts(metaDataContexts.getDefaultMetaData().getResource().getDatabaseType(),
+ metaDataContexts.getDefaultMetaData().getResource().getDataSources(), xaTransactionMangerType);
+ uploadLocalConfiguration(persistService, governanceRule.getRegistryCenter(), ruleConfigs, governanceConfig.isOverwrite());
+ }
+
+ public GovernanceShardingSphereDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigs,
+ final Properties props, final GovernanceConfiguration governanceConfig, final String schemaName) throws SQLException {
+ this.schemaName = getSchemaName(schemaName);
// TODO new GovernanceRule from SPI
governanceRule = new GovernanceRule(governanceConfig);
DistMetaDataPersistService persistService = new DistMetaDataPersistService(governanceRule.getRegistryCenter().getRepository());
@@ -86,6 +115,10 @@ public final class GovernanceShardingSphereDataSource extends AbstractUnsupporte
uploadLocalConfiguration(persistService, governanceRule.getRegistryCenter(), ruleConfigs, governanceConfig.isOverwrite());
}
+ private String getSchemaName(final String schemaName) {
+ return StringUtils.isNotEmpty(schemaName) ? schemaName : DefaultSchema.LOGIC_NAME;
+ }
+
private StandardMetaDataContexts createMetaDataContexts(final DistMetaDataPersistService persistService) throws SQLException {
Map<String, DataSourceConfiguration> dataSourceConfigs = persistService.getDataSourceService().load(DefaultSchema.LOGIC_NAME);
Collection<RuleConfiguration> ruleConfigs = persistService.getSchemaRuleService().load(DefaultSchema.LOGIC_NAME);
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/resources/yaml/integrate/sharding/configWithDataSourceWithProps.yaml b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/resources/yaml/integrate/sharding/configWithDataSourceWithProps.yaml
index be44b87..69d12f1 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/resources/yaml/integrate/sharding/configWithDataSourceWithProps.yaml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/resources/yaml/integrate/sharding/configWithDataSourceWithProps.yaml
@@ -15,6 +15,8 @@
# limitations under the License.
#
+schemaName: logic_db
+
dataSources:
db0:
dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/governance/ShardingSphereGovernanceAutoConfiguration.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/governance/ShardingSphereGovernanceAutoConfi [...]
index 01767e2..0d715ee 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/governance/ShardingSphereGovernanceAutoConfiguration.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/governance/ShardingSphereGovernanceAutoConfiguration.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.governance.repository.api.config.GovernanceConf
import org.apache.shardingsphere.spring.boot.datasource.DataSourceMapSetter;
import org.apache.shardingsphere.spring.boot.governance.common.GovernanceSpringBootRootConfiguration;
import org.apache.shardingsphere.spring.boot.governance.rule.LocalRulesCondition;
+import org.apache.shardingsphere.spring.boot.schema.SchemaNameSetter;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
@@ -66,6 +67,8 @@ public class ShardingSphereGovernanceAutoConfiguration implements EnvironmentAwa
private final RegistryCenterConfigurationYamlSwapper swapper = new RegistryCenterConfigurationYamlSwapper();
+ private String schemaName;
+
/**
* Get governance configuration.
*
@@ -109,13 +112,14 @@ public class ShardingSphereGovernanceAutoConfiguration implements EnvironmentAwa
@Override
public final void setEnvironment(final Environment environment) {
dataSourceMap.putAll(DataSourceMapSetter.getDataSourceMap(environment));
+ schemaName = SchemaNameSetter.getSchemaName(environment);
}
private DataSource createDataSourceWithRules(final List<RuleConfiguration> ruleConfigs, final GovernanceConfiguration governanceConfig) throws SQLException {
- return new GovernanceShardingSphereDataSource(dataSourceMap, ruleConfigs, root.getProps(), governanceConfig);
+ return new GovernanceShardingSphereDataSource(dataSourceMap, ruleConfigs, root.getProps(), governanceConfig, schemaName);
}
private DataSource createDataSourceWithoutRules(final GovernanceConfiguration governanceConfig) throws SQLException {
- return new GovernanceShardingSphereDataSource(governanceConfig);
+ return new GovernanceShardingSphereDataSource(governanceConfig, schemaName);
}
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/constants/SchemaNameBeanDefinitionTag.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/constants/SchemaNameBeanDefinitio [...]
new file mode 100644
index 0000000..649e1e7
--- /dev/null
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/constants/SchemaNameBeanDefinitionTag.java
@@ -0,0 +1,30 @@
+/*
+ * 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.spring.namespace.governance.constants;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Schema name bean definition tag.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SchemaNameBeanDefinitionTag {
+
+ public static final String ROOT_TAG = "schema-name";
+}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/parser/DataSourceBeanDefinitionParser.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/parser/DataSourceBeanDefinitionPa [...]
index 7ffea1f..dbb365b 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/parser/DataSourceBeanDefinitionParser.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/parser/DataSourceBeanDefinitionParser.java
@@ -21,7 +21,9 @@ import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import org.apache.shardingsphere.driver.governance.internal.datasource.GovernanceShardingSphereDataSource;
import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
+import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.spring.namespace.governance.constants.DataSourceBeanDefinitionTag;
+import org.apache.shardingsphere.spring.namespace.governance.constants.SchemaNameBeanDefinitionTag;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -30,6 +32,7 @@ import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
@@ -56,9 +59,10 @@ public final class DataSourceBeanDefinitionParser extends AbstractBeanDefinition
factory.addConstructorArgValue(parseDataSources(element));
factory.addConstructorArgValue(parseRuleConfigurations(element));
factory.addConstructorArgValue(parseProperties(element, parserContext));
- factory.setDestroyMethodName("close");
}
factory.addConstructorArgValue(getGovernanceConfiguration(element));
+ factory.addConstructorArgValue(parseSchemaName(element));
+ factory.setDestroyMethodName("close");
}
private Map<String, RuntimeBeanReference> parseDataSources(final Element element) {
@@ -90,4 +94,9 @@ public final class DataSourceBeanDefinitionParser extends AbstractBeanDefinition
factory.addConstructorArgValue(element.getAttribute(DataSourceBeanDefinitionTag.OVERWRITE_ATTRIBUTE));
return factory.getBeanDefinition();
}
+
+ private String parseSchemaName(final Element element) {
+ String schemaName = element.getAttribute(SchemaNameBeanDefinitionTag.ROOT_TAG);
+ return StringUtils.isEmpty(schemaName) ? DefaultSchema.LOGIC_NAME : schemaName;
+ }
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/resources/META-INF/namespace/governance.xsd b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/resources/META-INF/namespace/governance.xsd
index de03f52..8542786 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/resources/META-INF/namespace/governance.xsd
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/resources/META-INF/namespace/governance.xsd
@@ -34,6 +34,7 @@
<xsd:attribute name="rule-refs" type="xsd:string" />
<xsd:attribute name="config-center-ref" type="xsd:string" />
<xsd:attribute name="overwrite" type="xsd:string" default="false" />
+ <xsd:attribute name="schema-name" type="xsd:string" />
</xsd:complexType>
</xsd:element>