You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2022/09/15 16:05:00 UTC
[shardingsphere] branch master updated: Reuse PrepareJobWithoutEnoughPrivilegeException (#21008)
This is an automated email from the ASF dual-hosted git repository.
yx9o 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 0f0931f68d8 Reuse PrepareJobWithoutEnoughPrivilegeException (#21008)
0f0931f68d8 is described below
commit 0f0931f68d8d8cbf6203b74278ef773565e82a2d
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Sep 16 00:04:50 2022 +0800
Reuse PrepareJobWithoutEnoughPrivilegeException (#21008)
* Reuse PrepareJobWithoutEnoughPrivilegeException
* Refactor ShardingSpherePreconditions
---
.../user-manual/error-code/sql-error-code.cn.md | 2 +-
.../user-manual/error-code/sql-error-code.en.md | 2 +-
.../protocol/mysql/constant/MySQLCharacterSet.java | 4 +--
.../statement/dml/InsertStatementContext.java | 4 +--
.../statement/dml/SelectStatementContext.java | 2 +-
.../metadata/url/StandardJdbcUrlParser.java | 2 +-
.../result/impl/stream/StreamMergedResult.java | 2 +-
.../exception/ShardingSpherePreconditions.java | 37 +++-------------------
.../exception/ShardingSpherePreconditionsTest.java | 15 ++++-----
.../core/api/impl/AbstractPipelineJobAPIImpl.java | 2 +-
.../PrepareJobWithoutEnoughPrivilegeException.java | 6 ++--
.../core/util/PipelineTableMetaDataUtil.java | 2 +-
.../check/datasource/MySQLDataSourceChecker.java | 2 +-
.../datasource/OpenGaussDataSourceChecker.java | 9 +++---
.../datasource/PostgreSQLDataSourceChecker.java | 9 +++---
.../SingleTableDropSchemaMetadataValidator.java | 2 +-
.../advanced/resultset/FederationResultSet.java | 2 +-
.../handler/DatabaseRequiredBackendHandler.java | 2 +-
18 files changed, 40 insertions(+), 66 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 c6005cf0694..5e364d00a45 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
@@ -97,7 +97,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY000 | 18082 | Sharding count of job \`%s\` is 0 |
| HY000 | 18083 | Can not split range for table \`%s\`, reason: %s |
| HY000 | 18084 | Target table \`%s\` is not empty |
-| 01007 | 18085 | Source data source is lack of REPLICATION SLAVE, REPLICATION CLIENT ON *.* privileges |
+| 01007 | 18085 | Source data source lacks %s privilege(s) |
| HY000 | 18086 | Source data source required \`%s = %s\`, now is \`%s\` |
| HY000 | 18090 | Importer job write data failed |
| HY000 | 18091 | Can not poll event because of binlog sync channel already closed |
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 8f1442927f1..39cc672679e 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
@@ -97,7 +97,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| HY000 | 18082 | Sharding count of job \`%s\` is 0 |
| HY000 | 18083 | Can not split range for table \`%s\`, reason: %s |
| HY000 | 18084 | Target table \`%s\` is not empty |
-| 01007 | 18085 | Source data source is lack of REPLICATION SLAVE, REPLICATION CLIENT ON *.* privileges |
+| 01007 | 18085 | Source data source lacks %s privilege(s) |
| HY000 | 18086 | Source data source required \`%s = %s\`, now is \`%s\` |
| HY000 | 18090 | Importer job write data failed |
| HY000 | 18091 | Can not poll event because of binlog sync channel already closed |
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLCharacterSet.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLCharacterSet.java
index e08ebe302aa..c9c45783e19 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLCharacterSet.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLCharacterSet.java
@@ -335,8 +335,8 @@ public enum MySQLCharacterSet {
*/
public static MySQLCharacterSet findById(final int id) {
MySQLCharacterSet result = CHARACTER_SET_MAP.get(id);
- ShardingSpherePreconditions.checkNotNull(result, new UnknownCollationException(id));
- ShardingSpherePreconditions.checkNotNull(result.getCharset(), new UnknownCollationException(id));
+ ShardingSpherePreconditions.checkNotNull(result, () -> new UnknownCollationException(id));
+ ShardingSpherePreconditions.checkNotNull(result.getCharset(), () -> new UnknownCollationException(id));
return result;
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
index 15846351741..a7f8ad704ad 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
@@ -99,9 +99,9 @@ public final class InsertStatementContext extends CommonSQLStatementContext<Inse
private ShardingSphereSchema getSchema(final Map<String, ShardingSphereDatabase> databases, final String defaultDatabaseName) {
String databaseName = tablesContext.getDatabaseName().orElse(defaultDatabaseName);
- ShardingSpherePreconditions.checkNotNull(databaseName, new NoDatabaseSelectedException());
+ ShardingSpherePreconditions.checkNotNull(databaseName, NoDatabaseSelectedException::new);
ShardingSphereDatabase database = databases.get(databaseName.toLowerCase());
- ShardingSpherePreconditions.checkNotNull(database, new UnknownDatabaseException(databaseName));
+ ShardingSpherePreconditions.checkNotNull(database, () -> new UnknownDatabaseException(databaseName));
String defaultSchema = DatabaseTypeEngine.getDefaultSchemaName(getDatabaseType(), databaseName);
return tablesContext.getSchemaName().map(database::getSchema).orElseGet(() -> database.getSchema(defaultSchema));
}
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
index 4e35e08153d..bb85d786994 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
@@ -137,7 +137,7 @@ public final class SelectStatementContext extends CommonSQLStatementContext<Sele
throw new NoDatabaseSelectedException();
}
ShardingSphereDatabase database = databases.get(databaseName.toLowerCase());
- ShardingSpherePreconditions.checkNotNull(database, new UnknownDatabaseException(databaseName));
+ ShardingSpherePreconditions.checkNotNull(database, () -> new UnknownDatabaseException(databaseName));
return database.getSchemas();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParser.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParser.java
index 12aa83eb614..a67e5b42dd5 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParser.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParser.java
@@ -57,7 +57,7 @@ public final class StandardJdbcUrlParser {
Matcher matcher = CONNECTION_URL_PATTERN.matcher(jdbcUrl);
if (matcher.matches()) {
String authority = matcher.group(AUTHORITY_GROUP_KEY);
- ShardingSpherePreconditions.checkNotNull(authority, new UnrecognizedDatabaseURLException(jdbcUrl, CONNECTION_URL_PATTERN.pattern().replaceAll("%", "%%")));
+ ShardingSpherePreconditions.checkNotNull(authority, () -> new UnrecognizedDatabaseURLException(jdbcUrl, CONNECTION_URL_PATTERN.pattern().replaceAll("%", "%%")));
return new JdbcUrl(parseHostname(authority), parsePort(authority), matcher.group(PATH_GROUP_KEY), parseQueryProperties(matcher.group(QUERY_GROUP_KEY)));
}
throw new UnrecognizedDatabaseURLException(jdbcUrl, CONNECTION_URL_PATTERN.pattern().replaceAll("%", "%%"));
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/stream/StreamMergedResult.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/stream/StreamMergedResult.java
index 3cfbd7f3c39..44f65a8d3be 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/stream/StreamMergedResult.java
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/stream/StreamMergedResult.java
@@ -37,7 +37,7 @@ public abstract class StreamMergedResult implements MergedResult {
private boolean wasNull;
protected final QueryResult getCurrentQueryResult() throws SQLException {
- ShardingSpherePreconditions.checkNotNull(currentQueryResult, new SQLException("Current ResultSet is null, ResultSet perhaps end of next."));
+ ShardingSpherePreconditions.checkNotNull(currentQueryResult, () -> new SQLException("Current ResultSet is null, ResultSet perhaps end of next"));
return currentQueryResult;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
index 217e5606d79..f3377fe4850 100644
--- a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
+++ b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
@@ -19,10 +19,7 @@ package org.apache.shardingsphere.infra.util.exception;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.exception.external.ShardingSphereExternalException;
-import org.apache.shardingsphere.infra.util.exception.internal.ShardingSphereInternalException;
-import java.sql.SQLException;
import java.util.function.Supplier;
/**
@@ -48,38 +45,14 @@ public final class ShardingSpherePreconditions {
/**
* Ensures that an object reference passed as a parameter to the calling method is not null.
*
+ * @param <T> type of exception
* @param reference object reference to be checked
- * @param exceptionIfUnexpected exception thrown if object is null
- */
- public static void checkNotNull(final Object reference, final ShardingSphereExternalException exceptionIfUnexpected) {
- if (null == reference) {
- throw exceptionIfUnexpected;
- }
- }
-
- /**
- * Ensures that an object reference passed as a parameter to the calling method is not null.
- *
- * @param reference object reference to be checked
- * @param exceptionIfUnexpected exception thrown if object is null
- * @throws ShardingSphereInternalException ShardingSphere internal exception
- */
- public static void checkNotNull(final Object reference, final ShardingSphereInternalException exceptionIfUnexpected) throws ShardingSphereInternalException {
- if (null == reference) {
- throw exceptionIfUnexpected;
- }
- }
-
- /**
- * Ensures that an object reference passed as a parameter to the calling method is not null.
- *
- * @param reference object reference to be checked
- * @param exceptionIfUnexpected exception thrown if object is null
- * @throws SQLException SQL exception
+ * @param exceptionSupplierIfUnexpected exception from this supplier will be thrown if expression is unexpected
+ * @throws T exception to be thrown
*/
- public static void checkNotNull(final Object reference, final SQLException exceptionIfUnexpected) throws SQLException {
+ public static <T extends Throwable> void checkNotNull(final Object reference, final Supplier<T> exceptionSupplierIfUnexpected) throws T {
if (null == reference) {
- throw exceptionIfUnexpected;
+ throw exceptionSupplierIfUnexpected.get();
}
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
index d7ded4fd48c..40bdabd7f34 100644
--- a/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
@@ -39,34 +39,31 @@ public final class ShardingSpherePreconditionsTest {
@Test(expected = ShardingSphereExternalException.class)
public void assertCheckNotNullToThrowsExternalException() {
- ShardingSpherePreconditions.checkNotNull(null, new SQLWrapperException(new SQLException()));
+ ShardingSpherePreconditions.checkNotNull(null, () -> new SQLWrapperException(new SQLException()));
}
- @SuppressWarnings("ObviousNullCheck")
@Test
public void assertCheckNotNullToNotThrowExternalException() {
- ShardingSpherePreconditions.checkNotNull(new Object(), new SQLWrapperException(new SQLException()));
+ ShardingSpherePreconditions.checkNotNull(new Object(), () -> new SQLWrapperException(new SQLException()));
}
@Test(expected = ShardingSphereInternalException.class)
public void assertCheckNotNullToThrowsInternalException() throws ShardingSphereInternalException {
- ShardingSpherePreconditions.checkNotNull(null, new ShardingSphereInternalExceptionFixture("message"));
+ ShardingSpherePreconditions.checkNotNull(null, () -> new ShardingSphereInternalExceptionFixture("message"));
}
- @SuppressWarnings("ObviousNullCheck")
@Test
public void assertCheckNotNullToNotThrowInternalException() throws ShardingSphereInternalException {
- ShardingSpherePreconditions.checkNotNull(new Object(), new ShardingSphereInternalExceptionFixture("message"));
+ ShardingSpherePreconditions.checkNotNull(new Object(), () -> new ShardingSphereInternalExceptionFixture("message"));
}
@Test(expected = SQLException.class)
public void assertCheckNotNullToThrowsSQLException() throws SQLException {
- ShardingSpherePreconditions.checkNotNull(null, new SQLException("message"));
+ ShardingSpherePreconditions.checkNotNull(null, () -> new SQLException("message"));
}
- @SuppressWarnings("ObviousNullCheck")
@Test
public void assertCheckNotNullToNotThrowSQLException() throws SQLException {
- ShardingSpherePreconditions.checkNotNull(new Object(), new SQLException("message"));
+ ShardingSpherePreconditions.checkNotNull(new Object(), () -> new SQLException("message"));
}
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
index 9f562e68309..5d815b48012 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
@@ -89,7 +89,7 @@ public abstract class AbstractPipelineJobAPIImpl implements PipelineJobAPI {
private YamlPipelineProcessConfiguration getTargetYamlProcessConfiguration() {
PipelineProcessConfiguration existingProcessConfig = processConfigPersistService.load(getJobType());
- ShardingSpherePreconditions.checkNotNull(existingProcessConfig, new AlterNotExistProcessConfigurationException());
+ ShardingSpherePreconditions.checkNotNull(existingProcessConfig, AlterNotExistProcessConfigurationException::new);
return PROCESS_CONFIG_SWAPPER.swapToYamlConfiguration(existingProcessConfig);
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/PrepareJobWithoutEnoughPrivilegeException.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/PrepareJobWithoutEnoughPrivilegeException.java
index b575b5f02f7..4acea96575d 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/PrepareJobWithoutEnoughPrivilegeException.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/PrepareJobWithoutEnoughPrivilegeException.java
@@ -20,6 +20,8 @@ package org.apache.shardingsphere.data.pipeline.core.exception.job;
import org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import java.util.Collection;
+
/**
* Prepare job without enough privilege exception.
*/
@@ -27,7 +29,7 @@ public final class PrepareJobWithoutEnoughPrivilegeException extends PipelineSQL
private static final long serialVersionUID = -8462039913248251254L;
- public PrepareJobWithoutEnoughPrivilegeException() {
- super(XOpenSQLState.PRIVILEGE_NOT_GRANTED, 85, "Source data source is lack of REPLICATION SLAVE, REPLICATION CLIENT ON *.* privileges");
+ public PrepareJobWithoutEnoughPrivilegeException(final Collection<String> privileges) {
+ super(XOpenSQLState.PRIVILEGE_NOT_GRANTED, 85, "Source data source lacks %s privilege(s)", privileges);
}
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineTableMetaDataUtil.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineTableMetaDataUtil.java
index 62bc64515ff..4b61486c9d3 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineTableMetaDataUtil.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineTableMetaDataUtil.java
@@ -107,7 +107,7 @@ public final class PipelineTableMetaDataUtil {
}
private static PipelineColumnMetaData mustGetAnAppropriateUniqueKeyColumn(final PipelineTableMetaData tableMetaData, final String tableName) {
- ShardingSpherePreconditions.checkNotNull(tableMetaData, new SplitPipelineJobException(tableName, "can not get table metadata"));
+ ShardingSpherePreconditions.checkNotNull(tableMetaData, () -> new SplitPipelineJobException(tableName, "can not get table metadata"));
List<String> primaryKeys = tableMetaData.getPrimaryKeyColumns();
if (1 == primaryKeys.size()) {
return tableMetaData.getColumnMetaData(tableMetaData.getPrimaryKeyColumns().get(0));
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java
index 17e93509045..b9fbd8ec426 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java
@@ -76,7 +76,7 @@ public final class MySQLDataSourceChecker extends AbstractDataSourceChecker {
} catch (final SQLException ex) {
throw new PipelineJobPrepareFailedException("Source data source check privileges failed.", ex);
}
- throw new PrepareJobWithoutEnoughPrivilegeException();
+ throw new PrepareJobWithoutEnoughPrivilegeException(Arrays.asList("REPLICATION SLAVE", "REPLICATION CLIENT"));
}
private boolean matchPrivileges(final String privilege) {
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/check/datasource/OpenGaussDataSourceChecker.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/check/datasource/OpenGaussDataSourceChecker.java
index 436907b9c58..1e141512a28 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/check/datasource/OpenGaussDataSourceChecker.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/check/datasource/OpenGaussDataSourceChecker.java
@@ -21,6 +21,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.core.check.datasource.AbstractDataSourceChecker;
import org.apache.shardingsphere.data.pipeline.core.exception.job.PipelineJobPrepareFailedException;
+import org.apache.shardingsphere.data.pipeline.core.exception.job.PrepareJobWithoutEnoughPrivilegeException;
+import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -29,6 +31,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.Collections;
/**
* Data source checker of openGauss.
@@ -57,10 +60,8 @@ public final class OpenGaussDataSourceChecker extends AbstractDataSourceChecker
String isReplicationRole = resultSet.getString("rolreplication");
String isSystemAdminRole = resultSet.getString("rolsystemadmin");
log.info("checkPrivilege: isSuperRole: {}, isReplicationRole: {}, isSystemAdminRole: {}", isSuperRole, isReplicationRole, isSystemAdminRole);
- if (!StringUtils.equalsAnyIgnoreCase("t", isSuperRole, isReplicationRole, isSystemAdminRole)) {
- throw new PipelineJobPrepareFailedException(String.format("Source data source is lack of REPLICATION privileges, you could try `ALTER ROLE \"%s\" REPLICATION;`.",
- metaData.getUserName()));
- }
+ ShardingSpherePreconditions.checkState(StringUtils.equalsAnyIgnoreCase("t", isSuperRole, isReplicationRole, isSystemAdminRole),
+ () -> new PrepareJobWithoutEnoughPrivilegeException(Collections.singleton("REPLICATION")));
}
} catch (final SQLException ex) {
throw new PipelineJobPrepareFailedException("Source data source check privileges failed.", ex);
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java
index 660316ea809..c16589ce4f7 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceChecker.java
@@ -21,6 +21,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.core.check.datasource.AbstractDataSourceChecker;
import org.apache.shardingsphere.data.pipeline.core.exception.job.PipelineJobPrepareFailedException;
+import org.apache.shardingsphere.data.pipeline.core.exception.job.PrepareJobWithoutEnoughPrivilegeException;
+import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -29,6 +31,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.Collections;
/**
* PostgreSQL Data source checker.
@@ -56,10 +59,8 @@ public class PostgreSQLDataSourceChecker extends AbstractDataSourceChecker {
String isSuperRole = resultSet.getString("rolsuper");
String isReplicationRole = resultSet.getString("rolreplication");
log.info("checkPrivilege: isSuperRole: {}, isReplicationRole: {}", isSuperRole, isReplicationRole);
- if (StringUtils.equalsIgnoreCase(isSuperRole, "f") && StringUtils.equalsIgnoreCase(isReplicationRole, "f")) {
- throw new PipelineJobPrepareFailedException(String.format("Source data source is lack of REPLICATION privileges, you could try `ALTER ROLE \"%s\" REPLICATION;`.",
- metaData.getUserName()));
- }
+ ShardingSpherePreconditions.checkState(!StringUtils.equalsIgnoreCase(isSuperRole, "f") && StringUtils.equalsIgnoreCase(isReplicationRole, "f"),
+ () -> new PrepareJobWithoutEnoughPrivilegeException(Collections.singleton("REPLICATION")));
}
} catch (final SQLException ex) {
throw new PipelineJobPrepareFailedException("Source data source check privileges failed.", ex);
diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java
index 078558889a9..2ab5a87d1ff 100644
--- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java
+++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java
@@ -40,7 +40,7 @@ public final class SingleTableDropSchemaMetadataValidator implements SingleTable
for (IdentifierValue each : sqlStatementContext.getSqlStatement().getSchemaNames()) {
String schemaName = each.getValue();
ShardingSphereSchema schema = database.getSchema(schemaName);
- ShardingSpherePreconditions.checkNotNull(schema, new SchemaNotFoundException(schemaName));
+ ShardingSpherePreconditions.checkNotNull(schema, () -> new SchemaNotFoundException(schemaName));
ShardingSpherePreconditions.checkState(containsCascade || schema.getAllTableNames().isEmpty(), () -> new DropNotEmptySchemaException(schemaName));
}
}
diff --git a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/resultset/FederationResultSet.java b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/resultset/FederationResultSet.java
index c3475462bdd..6da1a19c7d6 100644
--- a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/resultset/FederationResultSet.java
+++ b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/resultset/FederationResultSet.java
@@ -446,7 +446,7 @@ public final class FederationResultSet extends AbstractUnsupportedOperationResul
private Integer getIndexFromColumnLabelAndIndexMap(final String columnLabel) throws SQLException {
Integer result = columnLabelAndIndexMap.get(columnLabel.toLowerCase());
- ShardingSpherePreconditions.checkNotNull(result, new SQLFeatureNotSupportedException(String.format("can't get index from columnLabel[%s].", columnLabel)));
+ ShardingSpherePreconditions.checkNotNull(result, () -> new SQLFeatureNotSupportedException(String.format("can not get index from column label `%s`", columnLabel)));
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/DatabaseRequiredBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/DatabaseRequiredBackendHandler.java
index bc9fb3ea00a..def8cef05d2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/DatabaseRequiredBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/DatabaseRequiredBackendHandler.java
@@ -60,7 +60,7 @@ public abstract class DatabaseRequiredBackendHandler<T extends SQLStatement> imp
}
private void checkDatabaseName(final String databaseName) {
- ShardingSpherePreconditions.checkNotNull(databaseName, new NoDatabaseSelectedException());
+ ShardingSpherePreconditions.checkNotNull(databaseName, NoDatabaseSelectedException::new);
ShardingSpherePreconditions.checkState(ProxyContext.getInstance().databaseExists(databaseName), () -> new UnknownDatabaseException(databaseName));
}
}