This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 b36794c5ba6 Remove DataSourceDefinitionViolationException (#30766)
b36794c5ba6 is described below
commit b36794c5ba6267d488aebf01dabc14696850cc97
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Apr 4 12:52:06 2024 +0800
Remove DataSourceDefinitionViolationException (#30766)
* Refactor YamlDatabaseConfigurationImportExecutor
* Remove DataSourceDefinitionViolationException
---
.../DataSourceDefinitionViolationException.java | 33 ----------------------
.../MissingRequiredDataSourcesException.java | 32 ---------------------
.../YamlDatabaseConfigurationImportExecutor.java | 16 +++++------
.../ImportDatabaseConfigurationExecutorTest.java | 6 ++--
.../ral/updatable/ImportMetaDataExecutorTest.java | 4 +--
5 files changed, 13 insertions(+), 78 deletions(-)
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/datasource/DataSourceDefinitionViolationException.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/datasource/DataSourceDefinitionViolationException.java
deleted file mode 100644
index 7539094ea1b..00000000000
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/datasource/DataSourceDefinitionViolationException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.distsql.handler.exception.datasource;
-
-import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.DistSQLException;
-import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.SQLState;
-
-/**
- * Data source definition violation exception.
- */
-public abstract class DataSourceDefinitionViolationException extends
DistSQLException {
-
- private static final long serialVersionUID = -3318829232811230364L;
-
- protected DataSourceDefinitionViolationException(final SQLState sqlState,
final int errorCode, final String reason, final Object... messageArgs) {
- super(sqlState, errorCode, reason, messageArgs);
- }
-}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/datasource/MissingRequiredDataSourcesException.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/datasource/MissingRequiredDataSourcesException.java
deleted file mode 100644
index 1a8def0dc41..00000000000
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/datasource/MissingRequiredDataSourcesException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.distsql.handler.exception.datasource;
-
-import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Missing required data sources exception.
- */
-public final class MissingRequiredDataSourcesException extends
DataSourceDefinitionViolationException {
-
- private static final long serialVersionUID = -7846645449809082667L;
-
- public MissingRequiredDataSourcesException(final String message) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 201, message);
- }
-}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
index 268a9e05cfb..c4cfdf45114 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
@@ -17,11 +17,9 @@
package org.apache.shardingsphere.proxy.backend.util;
-import
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationCheckEngine;
-import
org.apache.shardingsphere.distsql.handler.exception.datasource.MissingRequiredDataSourcesException;
-import
org.apache.shardingsphere.infra.exception.metadata.resource.storageunit.StorageUnitsOperateException;
import
org.apache.shardingsphere.distsql.handler.validate.DistSQLDataSourcePoolPropertiesValidator;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationCheckEngine;
import org.apache.shardingsphere.infra.database.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.datasource.pool.config.DataSourceConfiguration;
@@ -29,8 +27,10 @@ import
org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCre
import
org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator;
import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
+import
org.apache.shardingsphere.infra.exception.core.external.sql.ShardingSphereSQLException;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException;
-import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.DistSQLException;
+import
org.apache.shardingsphere.infra.exception.metadata.resource.storageunit.EmptyStorageUnitException;
+import
org.apache.shardingsphere.infra.exception.metadata.resource.storageunit.StorageUnitsOperateException;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
@@ -78,12 +78,12 @@ public final class YamlDatabaseConfigurationImportExecutor {
public void importDatabaseConfiguration(final
YamlProxyDatabaseConfiguration yamlConfig) {
String databaseName = yamlConfig.getDatabaseName();
checkDatabase(databaseName);
- checkDataSources(yamlConfig.getDataSources());
+ checkDataSources(databaseName, yamlConfig.getDataSources());
addDatabase(databaseName);
addDataSources(databaseName, yamlConfig.getDataSources());
try {
addRules(databaseName, yamlConfig.getRules());
- } catch (final DistSQLException ex) {
+ } catch (final ShardingSphereSQLException ex) {
dropDatabase(databaseName);
throw ex;
}
@@ -97,8 +97,8 @@ public final class YamlDatabaseConfigurationImportExecutor {
}
}
- private void checkDataSources(final Map<String,
YamlProxyDataSourceConfiguration> dataSources) {
- ShardingSpherePreconditions.checkState(!dataSources.isEmpty(), () ->
new MissingRequiredDataSourcesException("Data source configurations in imported
config is required"));
+ private void checkDataSources(final String databaseName, final Map<String,
YamlProxyDataSourceConfiguration> dataSources) {
+ ShardingSpherePreconditions.checkState(!dataSources.isEmpty(), () ->
new EmptyStorageUnitException(databaseName));
}
private void addDatabase(final String databaseName) {
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
index 941f19fd0c0..10b81f0bc26 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
import lombok.SneakyThrows;
-import
org.apache.shardingsphere.distsql.handler.exception.datasource.MissingRequiredDataSourcesException;
-import
org.apache.shardingsphere.infra.exception.metadata.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.validate.DistSQLDataSourcePoolPropertiesValidator;
import
org.apache.shardingsphere.distsql.statement.ral.updatable.ImportDatabaseConfigurationStatement;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
@@ -27,6 +25,8 @@ import
org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException;
+import
org.apache.shardingsphere.infra.exception.metadata.resource.storageunit.EmptyStorageUnitException;
+import
org.apache.shardingsphere.infra.exception.metadata.rule.DuplicateRuleException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
@@ -110,7 +110,7 @@ class ImportDatabaseConfigurationExecutorTest {
@Test
void assertImportEmptyDataSource() {
- assertThrows(MissingRequiredDataSourcesException.class, () ->
assertExecute("sharding_db", "/conf/import/database-empty-data-source.yaml"));
+ assertThrows(EmptyStorageUnitException.class, () ->
assertExecute("sharding_db", "/conf/import/database-empty-data-source.yaml"));
}
@Test
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java
index 1772c3f1b80..632f54102f9 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
-import
org.apache.shardingsphere.distsql.handler.exception.datasource.MissingRequiredDataSourcesException;
import
org.apache.shardingsphere.distsql.statement.ral.updatable.ImportMetaDataStatement;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException;
+import
org.apache.shardingsphere.infra.exception.metadata.resource.storageunit.EmptyStorageUnitException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
@@ -80,7 +80,7 @@ class ImportMetaDataExecutorTest {
void assertCheckImportEmptyMetaData() {
init(null);
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
- assertThrows(MissingRequiredDataSourcesException.class, () ->
executor.executeUpdate(
+ assertThrows(EmptyStorageUnitException.class, () ->
executor.executeUpdate(
new ImportMetaDataStatement(null,
Objects.requireNonNull(ImportMetaDataExecutorTest.class.getResource(featureMap.get(EMPTY))).getPath()),
contextManager));
}