This is an automated email from the ASF dual-hosted git repository.
chengzhang 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 0ef22288580 Remove StorageUnitNotExistedException (#30713)
0ef22288580 is described below
commit 0ef22288580f43ba0df856a7c60eb356bcce74fb
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 31 15:50:51 2024 +0800
Remove StorageUnitNotExistedException (#30713)
* Refactor DuplicateStorageUnitExceptionDefinition
* Refactor StorageUnitNotExistedException
* Remove StorageUnitNotExistedException
---
.../user-manual/error-code/sql-error-code.cn.md | 3 +-
.../user-manual/error-code/sql-error-code.en.md | 3 +-
.../DuplicateStorageUnitExceptionDefinition.java | 2 +-
.../storageunit/EmptyStorageUnitException.java | 6 +++-
.../StorageUnitNotExistedException.java | 37 ----------------------
.../proxy/backend/connector/DatabaseConnector.java | 6 ++--
.../data/impl/UnicastDatabaseBackendHandler.java | 10 +++---
.../executor/UnicastResourceShowExecutor.java | 6 ++--
8 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 9af97e61db2..7036a259da9 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -28,12 +28,11 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 0A000 | 10040 | Unsupported storage type of \`%s.%s\`.
|
| 44000 | 10100 | Can not %s storage units '%s'.
|
| 44000 | 10101 | Storage units '%s' do not exist in database '%s'.
|
-| 44000 | 10102 | There is no storage unit in the database '%s'.
|
+| 42S02 | 10102 | There is no storage unit in database '%s'.
|
| 44000 | 10103 | Storage unit '%s' still used by '%s'.
|
| 44000 | 10104 | Duplicate storage unit names '%s'.
|
| 44000 | 10105 | Invalid storage unit status, error message is: %s.
|
| 44000 | 10106 | Read storage unit '%s' does not exist in rule
'%s'. |
-| 42000 | 10107 | There is no storage unit in database '%s'.
|
| 0A000 | 10108 | Can not alter connection info in storage units:
'%s'. |
| 0A000 | 10109 | Storage units can not connect, error messages are:
%s. |
| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s
|
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 14adc58967e..3909ee9560c 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -28,12 +28,11 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 0A000 | 10040 | Unsupported storage type of \`%s.%s\`.
|
| 44000 | 10100 | Can not %s storage units '%s'.
|
| 44000 | 10101 | Storage units '%s' do not exist in database '%s'.
|
-| 44000 | 10102 | There is no storage unit in the database '%s'.
|
+| 42S02 | 10102 | There is no storage unit in database '%s'.
|
| 44000 | 10103 | Storage unit '%s' still used by '%s'.
|
| 44000 | 10104 | Duplicate storage unit names '%s'.
|
| 44000 | 10105 | Invalid storage unit status, error message is: %s.
|
| 44000 | 10106 | Read storage unit '%s' does not exist in rule
'%s'. |
-| 42000 | 10107 | There is no storage unit in database '%s'.
|
| 0A000 | 10108 | Can not alter connection info in storage units:
'%s'. |
| 0A000 | 10109 | Storage units can not connect, error messages are:
%s. |
| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s
|
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java
index b57e7b665b3..f3491418e1a 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java
@@ -30,6 +30,6 @@ public final class DuplicateStorageUnitExceptionDefinition
extends ResourceDefin
private static final long serialVersionUID = 2103793827572264148L;
public DuplicateStorageUnitExceptionDefinition(final Collection<String>
storageUnitNames) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 4, "Duplicate storage unit
names '%s'.", storageUnitNames);
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 4, "Duplicate storage unit
names '%s'.", String.join(", ", storageUnitNames));
}
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/EmptyStorageUnitException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/EmptyStorageUnitException.java
index a743b129b99..c61e84b1870 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/EmptyStorageUnitException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/EmptyStorageUnitException.java
@@ -27,7 +27,11 @@ public final class EmptyStorageUnitException extends
ResourceDefinitionException
private static final long serialVersionUID = 1704331180489268L;
+ public EmptyStorageUnitException() {
+ super(XOpenSQLState.NOT_FOUND, 2, "There is no storage unit in any
database.");
+ }
+
public EmptyStorageUnitException(final String databaseName) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "There is no storage
unit in the database '%s'.", databaseName);
+ super(XOpenSQLState.NOT_FOUND, 2, "There is no storage unit in
database '%s'.", databaseName);
}
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitNotExistedException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitNotExistedException.java
deleted file mode 100644
index 0120304dd39..00000000000
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitNotExistedException.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.exception.storageunit;
-
-import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ResourceDefinitionException;
-
-/**
- * Storage unit not existed exception.
- */
-public final class StorageUnitNotExistedException extends
ResourceDefinitionException {
-
- private static final long serialVersionUID = 4146100333670404924L;
-
- public StorageUnitNotExistedException() {
- super(XOpenSQLState.SYNTAX_ERROR, 7, "There is no storage unit in any
database.");
- }
-
- public StorageUnitNotExistedException(final String databaseName) {
- super(XOpenSQLState.SYNTAX_ERROR, 7, "There is no storage unit in
database '%s'.", databaseName);
- }
-}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
index 606bca8b2b2..d1b6c6405ff 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.backend.connector;
import com.google.common.base.Preconditions;
-import org.apache.shardingsphere.infra.exception.rule.RuleNotExistedException;
import
org.apache.shardingsphere.infra.binder.context.aware.CursorDefinitionAware;
import
org.apache.shardingsphere.infra.binder.context.segment.insert.keygen.GeneratedKeyContext;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
@@ -33,6 +32,8 @@ import
org.apache.shardingsphere.infra.connection.refresher.MetaDataRefreshEngin
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.dialect.SQLExceptionTransformEngine;
+import org.apache.shardingsphere.infra.exception.rule.RuleNotExistedException;
+import
org.apache.shardingsphere.infra.exception.storageunit.EmptyStorageUnitException;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
import
org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutorExceptionHandler;
import
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
@@ -56,7 +57,6 @@ import
org.apache.shardingsphere.proxy.backend.connector.jdbc.executor.callback.
import
org.apache.shardingsphere.proxy.backend.connector.jdbc.statement.JDBCBackendStatement;
import
org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitNotExistedException;
import
org.apache.shardingsphere.proxy.backend.handler.data.DatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
@@ -130,7 +130,7 @@ public final class DatabaseConnector implements
DatabaseBackendHandler {
private void failedIfBackendNotReady(final ConnectionSession
connectionSession, final SQLStatementContext sqlStatementContext) {
ShardingSphereDatabase database =
ProxyContext.getInstance().getContextManager().getDatabase(connectionSession.getDatabaseName());
boolean isSystemSchema =
SystemSchemaUtils.containsSystemSchema(sqlStatementContext.getDatabaseType(),
sqlStatementContext.getTablesContext().getSchemaNames(), database);
- ShardingSpherePreconditions.checkState(isSystemSchema ||
database.containsDataSource(), () -> new
StorageUnitNotExistedException(connectionSession.getDatabaseName()));
+ ShardingSpherePreconditions.checkState(isSystemSchema ||
database.containsDataSource(), () -> new
EmptyStorageUnitException(connectionSession.getDatabaseName()));
if (!isSystemSchema && !database.isComplete()) {
throw new
RuleNotExistedException(connectionSession.getDatabaseName());
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
index a8b146c4fcc..9af2df5ce1b 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
@@ -20,13 +20,13 @@ package
org.apache.shardingsphere.proxy.backend.handler.data.impl;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
+import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException;
+import
org.apache.shardingsphere.infra.exception.storageunit.EmptyStorageUnitException;
import org.apache.shardingsphere.infra.session.query.QueryContext;
-import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import
org.apache.shardingsphere.proxy.backend.connector.DatabaseConnectorFactory;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnector;
+import
org.apache.shardingsphere.proxy.backend.connector.DatabaseConnectorFactory;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitNotExistedException;
import
org.apache.shardingsphere.proxy.backend.handler.data.DatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
@@ -56,7 +56,7 @@ public final class UnicastDatabaseBackendHandler implements
DatabaseBackendHandl
String originalDatabaseName =
connectionSession.getDefaultDatabaseName();
String unicastDatabaseName = null == originalDatabaseName ?
getFirstDatabaseName() : originalDatabaseName;
ShardingSpherePreconditions.checkState(ProxyContext.getInstance().getContextManager().getDatabase(unicastDatabaseName).containsDataSource(),
- () -> new StorageUnitNotExistedException(unicastDatabaseName));
+ () -> new EmptyStorageUnitException(unicastDatabaseName));
try {
connectionSession.setCurrentDatabase(unicastDatabaseName);
databaseConnector =
databaseConnectorFactory.newInstance(queryContext,
connectionSession.getDatabaseConnectionManager(), false);
@@ -75,7 +75,7 @@ public final class UnicastDatabaseBackendHandler implements
DatabaseBackendHandl
Optional<ShardingSpherePrivileges> privileges =
authorityRule.findPrivileges(connectionSession.getGrantee());
Stream<String> databaseStream = databaseNames.stream().filter(each ->
ProxyContext.getInstance().getContextManager().getDatabase(each).containsDataSource());
Optional<String> result = privileges.map(optional ->
databaseStream.filter(optional::hasPrivileges).findFirst()).orElseGet(databaseStream::findFirst);
- ShardingSpherePreconditions.checkState(result.isPresent(),
StorageUnitNotExistedException::new);
+ ShardingSpherePreconditions.checkState(result.isPresent(),
EmptyStorageUnitException::new);
return result.get();
}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UnicastResourceShowExecutor.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UnicastResourceShowExecutor.java
index 7739188d5a0..438c6a602d1 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UnicastResourceShowExecutor.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UnicastResourceShowExecutor.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementCont
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException;
+import
org.apache.shardingsphere.infra.exception.storageunit.EmptyStorageUnitException;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultColumnMetaData;
@@ -37,7 +38,6 @@ import
org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnector;
import
org.apache.shardingsphere.proxy.backend.connector.DatabaseConnectorFactory;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitNotExistedException;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader;
@@ -77,7 +77,7 @@ public final class UnicastResourceShowExecutor implements
DatabaseAdminQueryExec
public void execute(final ConnectionSession connectionSession) throws
SQLException {
String originDatabase = connectionSession.getDatabaseName();
String databaseName = null == originDatabase ? getFirstDatabaseName()
: originDatabase;
-
ShardingSpherePreconditions.checkState(ProxyContext.getInstance().getContextManager().getDatabase(databaseName).containsDataSource(),
() -> new StorageUnitNotExistedException(databaseName));
+
ShardingSpherePreconditions.checkState(ProxyContext.getInstance().getContextManager().getDatabase(databaseName).containsDataSource(),
() -> new EmptyStorageUnitException(databaseName));
HintValueContext hintValueContext = SQLHintUtils.extractHint(sql);
try {
connectionSession.setCurrentDatabase(databaseName);
@@ -99,7 +99,7 @@ public final class UnicastResourceShowExecutor implements
DatabaseAdminQueryExec
throw new NoDatabaseSelectedException();
}
Optional<String> result = databaseNames.stream().filter(each ->
ProxyContext.getInstance().getContextManager().getDatabase(each).containsDataSource()).findFirst();
- ShardingSpherePreconditions.checkState(result.isPresent(),
StorageUnitNotExistedException::new);
+ ShardingSpherePreconditions.checkState(result.isPresent(),
EmptyStorageUnitException::new);
return result.get();
}