You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/07/03 17:26:45 UTC
[shardingsphere] branch master updated: Refactor
RuleDefinitionViolationException to extend SQLException (#11129)
This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 18ab59a Refactor RuleDefinitionViolationException to extend SQLException (#11129)
18ab59a is described below
commit 18ab59a5ac8de3a2c2d2c1dac39de3041b9c36f3
Author: Liang Zhang <te...@163.com>
AuthorDate: Sun Jul 4 01:26:11 2021 +0800
Refactor RuleDefinitionViolationException to extend SQLException (#11129)
* Refactor RDLBackendHandler
* Refactor RuleDefinitionViolationException to extend SQLException
---
.../DatabaseDiscoveryRuleNotExistedException.java | 2 +-
.../InvalidDatabaseDiscoveryTypesException.java | 2 +-
...AlterDatabaseDiscoveryRuleStatementUpdater.java | 13 +++--
...reateDatabaseDiscoveryRuleStatementUpdater.java | 10 ++--
.../DropDatabaseDiscoveryRuleStatementUpdater.java | 9 ++--
...rDatabaseDiscoveryRuleStatementUpdaterTest.java | 9 ++--
...eDatabaseDiscoveryRuleStatementUpdaterTest.java | 7 +--
...pDatabaseDiscoveryRuleStatementUpdaterTest.java | 5 +-
.../exception/EncryptRuleNotExistedException.java | 2 +-
.../exception/InvalidEncryptorsException.java | 2 +-
.../update/AlterEncryptRuleStatementUpdater.java | 11 +++--
.../update/CreateEncryptRuleStatementUpdater.java | 8 ++--
.../update/DropEncryptRuleStatementUpdater.java | 10 ++--
.../AlterEncryptRuleStatementUpdaterTest.java | 7 +--
.../CreateEncryptRuleStatementUpdaterTest.java | 5 +-
.../DropEncryptRuleStatementUpdaterTest.java | 5 +-
.../exception/InvalidLoadBalancersException.java | 2 +-
.../ReadwriteSplittingRuleNotExistedException.java | 2 +-
...lterReadwriteSplittingRuleStatementUpdater.java | 14 ++++--
...eateReadwriteSplittingRuleStatementUpdater.java | 11 +++--
...DropReadwriteSplittingRuleStatementUpdater.java | 9 ++--
...ReadwriteSplittingRuleStatementUpdaterTest.java | 9 ++--
...ReadwriteSplittingRuleStatementUpdaterTest.java | 7 +--
...ReadwriteSplittingRuleStatementUpdaterTest.java | 5 +-
.../exception/DuplicateBindingTablesException.java | 2 +-
.../exception/DuplicateTablesException.java | 2 +-
.../exception/InvalidKeyGeneratorsException.java | 2 +-
.../InvalidShardingAlgorithmsException.java | 2 +-
...ShardingBindingTableRuleNotExistsException.java | 2 +-
...ShardingBroadcastTableRuleExistedException.java | 2 +-
...ardingBroadcastTableRuleNotExistsException.java | 2 +-
.../ShardingTableRuleNotExistedException.java | 2 +-
.../ShardingTableRulesInUsedException.java | 2 +-
...erShardingBindingTableRuleStatementUpdater.java | 10 ++--
...ShardingBroadcastTableRuleStatementUpdater.java | 5 +-
.../AlterShardingTableRuleStatementUpdater.java | 17 ++++---
...teShardingBindingTableRuleStatementUpdater.java | 11 +++--
...ShardingBroadcastTableRuleStatementUpdater.java | 5 +-
.../CreateShardingTableRuleStatementUpdater.java | 11 +++--
...opShardingBindingTableRuleStatementUpdater.java | 5 +-
...ShardingBroadcastTableRuleStatementUpdater.java | 5 +-
.../DropShardingTableRuleStatementUpdater.java | 11 +++--
....shardingsphere.infra.distsql.update.RDLUpdater | 17 +++++++
...ardingBindingTableRuleStatementUpdaterTest.java | 5 +-
...dingBroadcastTableRuleStatementUpdaterTest.java | 3 +-
...AlterShardingTableRuleStatementUpdaterTest.java | 9 ++--
...ardingBindingTableRuleStatementUpdaterTest.java | 5 +-
...reateShardingTableRuleStatementUpdaterTest.java | 5 +-
...ardingBindingTableRuleStatementUpdaterTest.java | 5 +-
...dingBroadcastTableRuleStatementUpdaterTest.java | 5 +-
.../DropShardingTableRuleStatementUpdaterTest.java | 7 +--
.../infra/distsql/update/RDLCreateUpdater.java | 4 +-
.../infra/distsql/update/RDLUpdater.java | 4 +-
.../exception/rule/DuplicateResourceException.java | 2 +-
.../rule/DuplicateRuleNamesException.java | 2 +-
.../exception/rule/InvalidResourceException.java | 2 +-
.../exception/rule/ResourceInUsedException.java | 2 +-
.../rule/ResourceNotExistedException.java | 2 +-
.../rule/RuleDefinitionViolationException.java | 15 ++----
.../backend/text/SchemaRequiredBackendHandler.java | 5 +-
.../distsql/rdl/{impl => }/RDLBackendHandler.java | 55 +++++++++++++++-------
.../text/distsql/rdl/RDLBackendHandlerFactory.java | 1 -
.../rdl/impl/AddResourceBackendHandler.java | 9 ++--
.../rdl/impl/DropDatabaseBackendHandler.java | 3 +-
.../rdl/impl/DropResourceBackendHandler.java | 9 ++--
.../rdl/impl/AddResourceBackendHandlerTest.java | 3 +-
.../frontend/mysql/err/MySQLErrPacketFactory.java | 10 +---
.../mysql/err/MySQLErrPacketFactoryTest.java | 4 +-
68 files changed, 275 insertions(+), 182 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/exception/DatabaseDiscoveryRuleNotExistedException.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/exception/DatabaseDisc [...]
index b8b81ac..89510b6 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/exception/DatabaseDiscoveryRuleNotExistedException.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/exception/DatabaseDiscoveryRuleNotExistedException.java
@@ -29,6 +29,6 @@ public final class DatabaseDiscoveryRuleNotExistedException extends RuleDefiniti
private static final long serialVersionUID = 1293361372683913161L;
public DatabaseDiscoveryRuleNotExistedException(final String schemaName, final Collection<String> ruleNames) {
- super(1116, "C1116", String.format("Database discovery rules %s do not exist in schema %s.", ruleNames, schemaName));
+ super(1116, String.format("Database discovery rules %s do not exist in schema %s.", ruleNames, schemaName));
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/exception/InvalidDatabaseDiscoveryTypesException.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/exception/InvalidDatabas [...]
index 0a4b66b..7d7584a 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/exception/InvalidDatabaseDiscoveryTypesException.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/exception/InvalidDatabaseDiscoveryTypesException.java
@@ -29,6 +29,6 @@ public final class InvalidDatabaseDiscoveryTypesException extends RuleDefinition
private static final long serialVersionUID = -6919328513016324005L;
public InvalidDatabaseDiscoveryTypesException(final Collection<String> databaseDiscoveryTypes) {
- super(1115, "C1115", String.format("Invalid database discovery types %s.", databaseDiscoveryTypes));
+ super(1115, String.format("Invalid database discovery types %s.", databaseDiscoveryTypes));
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDis [...]
index 24dc7f9..19696d2 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatab
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.distsql.update.RDLAlterUpdater;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
@@ -50,20 +51,22 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RDLAlte
@Override
public void checkSQLStatement(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement,
- final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
checkToBeAlteredRules(schemaName, sqlStatement, currentRuleConfig);
checkToBeAlteredResources(schemaName, sqlStatement, resource);
checkToBeAlteredDiscoveryType(sqlStatement);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement,
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DatabaseDiscoveryRuleNotExistedException {
if (null == currentRuleConfig) {
throw new DatabaseDiscoveryRuleNotExistedException(schemaName, getToBeAlteredRuleNames(sqlStatement));
}
}
- private void checkToBeAlteredRules(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ private void checkToBeAlteredRules(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement,
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DatabaseDiscoveryRuleNotExistedException {
Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
Collection<String> notExistedRuleNames = getToBeAlteredRuleNames(sqlStatement).stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
if (!notExistedRuleNames.isEmpty()) {
@@ -75,7 +78,7 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RDLAlte
return sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getName).collect(Collectors.toList());
}
- private void checkToBeAlteredResources(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereResource resource) {
+ private void checkToBeAlteredResources(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereResource resource) throws ResourceNotExistedException {
Collection<String> notExistedResources = resource.getNotExistedResources(getToBeAlteredResourceNames(sqlStatement));
if (!notExistedResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistedResources);
@@ -88,7 +91,7 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RDLAlte
return result;
}
- private void checkToBeAlteredDiscoveryType(final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
+ private void checkToBeAlteredDiscoveryType(final AlterDatabaseDiscoveryRuleStatement sqlStatement) throws InvalidDatabaseDiscoveryTypesException {
Collection<String> notExistedDiscoveryTypes = getToBeAlteredDiscoveryTypeNames(sqlStatement).stream()
.filter(each -> !TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryType.class, each, new Properties()).isPresent()).collect(Collectors.toList());
if (!notExistedDiscoveryTypes.isEmpty()) {
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseD [...]
index bbd1cce..01d511d 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.distsql.update.RDLCreateUpdater;
import org.apache.shardingsphere.infra.exception.rule.DuplicateRuleNamesException;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
@@ -49,13 +50,14 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdater implements RDLCre
@Override
public void checkSQLStatement(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement,
- final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkDuplicateRuleNames(schemaName, sqlStatement, currentRuleConfig);
checkToBeCreatedResources(schemaName, sqlStatement, resource);
checkToBeCreatedDiscoverTypes(sqlStatement);
}
- private void checkDuplicateRuleNames(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ private void checkDuplicateRuleNames(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement,
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DuplicateRuleNamesException {
if (null != currentRuleConfig) {
Collection<String> existRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toList());
Collection<String> duplicateRuleNames = sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getName).filter(existRuleNames::contains).collect(Collectors.toSet());
@@ -75,7 +77,7 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdater implements RDLCre
.collect(Collectors.toSet());
}
- private void checkToBeCreatedResources(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereResource resource) {
+ private void checkToBeCreatedResources(final String schemaName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereResource resource) throws ResourceNotExistedException {
Collection<String> resources = new LinkedHashSet<>();
sqlStatement.getRules().forEach(each -> resources.addAll(each.getDataSources()));
Collection<String> notExistResources = resource.getNotExistedResources(resources);
@@ -84,7 +86,7 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdater implements RDLCre
}
}
- private void checkToBeCreatedDiscoverTypes(final CreateDatabaseDiscoveryRuleStatement sqlStatement) {
+ private void checkToBeCreatedDiscoverTypes(final CreateDatabaseDiscoveryRuleStatement sqlStatement) throws InvalidDatabaseDiscoveryTypesException {
Collection<String> notExistedDiscoveryTypes = sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getDiscoveryTypeName).distinct()
.filter(each -> !TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryType.class, each, new Properties()).isPresent()).collect(Collectors.toList());
if (!notExistedDiscoveryTypes.isEmpty()) {
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDisco [...]
index 79965c6..e1dd48b 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDa
import org.apache.shardingsphere.dbdiscovery.distsql.handler.exception.DatabaseDiscoveryRuleNotExistedException;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.infra.distsql.update.RDLDropUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import java.util.Collection;
@@ -36,18 +37,20 @@ public final class DropDatabaseDiscoveryRuleStatementUpdater implements RDLDropU
@Override
public void checkSQLStatement(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement,
- final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
checkToBeDroppedRuleNames(schemaName, sqlStatement, currentRuleConfig);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement,
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DatabaseDiscoveryRuleNotExistedException {
if (null == currentRuleConfig) {
throw new DatabaseDiscoveryRuleNotExistedException(schemaName, sqlStatement.getRuleNames());
}
}
- private void checkToBeDroppedRuleNames(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
+ private void checkToBeDroppedRuleNames(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement,
+ final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DatabaseDiscoveryRuleNotExistedException {
Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toList());
Collection<String> notExistedRuleNames = sqlStatement.getRuleNames().stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
if (!notExistedRuleNames.isEmpty()) {
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabas [...]
index e076b33..aa10e32 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.dbdiscovery.distsql.handler.exception.InvalidDa
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.junit.Test;
@@ -42,25 +43,25 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdaterTest {
private final AlterDatabaseDiscoveryRuleStatementUpdater updater = new AlterDatabaseDiscoveryRuleStatementUpdater();
@Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", new AlterDatabaseDiscoveryRuleStatement(Collections.emptyList()), null, mock(ShardingSphereResource.class));
}
@Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutToBeAlteredDatabaseDiscoveryRule() {
+ public void assertCheckSQLStatementWithoutToBeAlteredDatabaseDiscoveryRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("TEST"),
new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap()), mock(ShardingSphereResource.class));
}
@Test(expected = ResourceNotExistedException.class)
- public void assertCheckSQLStatementWithoutExistedResources() {
+ public void assertCheckSQLStatementWithoutExistedResources() throws RuleDefinitionViolationException {
ShardingSphereResource resource = mock(ShardingSphereResource.class);
when(resource.getNotExistedResources(any())).thenReturn(Collections.singleton("ds0"));
updater.checkSQLStatement("foo", createSQLStatement("TEST"), createCurrentRuleConfiguration(), resource);
}
@Test(expected = InvalidDatabaseDiscoveryTypesException.class)
- public void assertCheckSQLStatementWithoutToBeAlteredDiscoveryTypes() {
+ public void assertCheckSQLStatementWithoutToBeAlteredDiscoveryTypes() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatab [...]
index 5f610f5..3019b84 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDisc
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.infra.exception.rule.DuplicateRuleNamesException;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.junit.Test;
@@ -40,21 +41,21 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdaterTest {
private final CreateDatabaseDiscoveryRuleStatementUpdater updater = new CreateDatabaseDiscoveryRuleStatementUpdater();
@Test(expected = DuplicateRuleNamesException.class)
- public void assertCheckSQLStatementWithDuplicateRuleNames() {
+ public void assertCheckSQLStatementWithDuplicateRuleNames() throws RuleDefinitionViolationException {
DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("pr_ds", Collections.emptyList(), "test");
updater.checkSQLStatement(
"foo", createSQLStatement("TEST"), new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig), Collections.emptyMap()), mock(ShardingSphereResource.class));
}
@Test(expected = ResourceNotExistedException.class)
- public void assertCheckSQLStatementWithoutExistedResources() {
+ public void assertCheckSQLStatementWithoutExistedResources() throws RuleDefinitionViolationException {
ShardingSphereResource resource = mock(ShardingSphereResource.class);
when(resource.getNotExistedResources(any())).thenReturn(Collections.singleton("ds_read_0"));
updater.checkSQLStatement("foo", createSQLStatement("TEST"), null, resource);
}
@Test(expected = InvalidDatabaseDiscoveryTypesException.class)
- public void assertCheckSQLStatementWithDatabaseDiscoveryType() {
+ public void assertCheckSQLStatementWithDatabaseDiscoveryType() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), null, mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseD [...]
index 75bf795..cae27f7 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDa
import org.apache.shardingsphere.dbdiscovery.distsql.handler.exception.DatabaseDiscoveryRuleNotExistedException;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.junit.Test;
@@ -38,12 +39,12 @@ public final class DropDatabaseDiscoveryRuleStatementUpdaterTest {
private final DropDatabaseDiscoveryRuleStatementUpdater updater = new DropDatabaseDiscoveryRuleStatementUpdater();
@Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), null, mock(ShardingSphereResource.class));
}
@Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutToBeDroppedRules() {
+ public void assertCheckSQLStatementWithoutToBeDroppedRules() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap()), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/exception/EncryptRuleNotExistedException.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/exception/EncryptRuleNotExistedException.java
index c23e0e3..edc8f5a 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/exception/EncryptRuleNotExistedException.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/exception/EncryptRuleNotExistedException.java
@@ -29,6 +29,6 @@ public final class EncryptRuleNotExistedException extends RuleDefinitionViolatio
private static final long serialVersionUID = -3070306238552517428L;
public EncryptRuleNotExistedException(final String schemaName, final Collection<String> tables) {
- super(1118, "C1118", "Encrypt rules %s do not exist in schema %s.");
+ super(1118, String.format("Encrypt rules %s do not exist in schema %s.", tables, schemaName));
}
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/exception/InvalidEncryptorsException.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/exception/InvalidEncryptorsException.java
index b2f554c..a8418db 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/exception/InvalidEncryptorsException.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/exception/InvalidEncryptorsException.java
@@ -29,6 +29,6 @@ public final class InvalidEncryptorsException extends RuleDefinitionViolationExc
private static final long serialVersionUID = 3175781664028568140L;
public InvalidEncryptorsException(final Collection<String> encryptors) {
- super(1117, "C1117", String.format("Invalid encryptors %s.", encryptors));
+ super(1117, String.format("Invalid encryptors %s.", encryptors));
}
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
index d71c35c..6530cfa 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegme
import org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.distsql.update.RDLAlterUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
@@ -48,19 +49,21 @@ public final class AlterEncryptRuleStatementUpdater implements RDLAlterUpdater<A
}
@Override
- public void checkSQLStatement(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ public void checkSQLStatement(final String schemaName, final AlterEncryptRuleStatement sqlStatement,
+ final EncryptRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
checkToBeAlteredRules(schemaName, sqlStatement, currentRuleConfig);
checkToBeAlteredEncryptors(sqlStatement);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final AlterEncryptRuleStatement sqlStatement,
+ final EncryptRuleConfiguration currentRuleConfig) throws EncryptRuleNotExistedException {
if (null == currentRuleConfig) {
throw new EncryptRuleNotExistedException(schemaName, getToBeAlteredEncryptTableNames(sqlStatement));
}
}
- private void checkToBeAlteredRules(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ private void checkToBeAlteredRules(final String schemaName, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) throws EncryptRuleNotExistedException {
Collection<String> currentEncryptTableNames = currentRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
Collection<String> notExistEncryptTableNames = getToBeAlteredEncryptTableNames(sqlStatement).stream().filter(each -> !currentEncryptTableNames.contains(each)).collect(Collectors.toList());
if (!notExistEncryptTableNames.isEmpty()) {
@@ -72,7 +75,7 @@ public final class AlterEncryptRuleStatementUpdater implements RDLAlterUpdater<A
return sqlStatement.getRules().stream().map(EncryptRuleSegment::getTableName).collect(Collectors.toList());
}
- private void checkToBeAlteredEncryptors(final AlterEncryptRuleStatement sqlStatement) {
+ private void checkToBeAlteredEncryptors(final AlterEncryptRuleStatement sqlStatement) throws InvalidEncryptorsException {
Collection<String> encryptors = new LinkedHashSet<>();
for (EncryptRuleSegment each : sqlStatement.getRules()) {
encryptors.addAll(each.getColumns().stream().map(column -> column.getEncryptor().getName()).collect(Collectors.toSet()));
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
index 76cf245..215dfe6 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptR
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.distsql.update.RDLCreateUpdater;
import org.apache.shardingsphere.infra.exception.rule.DuplicateRuleNamesException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
@@ -46,13 +47,14 @@ public final class CreateEncryptRuleStatementUpdater implements RDLCreateUpdater
}
@Override
- public void checkSQLStatement(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ public void checkSQLStatement(final String schemaName, final CreateEncryptRuleStatement sqlStatement,
+ final EncryptRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkDuplicateRuleNames(schemaName, sqlStatement, currentRuleConfig);
checkToBeCreatedEncryptors(sqlStatement);
// TODO check resource
}
- private void checkDuplicateRuleNames(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ private void checkDuplicateRuleNames(final String schemaName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) throws DuplicateRuleNamesException {
if (null != currentRuleConfig) {
Collection<String> currentRuleNames = currentRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
Collection<String> toBeCreatedDuplicateRuleNames = sqlStatement.getRules().stream().map(EncryptRuleSegment::getTableName).filter(currentRuleNames::contains).collect(Collectors.toList());
@@ -62,7 +64,7 @@ public final class CreateEncryptRuleStatementUpdater implements RDLCreateUpdater
}
}
- private void checkToBeCreatedEncryptors(final CreateEncryptRuleStatement sqlStatement) {
+ private void checkToBeCreatedEncryptors(final CreateEncryptRuleStatement sqlStatement) throws InvalidEncryptorsException {
Collection<String> encryptors = new LinkedHashSet<>();
sqlStatement.getRules().forEach(each -> encryptors.addAll(each.getColumns().stream().map(column -> column.getEncryptor().getName()).collect(Collectors.toSet())));
Collection<String> notExistedEncryptors = encryptors.stream().filter(
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
index 9be9ade..fa93ce9 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfigu
import org.apache.shardingsphere.encrypt.distsql.handler.exception.EncryptRuleNotExistedException;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.DropEncryptRuleStatement;
import org.apache.shardingsphere.infra.distsql.update.RDLDropUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import java.util.Collection;
@@ -35,18 +36,21 @@ import java.util.stream.Collectors;
public final class DropEncryptRuleStatementUpdater implements RDLDropUpdater<DropEncryptRuleStatement, EncryptRuleConfiguration> {
@Override
- public void checkSQLStatement(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ public void checkSQLStatement(final String schemaName, final DropEncryptRuleStatement sqlStatement,
+ final EncryptRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
checkToBeDroppedEncryptTableNames(schemaName, sqlStatement, currentRuleConfig);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final DropEncryptRuleStatement sqlStatement,
+ final EncryptRuleConfiguration currentRuleConfig) throws EncryptRuleNotExistedException {
if (null == currentRuleConfig) {
throw new EncryptRuleNotExistedException(schemaName, sqlStatement.getTables());
}
}
- private void checkToBeDroppedEncryptTableNames(final String schemaName, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
+ private void checkToBeDroppedEncryptTableNames(final String schemaName, final DropEncryptRuleStatement sqlStatement,
+ final EncryptRuleConfiguration currentRuleConfig) throws EncryptRuleNotExistedException {
Collection<String> currentEncryptTableNames = currentRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
Collection<String> notExistedTableNames = sqlStatement.getTables().stream().filter(each -> !currentEncryptTableNames.contains(each)).collect(Collectors.toList());
if (!notExistedTableNames.isEmpty()) {
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
index dd303de..4ed01fc 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.encrypt.distsql.handler.exception.InvalidEncryp
import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.junit.Test;
@@ -40,17 +41,17 @@ public final class AlterEncryptRuleStatementUpdaterTest {
private final AlterEncryptRuleStatementUpdater updater = new AlterEncryptRuleStatementUpdater();
@Test(expected = EncryptRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("MD5"), null, mock(ShardingSphereResource.class));
}
@Test(expected = EncryptRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutToBeAlteredRules() {
+ public void assertCheckSQLStatementWithoutToBeAlteredRules() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("MD5"), new EncryptRuleConfiguration(Collections.emptyList(), new HashMap<>()), mock(ShardingSphereResource.class));
}
@Test(expected = InvalidEncryptorsException.class)
- public void assertCheckSQLStatementWithoutToBeAlteredEncryptors() {
+ public void assertCheckSQLStatementWithoutToBeAlteredEncryptors() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
index 636e380..d36dcfc 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSeg
import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptRuleStatement;
import org.apache.shardingsphere.infra.exception.rule.DuplicateRuleNamesException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.junit.Test;
@@ -38,12 +39,12 @@ public final class CreateEncryptRuleStatementUpdaterTest {
private final CreateEncryptRuleStatementUpdater updater = new CreateEncryptRuleStatementUpdater();
@Test(expected = DuplicateRuleNamesException.class)
- public void assertCheckSQLStatementWithDuplicateEncryptRule() {
+ public void assertCheckSQLStatementWithDuplicateEncryptRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("MD5"), getCurrentRuleConfig(), mock(ShardingSphereResource.class));
}
@Test(expected = InvalidEncryptorsException.class)
- public void assertCheckSQLStatementWithoutToBeCreatedEncryptors() {
+ public void assertCheckSQLStatementWithoutToBeCreatedEncryptors() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), null, mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
index 3c962a1..b37cdd5 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfigu
import org.apache.shardingsphere.encrypt.distsql.handler.exception.EncryptRuleNotExistedException;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.DropEncryptRuleStatement;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.junit.Test;
@@ -39,12 +40,12 @@ public final class DropEncryptRuleStatementUpdaterTest {
private final DropEncryptRuleStatementUpdater updater = new DropEncryptRuleStatementUpdater();
@Test(expected = EncryptRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), null, mock(ShardingSphereResource.class));
}
@Test(expected = EncryptRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutToBeDroppedRule() {
+ public void assertCheckSQLStatementWithoutToBeDroppedRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap()), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/InvalidLoadBalancersException.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritespl [...]
index f0e4530..9452efc 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/InvalidLoadBalancersException.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/InvalidLoadBalancersException.java
@@ -29,6 +29,6 @@ public final class InvalidLoadBalancersException extends RuleDefinitionViolation
private static final long serialVersionUID = -8028595443792872970L;
public InvalidLoadBalancersException(final Collection<String> loadBalancers) {
- super(1114, "C1114", String.format("Invalid load balancers %s.", loadBalancers));
+ super(1114, String.format("Invalid load balancers %s.", loadBalancers));
}
}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/ReadwriteSplittingRuleNotExistedException.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/ [...]
index 5b6bf5f..23442d1 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/ReadwriteSplittingRuleNotExistedException.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/ReadwriteSplittingRuleNotExistedException.java
@@ -29,6 +29,6 @@ public final class ReadwriteSplittingRuleNotExistedException extends RuleDefinit
private static final long serialVersionUID = -5119217255419990719L;
public ReadwriteSplittingRuleNotExistedException(final String schemaName, final Collection<String> ruleNames) {
- super(1113, "C113", String.format("Readwrite splitting rules %s do not exist in schema %s.", ruleNames, schemaName));
+ super(1113, String.format("Readwrite splitting rules %s do not exist in schema %s.", ruleNames, schemaName));
}
}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/r [...]
index 1bfcacf..bc8d880 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdater.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.distsql.update.RDLAlterUpdater;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
@@ -51,20 +52,22 @@ public final class AlterReadwriteSplittingRuleStatementUpdater implements RDLAlt
@Override
public void checkSQLStatement(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement,
- final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
checkToBeAlteredRules(schemaName, sqlStatement, currentRuleConfig);
checkToBeAlteredResources(schemaName, sqlStatement, resource);
checkToBeAlteredLoadBalancer(sqlStatement);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement,
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws ReadwriteSplittingRuleNotExistedException {
if (null == currentRuleConfig) {
throw new ReadwriteSplittingRuleNotExistedException(schemaName, getToBeAlteredRuleNames(sqlStatement));
}
}
- private void checkToBeAlteredRules(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ private void checkToBeAlteredRules(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement,
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws ReadwriteSplittingRuleNotExistedException {
Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
Collection<String> notExistedRuleNames = getToBeAlteredRuleNames(sqlStatement).stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
if (!notExistedRuleNames.isEmpty()) {
@@ -76,7 +79,7 @@ public final class AlterReadwriteSplittingRuleStatementUpdater implements RDLAlt
return sqlStatement.getRules().stream().map(ReadwriteSplittingRuleSegment::getName).collect(Collectors.toSet());
}
- private void checkToBeAlteredLoadBalancer(final AlterReadwriteSplittingRuleStatement sqlStatement) {
+ private void checkToBeAlteredLoadBalancer(final AlterReadwriteSplittingRuleStatement sqlStatement) throws InvalidLoadBalancersException {
Collection<String> invalidLoadBalances = sqlStatement.getRules().stream().map(ReadwriteSplittingRuleSegment::getLoadBalancer).distinct()
.filter(each -> !TypedSPIRegistry.findRegisteredService(ReplicaLoadBalanceAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
if (!invalidLoadBalances.isEmpty()) {
@@ -84,7 +87,8 @@ public final class AlterReadwriteSplittingRuleStatementUpdater implements RDLAlt
}
}
- private void checkToBeAlteredResources(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement, final ShardingSphereResource resource) {
+ private void checkToBeAlteredResources(final String schemaName, final AlterReadwriteSplittingRuleStatement sqlStatement,
+ final ShardingSphereResource resource) throws ResourceNotExistedException {
Collection<String> resources = new LinkedHashSet<>();
sqlStatement.getRules().stream().filter(each -> Strings.isNullOrEmpty(each.getAutoAwareResource())).forEach(each -> {
resources.add(each.getWriteDataSource());
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/ [...]
index 14a9e22..80d65d5 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdater.java
@@ -21,6 +21,7 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.distsql.update.RDLCreateUpdater;
import org.apache.shardingsphere.infra.exception.rule.DuplicateRuleNamesException;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
@@ -49,13 +50,14 @@ public final class CreateReadwriteSplittingRuleStatementUpdater implements RDLCr
@Override
public void checkSQLStatement(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement,
- final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkDuplicateRuleNames(schemaName, sqlStatement, currentRuleConfig);
checkToBeCreatedResources(schemaName, sqlStatement, resource);
checkToBeCreatedLoadBalancers(sqlStatement);
}
- private void checkDuplicateRuleNames(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ private void checkDuplicateRuleNames(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement,
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws DuplicateRuleNamesException {
if (null != currentRuleConfig) {
Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toList());
Collection<String> duplicateRuleNames = sqlStatement.getRules().stream().map(ReadwriteSplittingRuleSegment::getName).filter(currentRuleNames::contains).collect(Collectors.toList());
@@ -65,7 +67,8 @@ public final class CreateReadwriteSplittingRuleStatementUpdater implements RDLCr
}
}
- private void checkToBeCreatedResources(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement, final ShardingSphereResource resource) {
+ private void checkToBeCreatedResources(final String schemaName, final CreateReadwriteSplittingRuleStatement sqlStatement,
+ final ShardingSphereResource resource) throws ResourceNotExistedException {
Collection<String> notExistResources = resource.getNotExistedResources(getToBeCreatedResources(sqlStatement));
if (!notExistResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistResources);
@@ -81,7 +84,7 @@ public final class CreateReadwriteSplittingRuleStatementUpdater implements RDLCr
return result;
}
- private void checkToBeCreatedLoadBalancers(final CreateReadwriteSplittingRuleStatement sqlStatement) {
+ private void checkToBeCreatedLoadBalancers(final CreateReadwriteSplittingRuleStatement sqlStatement) throws InvalidLoadBalancersException {
Collection<String> notExistedLoadBalancers = sqlStatement.getRules().stream().map(ReadwriteSplittingRuleSegment::getLoadBalancer).distinct()
.filter(each -> !TypedSPIRegistry.findRegisteredService(ReplicaLoadBalanceAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
if (!notExistedLoadBalancers.isEmpty()) {
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/re [...]
index beb16db..11382c7 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.infra.distsql.update.RDLDropUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -36,18 +37,20 @@ public final class DropReadwriteSplittingRuleStatementUpdater implements RDLDrop
@Override
public void checkSQLStatement(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement,
- final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
checkToBeDroppedRuleNames(schemaName, sqlStatement, currentRuleConfig);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement,
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws ReadwriteSplittingRuleNotExistedException {
if (null == currentRuleConfig) {
throw new ReadwriteSplittingRuleNotExistedException(schemaName, sqlStatement.getRuleNames());
}
}
- private void checkToBeDroppedRuleNames(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+ private void checkToBeDroppedRuleNames(final String schemaName, final DropReadwriteSplittingRuleStatement sqlStatement,
+ final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws ReadwriteSplittingRuleNotExistedException {
Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toList());
Collection<String> notExistedRuleNames = sqlStatement.getRuleNames().stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
if (!notExistedRuleNames.isEmpty()) {
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphe [...]
index dc23979..68c13a8 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -42,24 +43,24 @@ public final class AlterReadwriteSplittingRuleStatementUpdaterTest {
private final AlterReadwriteSplittingRuleStatementUpdater updater = new AlterReadwriteSplittingRuleStatementUpdater();
@Test(expected = ReadwriteSplittingRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("TEST"), null, mock(ShardingSphereResource.class));
}
@Test(expected = ReadwriteSplittingRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutToBeAlteredRules() {
+ public void assertCheckSQLStatementWithoutToBeAlteredRules() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("TEST"), new ReadwriteSplittingRuleConfiguration(Collections.emptyList(), Collections.emptyMap()), mock(ShardingSphereResource.class));
}
@Test(expected = ResourceNotExistedException.class)
- public void assertCheckSQLStatementWithoutExistedResources() {
+ public void assertCheckSQLStatementWithoutExistedResources() throws RuleDefinitionViolationException {
ShardingSphereResource resource = mock(ShardingSphereResource.class);
when(resource.getNotExistedResources(any())).thenReturn(Collections.singleton("read_ds_0"));
updater.checkSQLStatement("foo", createSQLStatement("TEST"), createCurrentRuleConfiguration(), resource);
}
@Test(expected = InvalidLoadBalancersException.class)
- public void assertCheckSQLStatementWithoutToBeAlteredLoadBalancers() {
+ public void assertCheckSQLStatementWithoutToBeAlteredLoadBalancers() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsph [...]
index 1aba2ec..e02df99 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
import org.apache.shardingsphere.infra.exception.rule.DuplicateRuleNamesException;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -42,19 +43,19 @@ public final class CreateReadwriteSplittingRuleStatementUpdaterTest {
private final CreateReadwriteSplittingRuleStatementUpdater updater = new CreateReadwriteSplittingRuleStatementUpdater();
@Test(expected = DuplicateRuleNamesException.class)
- public void assertCheckSQLStatementWithDuplicateRuleNames() {
+ public void assertCheckSQLStatementWithDuplicateRuleNames() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("TEST"), getCurrentRuleConfig(), mock(ShardingSphereResource.class));
}
@Test(expected = ResourceNotExistedException.class)
- public void assertCheckSQLStatementWithoutExistedResources() {
+ public void assertCheckSQLStatementWithoutExistedResources() throws RuleDefinitionViolationException {
ShardingSphereResource resource = mock(ShardingSphereResource.class);
when(resource.getNotExistedResources(any())).thenReturn(Arrays.asList("read_ds_0", "read_ds_1"));
updater.checkSQLStatement("foo", createSQLStatement("TEST"), null, resource);
}
@Test(expected = InvalidLoadBalancersException.class)
- public void assertCheckSQLStatementWithoutToBeCreatedLoadBalancers() {
+ public void assertCheckSQLStatementWithoutToBeCreatedLoadBalancers() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), null, mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingspher [...]
index 07dc0a2..1492cc2 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -38,12 +39,12 @@ public final class DropReadwriteSplittingRuleStatementUpdaterTest {
private final DropReadwriteSplittingRuleStatementUpdater updater = new DropReadwriteSplittingRuleStatementUpdater();
@Test(expected = ReadwriteSplittingRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), null, mock(ShardingSphereResource.class));
}
@Test(expected = ReadwriteSplittingRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutToBeDroppedRule() {
+ public void assertCheckSQLStatementWithoutToBeDroppedRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), new ReadwriteSplittingRuleConfiguration(Collections.emptyList(), Collections.emptyMap()), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/DuplicateBindingTablesException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/DuplicateBindingTablesException.java
index faac555..ccaa0ed 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/DuplicateBindingTablesException.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/DuplicateBindingTablesException.java
@@ -29,6 +29,6 @@ public final class DuplicateBindingTablesException extends RuleDefinitionViolati
private static final long serialVersionUID = -8295737924657889408L;
public DuplicateBindingTablesException(final Collection<String> tableNames) {
- super(1121, "C1121", String.format("Duplicate sharding binding tables %s.", tableNames));
+ super(1121, String.format("Duplicate sharding binding tables %s.", tableNames));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/DuplicateTablesException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/DuplicateTablesException.java
index e564afe..067eae2 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/DuplicateTablesException.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/DuplicateTablesException.java
@@ -29,6 +29,6 @@ public final class DuplicateTablesException extends RuleDefinitionViolationExcep
private static final long serialVersionUID = 3539438597135687601L;
public DuplicateTablesException(final Collection<String> tableNames) {
- super(1108, "C1108", String.format("Duplicate table names %s.", tableNames));
+ super(1108, String.format("Duplicate table names %s.", tableNames));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/InvalidKeyGeneratorsException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/InvalidKeyGeneratorsException.java
index 078c23f..85599d3 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/InvalidKeyGeneratorsException.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/InvalidKeyGeneratorsException.java
@@ -29,6 +29,6 @@ public final class InvalidKeyGeneratorsException extends RuleDefinitionViolation
private static final long serialVersionUID = -1671459113165055997L;
public InvalidKeyGeneratorsException(final Collection<String> keyGenerators) {
- super(1120, "C1120", String.format("Invalid key generators %s.", keyGenerators));
+ super(1120, String.format("Invalid key generators %s.", keyGenerators));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/InvalidShardingAlgorithmsException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/InvalidShardingAlgorithmsException.java
index 5d7764e..d44e43d 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/InvalidShardingAlgorithmsException.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/InvalidShardingAlgorithmsException.java
@@ -29,6 +29,6 @@ public final class InvalidShardingAlgorithmsException extends RuleDefinitionViol
private static final long serialVersionUID = 4257890788163115250L;
public InvalidShardingAlgorithmsException(final Collection<String> algorithms) {
- super(1119, "C1119", String.format("Invalid sharding algorithms %s", algorithms));
+ super(1119, String.format("Invalid sharding algorithms %s", algorithms));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBindingTableRuleNotExistsException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBindingTableRuleNotExistsException.java
index 80b7d4c..658d0ae 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBindingTableRuleNotExistsException.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBindingTableRuleNotExistsException.java
@@ -27,6 +27,6 @@ public final class ShardingBindingTableRuleNotExistsException extends RuleDefini
private static final long serialVersionUID = -1930065143932541970L;
public ShardingBindingTableRuleNotExistsException(final String schemaName) {
- super(1111, "C1111", String.format("Sharding binding table rules do not exist in schema %s.", schemaName));
+ super(1111, String.format("Sharding binding table rules do not exist in schema %s.", schemaName));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBroadcastTableRuleExistedException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBroadcastTableRuleExistedException.java
index 9121c39..765c7fb 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBroadcastTableRuleExistedException.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBroadcastTableRuleExistedException.java
@@ -27,6 +27,6 @@ public final class ShardingBroadcastTableRuleExistedException extends RuleDefini
private static final long serialVersionUID = 9019772512528350085L;
public ShardingBroadcastTableRuleExistedException(final String schemaName) {
- super(1110, "C1110", String.format("Sharding broadcast table rules already exists in schema %s.", schemaName));
+ super(1110, String.format("Sharding broadcast table rules already exists in schema %s.", schemaName));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBroadcastTableRuleNotExistsException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBroadcastTableRuleNotExistsExc [...]
index 3eefa1b..a57cf61 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBroadcastTableRuleNotExistsException.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingBroadcastTableRuleNotExistsException.java
@@ -27,6 +27,6 @@ public final class ShardingBroadcastTableRuleNotExistsException extends RuleDefi
private static final long serialVersionUID = 2816401356514609173L;
public ShardingBroadcastTableRuleNotExistsException(final String schemaName) {
- super(1112, "C1112", String.format("Sharding broadcast table rules do not exist in schema %s.", schemaName));
+ super(1112, String.format("Sharding broadcast table rules do not exist in schema %s.", schemaName));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingTableRuleNotExistedException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingTableRuleNotExistedException.java
index 35e6db2..69171f9 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingTableRuleNotExistedException.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingTableRuleNotExistedException.java
@@ -29,6 +29,6 @@ public final class ShardingTableRuleNotExistedException extends RuleDefinitionVi
private static final long serialVersionUID = 8565541404478688849L;
public ShardingTableRuleNotExistedException(final String schemaName, final Collection<String> tableNames) {
- super(1106, "C1106", String.format("Sharding table rules %s do not exist in schema %s.", tableNames, schemaName));
+ super(1106, String.format("Sharding table rules %s do not exist in schema %s.", tableNames, schemaName));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingTableRulesInUsedException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingTableRulesInUsedException.java
index c9110d1..d6f80c9 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingTableRulesInUsedException.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/exception/ShardingTableRulesInUsedException.java
@@ -29,6 +29,6 @@ public final class ShardingTableRulesInUsedException extends RuleDefinitionViola
private static final long serialVersionUID = -6958306664517015097L;
public ShardingTableRulesInUsedException(final Collection<String> tableNames) {
- super(1107, "C1107", String.format("Sharding table rules %s are still used by binding table rule.", tableNames));
+ super(1107, String.format("Sharding table rules %s are still used by binding table rule.", tableNames));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBindingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBindingTableRuleStatementUpdater.java
index 50e607d..89d9182 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBindingTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBindingTableRuleStatementUpdater.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.distsql.handler.update;
import org.apache.shardingsphere.infra.distsql.update.RDLAlterUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -39,19 +40,20 @@ public final class AlterShardingBindingTableRuleStatementUpdater implements RDLA
@Override
public void checkSQLStatement(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, currentRuleConfig);
checkToBeAlertedBindingTables(schemaName, sqlStatement, currentRuleConfig);
checkToBeAlteredDuplicateBindingTables(sqlStatement);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) throws ShardingBindingTableRuleNotExistsException {
if (null == currentRuleConfig) {
throw new ShardingBindingTableRuleNotExistsException(schemaName);
}
}
- private void checkToBeAlertedBindingTables(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkToBeAlertedBindingTables(final String schemaName, final AlterShardingBindingTableRulesStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig) throws ShardingTableRuleNotExistedException {
Collection<String> currentLogicTables = getCurrentLogicTables(currentRuleConfig);
Collection<String> notExistedBindingTables = sqlStatement.getBindingTables().stream().filter(each -> !currentLogicTables.contains(each)).collect(Collectors.toSet());
if (!notExistedBindingTables.isEmpty()) {
@@ -66,7 +68,7 @@ public final class AlterShardingBindingTableRuleStatementUpdater implements RDLA
return result;
}
- private void checkToBeAlteredDuplicateBindingTables(final AlterShardingBindingTableRulesStatement sqlStatement) {
+ private void checkToBeAlteredDuplicateBindingTables(final AlterShardingBindingTableRulesStatement sqlStatement) throws DuplicateBindingTablesException {
Collection<String> toBeAlteredBindingTables = new HashSet<>();
Collection<String> duplicateBindingTables = sqlStatement.getBindingTables().stream().filter(each -> !toBeAlteredBindingTables.add(each)).collect(Collectors.toSet());
if (!duplicateBindingTables.isEmpty()) {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBroadcastTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBroadcastTableRuleStatementU [...]
index 63ac9c4..8c4c5a6 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBroadcastTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBroadcastTableRuleStatementUpdater.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.distsql.handler.update;
import org.apache.shardingsphere.infra.distsql.update.RDLAlterUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.exception.ShardingBroadcastTableRuleNotExistsException;
@@ -30,11 +31,11 @@ public final class AlterShardingBroadcastTableRuleStatementUpdater implements RD
@Override
public void checkSQLStatement(final String schemaName, final AlterShardingBroadcastTableRulesStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, currentRuleConfig);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) throws ShardingBroadcastTableRuleNotExistsException {
if (null == currentRuleConfig) {
throw new ShardingBroadcastTableRuleNotExistsException(schemaName);
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleStatementUpdater.java
index 3ad21f1..b814b42 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleStatementUpdater.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.sharding.distsql.handler.update;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.infra.distsql.update.RDLAlterUpdater;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
@@ -57,7 +58,7 @@ public final class AlterShardingTableRuleStatementUpdater implements RDLAlterUpd
@Override
public void checkSQLStatement(final String schemaName, final AlterShardingTableRuleStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
checkToBeAlteredResources(schemaName, sqlStatement, resource);
checkToBeAlteredShardingTables(schemaName, sqlStatement, currentRuleConfig);
@@ -66,7 +67,8 @@ public final class AlterShardingTableRuleStatementUpdater implements RDLAlterUpd
checkToBeAlteredDuplicateShardingTables(sqlStatement);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final AlterShardingTableRuleStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig) throws ShardingTableRuleNotExistedException {
if (null == currentRuleConfig) {
throw new ShardingTableRuleNotExistedException(schemaName, getToBeAlteredTableNames(sqlStatement));
}
@@ -76,7 +78,7 @@ public final class AlterShardingTableRuleStatementUpdater implements RDLAlterUpd
return sqlStatement.getRules().stream().map(TableRuleSegment::getLogicTable).collect(Collectors.toList());
}
- private void checkToBeAlteredResources(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingSphereResource resource) {
+ private void checkToBeAlteredResources(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingSphereResource resource) throws ResourceNotExistedException {
Collection<String> notExistResources = resource.getNotExistedResources(getToBeAlteredResources(sqlStatement));
if (!notExistResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistResources);
@@ -89,7 +91,8 @@ public final class AlterShardingTableRuleStatementUpdater implements RDLAlterUpd
return result;
}
- private void checkToBeAlteredShardingTables(final String schemaName, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkToBeAlteredShardingTables(final String schemaName, final AlterShardingTableRuleStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig) throws ShardingTableRuleNotExistedException {
Collection<String> currentShardingTables = getCurrentShardingTables(currentRuleConfig);
Collection<String> notExistedShardingTables = getToBeAlteredTableNames(sqlStatement).stream().filter(each -> !currentShardingTables.contains(each)).collect(Collectors.toList());
if (!notExistedShardingTables.isEmpty()) {
@@ -104,7 +107,7 @@ public final class AlterShardingTableRuleStatementUpdater implements RDLAlterUpd
return result;
}
- private void checkToBeAlteredShardingAlgorithm(final AlterShardingTableRuleStatement sqlStatement) {
+ private void checkToBeAlteredShardingAlgorithm(final AlterShardingTableRuleStatement sqlStatement) throws InvalidShardingAlgorithmsException {
Collection<String> notExistedShardingAlgorithms = sqlStatement.getRules().stream().map(each -> each.getTableStrategy().getName()).distinct()
.filter(each -> !TypedSPIRegistry.findRegisteredService(ShardingAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
if (!notExistedShardingAlgorithms.isEmpty()) {
@@ -112,7 +115,7 @@ public final class AlterShardingTableRuleStatementUpdater implements RDLAlterUpd
}
}
- private void checkToBeAlteredKeyGenerators(final AlterShardingTableRuleStatement sqlStatement) {
+ private void checkToBeAlteredKeyGenerators(final AlterShardingTableRuleStatement sqlStatement) throws InvalidKeyGeneratorsException {
Collection<String> notExistedKeyGenerators = getToBeAlteredKeyGenerators(sqlStatement).stream().distinct()
.filter(each -> !TypedSPIRegistry.findRegisteredService(KeyGenerateAlgorithm.class, each, new Properties()).isPresent()).collect(Collectors.toList());
if (!notExistedKeyGenerators.isEmpty()) {
@@ -124,7 +127,7 @@ public final class AlterShardingTableRuleStatementUpdater implements RDLAlterUpd
return sqlStatement.getRules().stream().filter(each -> null != each.getKeyGenerateStrategy()).map(each -> each.getKeyGenerateStrategy().getName()).collect(Collectors.toSet());
}
- private void checkToBeAlteredDuplicateShardingTables(final AlterShardingTableRuleStatement sqlStatement) {
+ private void checkToBeAlteredDuplicateShardingTables(final AlterShardingTableRuleStatement sqlStatement) throws DuplicateTablesException {
Collection<String> duplicateTables = getDuplicateTables(sqlStatement);
if (!duplicateTables.isEmpty()) {
throw new DuplicateTablesException(duplicateTables);
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBindingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBindingTableRuleStatementUpd [...]
index b89f2fb..cf7463a 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBindingTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBindingTableRuleStatementUpdater.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.distsql.handler.update;
import org.apache.shardingsphere.infra.distsql.update.RDLCreateUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -40,19 +41,20 @@ public final class CreateShardingBindingTableRuleStatementUpdater implements RDL
@Override
public void checkSQLStatement(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, currentRuleConfig);
checkToBeCreatedBindingTables(schemaName, sqlStatement, currentRuleConfig);
checkToBeCreatedDuplicateBindingTables(sqlStatement, currentRuleConfig);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) throws ShardingBindingTableRuleNotExistsException {
if (null == currentRuleConfig) {
throw new ShardingBindingTableRuleNotExistsException(schemaName);
}
}
- private void checkToBeCreatedBindingTables(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkToBeCreatedBindingTables(final String schemaName, final CreateShardingBindingTableRulesStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig) throws ShardingTableRuleNotExistedException {
Collection<String> notExistedBindingTables = new HashSet<>();
Collection<String> currentLogicTables = getCurrentLogicTables(currentRuleConfig);
for (String each : sqlStatement.getBindingTables()) {
@@ -72,7 +74,8 @@ public final class CreateShardingBindingTableRuleStatementUpdater implements RDL
return result;
}
- private void checkToBeCreatedDuplicateBindingTables(final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkToBeCreatedDuplicateBindingTables(final CreateShardingBindingTableRulesStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig) throws DuplicateBindingTablesException {
Collection<String> toBeCreatedBindingTables = new HashSet<>();
Collection<String> duplicateBindingTables = sqlStatement.getBindingTables().stream().filter(each -> !toBeCreatedBindingTables.add(each)).collect(Collectors.toSet());
duplicateBindingTables.addAll(getCurrentBindingTables(currentRuleConfig).stream().filter(each -> !toBeCreatedBindingTables.add(each)).collect(Collectors.toSet()));
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBroadcastTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBroadcastTableRuleStatemen [...]
index dfdb5bb..121e1d2 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBroadcastTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBroadcastTableRuleStatementUpdater.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.distsql.handler.update;
import org.apache.shardingsphere.infra.distsql.update.RDLCreateUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.exception.ShardingBroadcastTableRuleExistedException;
@@ -30,7 +31,7 @@ public final class CreateShardingBroadcastTableRuleStatementUpdater implements R
@Override
public void checkSQLStatement(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
}
@Override
@@ -40,7 +41,7 @@ public final class CreateShardingBroadcastTableRuleStatementUpdater implements R
@Override
public void updateCurrentRuleConfiguration(final String schemaName, final CreateShardingBroadcastTableRulesStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingRuleConfiguration toBeCreatedRuleConfig) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingRuleConfiguration toBeCreatedRuleConfig) throws RuleDefinitionViolationException {
if (null == currentRuleConfig) {
toBeCreatedRuleConfig.setBroadcastTables(sqlStatement.getTables());
} else {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java
index e51d754..7ad6daf 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sharding.distsql.handler.update;
import org.apache.shardingsphere.infra.distsql.update.RDLCreateUpdater;
import org.apache.shardingsphere.infra.exception.rule.ResourceNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
@@ -57,14 +58,14 @@ public final class CreateShardingTableRuleStatementUpdater implements RDLCreateU
@Override
public void checkSQLStatement(final String schemaName, final CreateShardingTableRuleStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkToBeCreatedResource(schemaName, sqlStatement, resource);
checkDuplicateTables(sqlStatement, currentRuleConfig);
checkToBeCreatedShardingAlgorithms(sqlStatement);
checkToBeCreatedKeyGenerators(sqlStatement);
}
- private void checkToBeCreatedResource(final String schemaName, final CreateShardingTableRuleStatement sqlStatement, final ShardingSphereResource resource) {
+ private void checkToBeCreatedResource(final String schemaName, final CreateShardingTableRuleStatement sqlStatement, final ShardingSphereResource resource) throws ResourceNotExistedException {
Collection<String> notExistedResources = resource.getNotExistedResources(getToBeCreatedResources(sqlStatement));
if (!notExistedResources.isEmpty()) {
throw new ResourceNotExistedException(schemaName, notExistedResources);
@@ -77,7 +78,7 @@ public final class CreateShardingTableRuleStatementUpdater implements RDLCreateU
return result;
}
- private void checkDuplicateTables(final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkDuplicateTables(final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DuplicateTablesException {
Collection<String> shardingTableNames = null == currentRuleConfig ? Collections.emptyList() : getShardingTables(currentRuleConfig);
Set<String> duplicateTableNames = sqlStatement.getRules().stream().collect(Collectors.toMap(TableRuleSegment::getLogicTable, each -> 1, Integer::sum))
.entrySet().stream().filter(entry -> entry.getValue() > 1).map(Entry::getKey).collect(Collectors.toSet());
@@ -94,7 +95,7 @@ public final class CreateShardingTableRuleStatementUpdater implements RDLCreateU
return result;
}
- private void checkToBeCreatedShardingAlgorithms(final CreateShardingTableRuleStatement sqlStatement) {
+ private void checkToBeCreatedShardingAlgorithms(final CreateShardingTableRuleStatement sqlStatement) throws InvalidShardingAlgorithmsException {
Collection<String> notExistedShardingAlgorithms = sqlStatement.getRules().stream().map(each -> each.getTableStrategy().getName()).distinct()
.filter(each -> !TypedSPIRegistry.findRegisteredService(ShardingAlgorithm.class, each, new Properties()).isPresent())
.collect(Collectors.toList());
@@ -103,7 +104,7 @@ public final class CreateShardingTableRuleStatementUpdater implements RDLCreateU
}
}
- private void checkToBeCreatedKeyGenerators(final CreateShardingTableRuleStatement sqlStatement) {
+ private void checkToBeCreatedKeyGenerators(final CreateShardingTableRuleStatement sqlStatement) throws InvalidKeyGeneratorsException {
Collection<String> invalidKeyGenerators = getToBeCreatedKeyGenerators(sqlStatement).stream().distinct()
.filter(each -> !TypedSPIRegistry.findRegisteredService(KeyGenerateAlgorithm.class, each, new Properties()).isPresent())
.collect(Collectors.toList());
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBindingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBindingTableRuleStatementUpdater.java
index 37440e1..1e31d6e 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBindingTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBindingTableRuleStatementUpdater.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.distsql.handler.update;
import org.apache.shardingsphere.infra.distsql.update.RDLDropUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.exception.ShardingBindingTableRuleNotExistsException;
@@ -30,11 +31,11 @@ public final class DropShardingBindingTableRuleStatementUpdater implements RDLDr
@Override
public void checkSQLStatement(final String schemaName, final DropShardingBindingTableRulesStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, currentRuleConfig);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) throws ShardingBindingTableRuleNotExistsException {
if (null == currentRuleConfig || currentRuleConfig.getBindingTableGroups().isEmpty()) {
throw new ShardingBindingTableRuleNotExistsException(schemaName);
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBroadcastTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBroadcastTableRuleStatementUpd [...]
index a8a5024..221145b 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBroadcastTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBroadcastTableRuleStatementUpdater.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.distsql.handler.update;
import org.apache.shardingsphere.infra.distsql.update.RDLDropUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.exception.ShardingBroadcastTableRuleNotExistsException;
@@ -30,11 +31,11 @@ public final class DropShardingBroadcastTableRuleStatementUpdater implements RDL
@Override
public void checkSQLStatement(final String schemaName, final DropShardingBroadcastTableRulesStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, currentRuleConfig);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) throws ShardingBroadcastTableRuleNotExistsException {
if (null == currentRuleConfig || currentRuleConfig.getBroadcastTables().isEmpty()) {
throw new ShardingBroadcastTableRuleNotExistsException(schemaName);
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java
index 3ec66cc..6775a72 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sharding.distsql.handler.update;
import com.google.common.base.Splitter;
import org.apache.shardingsphere.infra.distsql.update.RDLDropUpdater;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -39,13 +40,14 @@ public final class DropShardingTableRuleStatementUpdater implements RDLDropUpdat
@Override
public void checkSQLStatement(final String schemaName, final DropShardingTableRuleStatement sqlStatement,
- final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) {
+ final ShardingRuleConfiguration currentRuleConfig, final ShardingSphereResource resource) throws RuleDefinitionViolationException {
checkCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
checkToBeDroppedShardingTableNames(schemaName, sqlStatement, currentRuleConfig);
checkBindingTables(sqlStatement, currentRuleConfig);
}
- private void checkCurrentRuleConfiguration(final String schemaName, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkCurrentRuleConfiguration(final String schemaName, final DropShardingTableRuleStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig) throws ShardingTableRuleNotExistedException {
if (null == currentRuleConfig) {
throw new ShardingTableRuleNotExistedException(schemaName, getToBeDroppedShardingTableNames(sqlStatement));
}
@@ -55,7 +57,8 @@ public final class DropShardingTableRuleStatementUpdater implements RDLDropUpdat
return sqlStatement.getTableNames().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList());
}
- private void checkToBeDroppedShardingTableNames(final String schemaName, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkToBeDroppedShardingTableNames(final String schemaName, final DropShardingTableRuleStatement sqlStatement,
+ final ShardingRuleConfiguration currentRuleConfig) throws ShardingTableRuleNotExistedException {
Collection<String> currentShardingTableNames = getCurrentShardingTableNames(currentRuleConfig);
Collection<String> notExistedTableNames = getToBeDroppedShardingTableNames(sqlStatement).stream().filter(each -> !currentShardingTableNames.contains(each)).collect(Collectors.toList());
if (!notExistedTableNames.isEmpty()) {
@@ -70,7 +73,7 @@ public final class DropShardingTableRuleStatementUpdater implements RDLDropUpdat
return result;
}
- private void checkBindingTables(final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
+ private void checkBindingTables(final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws ShardingTableRulesInUsedException {
Collection<String> bindingTables = getBindingTables(currentRuleConfig);
Collection<String> usedTableNames = getToBeDroppedShardingTableNames(sqlStatement).stream().filter(bindingTables::contains).collect(Collectors.toList());
if (!usedTableNames.isEmpty()) {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RDLUpdater b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RDLUpdater
index a2d5402..fc29324 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RDLUpdater
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RDLUpdater
@@ -15,6 +15,23 @@
# limitations under the License.
#
+#
+# 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.
+#
+
org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingTableRuleStatementUpdater
org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingTableRuleStatementUpdater
org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingTableRuleStatementUpdater
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBindingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBindingTableRuleStatementUpdaterTest.java
index 2d56d82..5d50f5f 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBindingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBindingTableRuleStatementUpdaterTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.distsql.update;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -37,12 +38,12 @@ public final class AlterShardingBindingTableRuleStatementUpdaterTest {
private final AlterShardingBindingTableRuleStatementUpdater updater = new AlterShardingBindingTableRuleStatementUpdater();
@Test(expected = ShardingBindingTableRuleNotExistsException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), null, mock(ShardingSphereResource.class));
}
@Test(expected = DuplicateBindingTablesException.class)
- public void assertCheckSQLStatementWithDuplicateTables() {
+ public void assertCheckSQLStatementWithDuplicateTables() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createDuplicatedSQLStatement(), createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBroadcastTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBroadcastTableRuleStatementUpdaterTest.java
index 8edc10c..07393a0 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBroadcastTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBroadcastTableRuleStatementUpdaterTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.distsql.update;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.exception.ShardingBroadcastTableRuleNotExistsException;
@@ -33,7 +34,7 @@ public final class AlterShardingBroadcastTableRuleStatementUpdaterTest {
private final AlterShardingBroadcastTableRuleStatementUpdater updater = new AlterShardingBroadcastTableRuleStatementUpdater();
@Test(expected = ShardingBroadcastTableRuleNotExistsException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("t_1"), null, mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
index b7b236a..f803faa 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.distsql.update;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -42,22 +43,22 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
private final AlterShardingTableRuleStatementUpdater updater = new AlterShardingTableRuleStatementUpdater();
@Test(expected = ShardingTableRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("t_order", "STANDARD_TEST"), null, mock(ShardingSphereResource.class));
}
@Test(expected = DuplicateTablesException.class)
- public void assertCheckSQLStatementWithDuplicateTables() {
+ public void assertCheckSQLStatementWithDuplicateTables() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createDuplicatedSQLStatement(), createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
}
@Test(expected = ShardingTableRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutExistTable() {
+ public void assertCheckSQLStatementWithoutExistTable() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("invalid_table", "STANDARD_TEST"), createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
}
@Test(expected = InvalidShardingAlgorithmsException.class)
- public void assertCheckSQLStatementWithoutToBeAlteredShardingAlgorithms() {
+ public void assertCheckSQLStatementWithoutToBeAlteredShardingAlgorithms() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("t_order", "INVALID_TYPE"), createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingBindingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingBindingTableRuleStatementUpdaterTest.java
index 8e5caa2..12d2b78 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingBindingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingBindingTableRuleStatementUpdaterTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.distsql.update;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -36,12 +37,12 @@ public final class CreateShardingBindingTableRuleStatementUpdaterTest {
private final CreateShardingBindingTableRuleStatementUpdater updater = new CreateShardingBindingTableRuleStatementUpdater();
@Test(expected = ShardingTableRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutCurrentTableRule() {
+ public void assertCheckSQLStatementWithoutCurrentTableRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), new ShardingRuleConfiguration(), mock(ShardingSphereResource.class));
}
@Test(expected = DuplicateBindingTablesException.class)
- public void assertCheckSQLStatementWithDuplicateTables() {
+ public void assertCheckSQLStatementWithDuplicateTables() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createDuplicatedSQLStatement(), getCurrentRuleConfig(), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
index b744e2b..b52f6dd 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.distsql.update;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.distsql.handler.exception.DuplicateTablesException;
import org.apache.shardingsphere.sharding.distsql.handler.exception.InvalidShardingAlgorithmsException;
@@ -37,13 +38,13 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
private final CreateShardingTableRuleStatementUpdater updater = new CreateShardingTableRuleStatementUpdater();
@Test(expected = DuplicateTablesException.class)
- public void assertExecuteWithDuplicateTables() {
+ public void assertExecuteWithDuplicateTables() throws RuleDefinitionViolationException {
TableRuleSegment ruleSegment = new TableRuleSegment("t_order", Collections.emptyList(), null, null, null, null);
updater.checkSQLStatement("foo", createSQLStatement(ruleSegment, ruleSegment), null, mock(ShardingSphereResource.class));
}
@Test(expected = InvalidShardingAlgorithmsException.class)
- public void assertCheckSQLStatementWithoutToBeCreatedShardingAlgorithms() {
+ public void assertCheckSQLStatementWithoutToBeCreatedShardingAlgorithms() throws RuleDefinitionViolationException {
TableRuleSegment ruleSegment = new TableRuleSegment("t_order", Collections.emptyList(), null, new AlgorithmSegment("INVALID_TYPE", new Properties()), null, null);
updater.checkSQLStatement("foo", createSQLStatement(ruleSegment), null, mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBindingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBindingTableRuleStatementUpdaterTest.java
index e2134d3..567766e 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBindingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBindingTableRuleStatementUpdaterTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.distsql.update;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -34,12 +35,12 @@ public final class DropShardingBindingTableRuleStatementUpdaterTest {
private final DropShardingBindingTableRuleStatementUpdater updater = new DropShardingBindingTableRuleStatementUpdater();
@Test(expected = ShardingBindingTableRuleNotExistsException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), null, mock(ShardingSphereResource.class));
}
@Test(expected = ShardingBindingTableRuleNotExistsException.class)
- public void assertCheckSQLStatementWithoutExistedBindingTableRule() {
+ public void assertCheckSQLStatementWithoutExistedBindingTableRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), new ShardingRuleConfiguration(), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBroadcastTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBroadcastTableRuleStatementUpdaterTest.java
index 68ae8df..8dd9b4d 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBroadcastTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBroadcastTableRuleStatementUpdaterTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.distsql.update;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -34,12 +35,12 @@ public final class DropShardingBroadcastTableRuleStatementUpdaterTest {
private final DropShardingBroadcastTableRuleStatementUpdater updater = new DropShardingBroadcastTableRuleStatementUpdater();
@Test(expected = ShardingBroadcastTableRuleNotExistsException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), null, mock(ShardingSphereResource.class));
}
@Test(expected = ShardingBroadcastTableRuleNotExistsException.class)
- public void assertCheckSQLStatementWithoutExistBroadcastTableRule() {
+ public void assertCheckSQLStatementWithoutExistBroadcastTableRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement(), new ShardingRuleConfiguration(), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleStatementUpdaterTest.java
index 5e1b8b23..e88de77 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleStatementUpdaterTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.distsql.update;
import com.google.common.base.Splitter;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -45,17 +46,17 @@ public final class DropShardingTableRuleStatementUpdaterTest {
private final DropShardingTableRuleStatementUpdater updater = new DropShardingTableRuleStatementUpdater();
@Test(expected = ShardingTableRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutCurrentRule() {
+ public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", new DropShardingTableRuleStatement(Collections.emptyList()), null, mock(ShardingSphereResource.class));
}
@Test(expected = ShardingTableRuleNotExistedException.class)
- public void assertCheckSQLStatementWithoutExistedTableRule() {
+ public void assertCheckSQLStatementWithoutExistedTableRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("t_order"), new ShardingRuleConfiguration(), mock(ShardingSphereResource.class));
}
@Test(expected = ShardingTableRulesInUsedException.class)
- public void assertCheckSQLStatementWithBindingTableRule() {
+ public void assertCheckSQLStatementWithBindingTableRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement("foo", createSQLStatement("t_order_item"), createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RDLCreateUpdater.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RDLCreateUpdater.java
index 272cfc2..c0f462d 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RDLCreateUpdater.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RDLCreateUpdater.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.distsql.update;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
/**
@@ -44,6 +45,7 @@ public interface RDLCreateUpdater<T extends SQLStatement, R extends RuleConfigur
* @param sqlStatement SQL statement
* @param currentRuleConfig current rule configuration to be updated
* @param toBeCreatedRuleConfig to be created rule configuration
+ * @throws RuleDefinitionViolationException rule definition violation exception
*/
- void updateCurrentRuleConfiguration(String schemaName, T sqlStatement, R currentRuleConfig, R toBeCreatedRuleConfig);
+ void updateCurrentRuleConfiguration(String schemaName, T sqlStatement, R currentRuleConfig, R toBeCreatedRuleConfig) throws RuleDefinitionViolationException;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RDLUpdater.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RDLUpdater.java
index 9acf96e..fc9a64c 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RDLUpdater.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RDLUpdater.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.distsql.update;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -37,8 +38,9 @@ public interface RDLUpdater<T extends SQLStatement, R extends RuleConfiguration>
* @param sqlStatement SQL statement
* @param currentRuleConfig current rule configuration
* @param resource ShardingSphere resource
+ * @throws RuleDefinitionViolationException rule definition violation exception
*/
- void checkSQLStatement(String schemaName, T sqlStatement, R currentRuleConfig, ShardingSphereResource resource);
+ void checkSQLStatement(String schemaName, T sqlStatement, R currentRuleConfig, ShardingSphereResource resource) throws RuleDefinitionViolationException;
/**
* Get rule configuration class.
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateResourceException.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateResourceException.java
index c66151a..a19ece8 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateResourceException.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateResourceException.java
@@ -27,6 +27,6 @@ public final class DuplicateResourceException extends RuleDefinitionViolationExc
private static final long serialVersionUID = 2103793827572264148L;
public DuplicateResourceException(final Collection<String> resourceNames) {
- super(1104, "C1104", String.format("Duplicate resource names %s.", resourceNames));
+ super(1104, String.format("Duplicate resource names %s.", resourceNames));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleNamesException.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleNamesException.java
index 075ad8b..f0d6020 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleNamesException.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleNamesException.java
@@ -27,6 +27,6 @@ public final class DuplicateRuleNamesException extends RuleDefinitionViolationEx
private static final long serialVersionUID = -1738699538105858939L;
public DuplicateRuleNamesException(final String schemaName, final Collection<String> ruleNames) {
- super(1105, "C1105", String.format("Duplicate rule names %s in schema %s", ruleNames, schemaName));
+ super(1105, String.format("Duplicate rule names %s in schema %s", ruleNames, schemaName));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InvalidResourceException.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InvalidResourceException.java
index 7f12bcd..dc4912f 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InvalidResourceException.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InvalidResourceException.java
@@ -27,6 +27,6 @@ public final class InvalidResourceException extends RuleDefinitionViolationExcep
private static final long serialVersionUID = 7029641448948791509L;
public InvalidResourceException(final Collection<String> resourceNames) {
- super(1103, "C1103", String.format("Can not add invalid resources %s.", resourceNames));
+ super(1103, String.format("Can not add invalid resources %s.", resourceNames));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/ResourceInUsedException.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/ResourceInUsedException.java
index ef5d238..150b1c7 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/ResourceInUsedException.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/ResourceInUsedException.java
@@ -27,6 +27,6 @@ public final class ResourceInUsedException extends RuleDefinitionViolationExcept
private static final long serialVersionUID = -3427324685070457375L;
public ResourceInUsedException(final Collection<String> resourceNames) {
- super(1101, "C1101", String.format("Resources %s in the rule are still in used.", resourceNames));
+ super(1101, String.format("Resources %s in the rule are still in used.", resourceNames));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/ResourceNotExistedException.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/ResourceNotExistedException.java
index 70ec25a..72ba342 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/ResourceNotExistedException.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/ResourceNotExistedException.java
@@ -27,6 +27,6 @@ public final class ResourceNotExistedException extends RuleDefinitionViolationEx
private static final long serialVersionUID = 1704331180489268L;
public ResourceNotExistedException(final String schemaName, final Collection<String> resourceNames) {
- super(1102, "C1102", String.format("Resources %s do not exist in schema %s.", resourceNames, schemaName));
+ super(1102, String.format("Resources %s do not exist in schema %s.", resourceNames, schemaName));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleDefinitionViolationException.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleDefinitionViolationException.java
index 29f2d96..8276dfd 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleDefinitionViolationException.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleDefinitionViolationException.java
@@ -17,21 +17,16 @@
package org.apache.shardingsphere.infra.exception.rule;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
+import java.sql.SQLException;
/**
* Rule definition violation exception.
*/
-@RequiredArgsConstructor
-@Getter
-public abstract class RuleDefinitionViolationException extends RuntimeException {
+public abstract class RuleDefinitionViolationException extends SQLException {
private static final long serialVersionUID = 1090914641996552474L;
- private final int errorCode;
-
- private final String sqlState;
-
- private final String errorMessage;
+ public RuleDefinitionViolationException(final int errorCode, final String reason) {
+ super(reason, "C" + errorCode, errorCode);
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/SchemaRequiredBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/SchemaRequiredBackendHandler.java
index ec4874f..23e7f50 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/SchemaRequiredBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/SchemaRequiredBackendHandler.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSeg
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.available.FromSchemaAvailable;
+import java.sql.SQLException;
import java.util.Optional;
/**
@@ -44,13 +45,13 @@ public abstract class SchemaRequiredBackendHandler<T extends SQLStatement> imple
private final BackendConnection backendConnection;
@Override
- public final ResponseHeader execute() {
+ public final ResponseHeader execute() throws SQLException {
String schemaName = getSchemaName(backendConnection, sqlStatement);
checkSchema(schemaName);
return execute(schemaName, sqlStatement);
}
- protected abstract ResponseHeader execute(String schemaName, T sqlStatement);
+ protected abstract ResponseHeader execute(String schemaName, T sqlStatement) throws SQLException;
private String getSchemaName(final BackendConnection backendConnection, final T sqlStatement) {
Optional<SchemaSegment> schemaFromSQL = sqlStatement instanceof FromSchemaAvailable ? ((FromSchemaAvailable) sqlStatement).getSchema() : Optional.empty();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/RDLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandler.java
similarity index 62%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/RDLBackendHandler.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandler.java
index 7b70f16..6053324 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/RDLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandler.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl;
import org.apache.shardingsphere.governance.core.registry.config.event.rule.RuleConfigurationsAlteredSQLNotificationEvent;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.distsql.update.RDLCreateUpdater;
import org.apache.shardingsphere.infra.distsql.update.RDLDropUpdater;
import org.apache.shardingsphere.infra.distsql.update.RDLUpdater;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
@@ -53,26 +54,12 @@ public final class RDLBackendHandler<T extends SQLStatement> extends SchemaRequi
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
- protected ResponseHeader execute(final String schemaName, final T sqlStatement) {
+ protected ResponseHeader execute(final String schemaName, final T sqlStatement) throws RuleDefinitionViolationException {
RDLUpdater rdlUpdater = TypedSPIRegistry.getRegisteredService(RDLUpdater.class, sqlStatement.getClass().getCanonicalName(), new Properties());
Class<? extends RuleConfiguration> ruleConfigClass = rdlUpdater.getRuleConfigurationClass();
RuleConfiguration currentRuleConfig = findCurrentRuleConfiguration(schemaName, ruleConfigClass).orElse(null);
rdlUpdater.checkSQLStatement(schemaName, sqlStatement, currentRuleConfig, ProxyContext.getInstance().getMetaData(schemaName).getResource());
- if (rdlUpdater instanceof RDLCreateUpdater) {
- RuleConfiguration toBeCreatedRuleConfig = ((RDLCreateUpdater) rdlUpdater).buildToBeCreatedRuleConfiguration(schemaName, sqlStatement);
- ((RDLCreateUpdater) rdlUpdater).updateCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig, toBeCreatedRuleConfig);
- if (null == currentRuleConfig && null != toBeCreatedRuleConfig) {
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().add(toBeCreatedRuleConfig);
- }
- } else if (rdlUpdater instanceof RDLAlterUpdater) {
- ((RDLAlterUpdater) rdlUpdater).updateCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
- } else if (rdlUpdater instanceof RDLDropUpdater) {
- if (((RDLDropUpdater) rdlUpdater).updateCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig)) {
- ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().remove(currentRuleConfig);
- }
- } else {
- throw new UnsupportedOperationException(String.format("Cannot support RDLUpdater type `%s`", rdlUpdater.getClass().getCanonicalName()));
- }
+ processSQLStatement(schemaName, sqlStatement, rdlUpdater, currentRuleConfig);
postRuleConfigurationChange(schemaName);
return new UpdateResponseHeader(sqlStatement);
}
@@ -86,6 +73,40 @@ public final class RDLBackendHandler<T extends SQLStatement> extends SchemaRequi
return Optional.empty();
}
+ @SuppressWarnings("rawtypes")
+ private void processSQLStatement(final String schemaName, final T sqlStatement, final RDLUpdater updater, final RuleConfiguration currentRuleConfig) throws RuleDefinitionViolationException {
+ if (updater instanceof RDLCreateUpdater) {
+ processCreate(schemaName, sqlStatement, (RDLCreateUpdater) updater, currentRuleConfig);
+ } else if (updater instanceof RDLAlterUpdater) {
+ processAlter(schemaName, sqlStatement, (RDLAlterUpdater) updater, currentRuleConfig);
+ } else if (updater instanceof RDLDropUpdater) {
+ processDrop(schemaName, sqlStatement, (RDLDropUpdater) updater, currentRuleConfig);
+ } else {
+ throw new UnsupportedOperationException(String.format("Cannot support RDLUpdater type `%s`", updater.getClass().getCanonicalName()));
+ }
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private void processCreate(final String schemaName, final T sqlStatement, final RDLCreateUpdater updater, final RuleConfiguration currentRuleConfig) throws RuleDefinitionViolationException {
+ RuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(schemaName, sqlStatement);
+ updater.updateCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig, toBeCreatedRuleConfig);
+ if (null == currentRuleConfig && null != toBeCreatedRuleConfig) {
+ ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().add(toBeCreatedRuleConfig);
+ }
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private void processAlter(final String schemaName, final T sqlStatement, final RDLAlterUpdater updater, final RuleConfiguration currentRuleConfig) {
+ updater.updateCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig);
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private void processDrop(final String schemaName, final T sqlStatement, final RDLDropUpdater rdlUpdater, final RuleConfiguration currentRuleConfig) {
+ if (rdlUpdater.updateCurrentRuleConfiguration(schemaName, sqlStatement, currentRuleConfig)) {
+ ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().remove(currentRuleConfig);
+ }
+ }
+
private void postRuleConfigurationChange(final String schemaName) {
ShardingSphereEventBus.getInstance().post(
new RuleConfigurationsAlteredSQLNotificationEvent(schemaName, ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations()));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
index 05a37f8..d03a857 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
@@ -30,7 +30,6 @@ import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.AddResource
import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.CreateDatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.DropDatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.DropResourceBackendHandler;
-import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.RDLBackendHandler;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateDatabaseStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropDatabaseStatement;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
index 698b6a7..5500d7c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
@@ -24,10 +24,11 @@ import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration
import org.apache.shardingsphere.infra.config.datasource.DataSourceValidator;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.infra.exception.rule.DuplicateResourceException;
import org.apache.shardingsphere.infra.exception.rule.InvalidResourceException;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
@@ -59,7 +60,7 @@ public final class AddResourceBackendHandler extends SchemaRequiredBackendHandle
}
@Override
- public ResponseHeader execute(final String schemaName, final AddResourceStatement sqlStatement) {
+ public ResponseHeader execute(final String schemaName, final AddResourceStatement sqlStatement) throws RuleDefinitionViolationException {
check(schemaName, sqlStatement);
Map<String, DataSourceConfiguration> dataSourceConfigMap = DataSourceParameterConverter.getDataSourceConfigurationMap(
DataSourceParameterConverter.getDataSourceParameterMapFromYamlConfiguration(AddResourcesStatementConverter.convert(databaseType, sqlStatement)));
@@ -72,7 +73,7 @@ public final class AddResourceBackendHandler extends SchemaRequiredBackendHandle
return new UpdateResponseHeader(sqlStatement);
}
- private void check(final String schemaName, final AddResourceStatement sqlStatement) {
+ private void check(final String schemaName, final AddResourceStatement sqlStatement) throws DuplicateResourceException {
List<String> dataSourceNames = new ArrayList<>(sqlStatement.getDataSources().size());
Set<String> duplicateDataSourceNames = new HashSet<>(sqlStatement.getDataSources().size(), 1);
for (DataSourceSegment each : sqlStatement.getDataSources()) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseBackendHandler.java
index 2ee3404..3d864d6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseBackendHandler.java
@@ -56,8 +56,7 @@ public final class DropDatabaseBackendHandler implements TextProtocolBackendHand
}
private boolean isDropCurrentDatabase(final String databaseName) {
- return !Strings.isNullOrEmpty(backendConnection.getSchemaName())
- && backendConnection.getSchemaName().equals(databaseName);
+ return !Strings.isNullOrEmpty(backendConnection.getSchemaName()) && backendConnection.getSchemaName().equals(databaseName);
}
private void post(final DropDatabaseStatement sqlStatement) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropResourceBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropResourceBackendHandler.java
index c538d5a..93c3c56 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropResourceBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropResourceBackendHandler.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropResourceS
import org.apache.shardingsphere.governance.core.registry.config.event.datasource.DataSourceDroppedSQLNotificationEvent;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
import org.apache.shardingsphere.infra.rule.type.DataSourceContainedRule;
@@ -50,7 +51,7 @@ public final class DropResourceBackendHandler extends SchemaRequiredBackendHandl
}
@Override
- public ResponseHeader execute(final String schemaName, final DropResourceStatement sqlStatement) {
+ public ResponseHeader execute(final String schemaName, final DropResourceStatement sqlStatement) throws RuleDefinitionViolationException {
Collection<String> toBeDroppedResourceNames = sqlStatement.getNames();
check(schemaName, toBeDroppedResourceNames);
drop(schemaName, toBeDroppedResourceNames);
@@ -58,12 +59,12 @@ public final class DropResourceBackendHandler extends SchemaRequiredBackendHandl
return new UpdateResponseHeader(sqlStatement);
}
- private void check(final String schemaName, final Collection<String> toBeDroppedResourceNames) {
+ private void check(final String schemaName, final Collection<String> toBeDroppedResourceNames) throws ResourceNotExistedException, ResourceInUsedException {
checkResourceNameExisted(schemaName, toBeDroppedResourceNames);
checkResourceNameNotInUse(schemaName, toBeDroppedResourceNames);
}
- private void checkResourceNameExisted(final String schemaName, final Collection<String> resourceNames) {
+ private void checkResourceNameExisted(final String schemaName, final Collection<String> resourceNames) throws ResourceNotExistedException {
Map<String, DataSource> resources = ProxyContext.getInstance().getMetaData(schemaName).getResource().getDataSources();
Collection<String> notExistedResourceNames = resourceNames.stream().filter(each -> !resources.containsKey(each)).collect(Collectors.toList());
if (!notExistedResourceNames.isEmpty()) {
@@ -71,7 +72,7 @@ public final class DropResourceBackendHandler extends SchemaRequiredBackendHandl
}
}
- private void checkResourceNameNotInUse(final String schemaName, final Collection<String> toBeDroppedResourceNames) {
+ private void checkResourceNameNotInUse(final String schemaName, final Collection<String> toBeDroppedResourceNames) throws ResourceInUsedException {
Collection<String> inUsedResourceNames = getInUsedResourceNames(schemaName);
inUsedResourceNames.retainAll(toBeDroppedResourceNames);
if (!inUsedResourceNames.isEmpty()) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandlerTest.java
index 9758384..17d53e1 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandlerTest.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration
import org.apache.shardingsphere.infra.config.datasource.DataSourceValidator;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
@@ -81,7 +82,7 @@ public final class AddResourceBackendHandlerTest {
}
@Test
- public void assertExecute() {
+ public void assertExecute() throws RuleDefinitionViolationException {
ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test"));
when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
index 47eb3bb..6b64495 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
@@ -20,11 +20,9 @@ package org.apache.shardingsphere.proxy.frontend.mysql.err;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.db.protocol.error.CommonErrorCode;
-import org.apache.shardingsphere.db.protocol.error.CustomizedErrorCode;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerErrorCode;
import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket;
import org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
-import org.apache.shardingsphere.infra.exception.rule.RuleDefinitionViolationException;
import org.apache.shardingsphere.proxy.backend.exception.CircuitBreakException;
import org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException;
import org.apache.shardingsphere.proxy.backend.exception.DBDropExistsException;
@@ -60,8 +58,8 @@ public final class MySQLErrPacketFactory {
public static MySQLErrPacket newInstance(final Exception cause) {
if (cause instanceof SQLException) {
SQLException sqlException = (SQLException) cause;
- return null != sqlException.getSQLState() ? new MySQLErrPacket(1, sqlException.getErrorCode(), sqlException.getSQLState(), sqlException.getMessage())
- : new MySQLErrPacket(1, MySQLServerErrorCode.ER_INTERNAL_ERROR, cause.getMessage());
+ return null == sqlException.getSQLState() ? new MySQLErrPacket(1, MySQLServerErrorCode.ER_INTERNAL_ERROR, cause.getMessage())
+ : new MySQLErrPacket(1, sqlException.getErrorCode(), sqlException.getSQLState(), sqlException.getMessage());
}
if (cause instanceof ShardingCTLException) {
ShardingCTLException shardingCTLException = (ShardingCTLException) cause;
@@ -91,10 +89,6 @@ public final class MySQLErrPacketFactory {
if (cause instanceof CircuitBreakException) {
return new MySQLErrPacket(1, CommonErrorCode.CIRCUIT_BREAK_MODE);
}
- if (cause instanceof RuleDefinitionViolationException) {
- RuleDefinitionViolationException ruleViolationCause = (RuleDefinitionViolationException) cause;
- return new MySQLErrPacket(1, new CustomizedErrorCode(ruleViolationCause.getErrorCode(), ruleViolationCause.getSqlState(), ruleViolationCause.getErrorMessage()));
- }
if (cause instanceof UnsupportedCommandException) {
return new MySQLErrPacket(1, CommonErrorCode.UNSUPPORTED_COMMAND, ((UnsupportedCommandException) cause).getCommandType());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
index 6448fc5..4779027 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
@@ -196,8 +196,8 @@ public final class MySQLErrPacketFactoryTest {
public void assertNewInstanceWithRuleDefinitionViolationException() {
RuleDefinitionViolationException exception = mock(RuleDefinitionViolationException.class);
when(exception.getErrorCode()).thenReturn(1);
- when(exception.getSqlState()).thenReturn("C0000");
- when(exception.getErrorMessage()).thenReturn("Test error");
+ when(exception.getSQLState()).thenReturn("C0000");
+ when(exception.getMessage()).thenReturn("Test error");
MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(exception);
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(1));